Skip to content

Commit 97312ee

Browse files
committed
create a test that uses the APQ feature
1 parent 5429f64 commit 97312ee

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using FluentAssertions;
3+
using GraphQL.Client.Abstractions;
4+
using GraphQL.Client.Http;
5+
using GraphQL.Client.Tests.Common.StarWars.TestData;
6+
using GraphQL.Integration.Tests.Helpers;
7+
using Xunit;
8+
9+
namespace GraphQL.Integration.Tests.APQ;
10+
11+
[SuppressMessage("ReSharper", "UseConfigureAwaitFalse")]
12+
public class APQViaHttpRequests : IAsyncLifetime, IClassFixture<SystemTextJsonAutoNegotiateServerTestFixture>
13+
{
14+
public SystemTextJsonAutoNegotiateServerTestFixture Fixture { get; }
15+
protected GraphQLHttpClient StarWarsClient;
16+
17+
public APQViaHttpRequests(SystemTextJsonAutoNegotiateServerTestFixture fixture)
18+
{
19+
Fixture = fixture;
20+
}
21+
22+
public async Task InitializeAsync()
23+
{
24+
await Fixture.CreateServer();
25+
StarWarsClient = Fixture.GetStarWarsClient(options => options.EnableAutomaticPersistedQueries = _ => true);
26+
}
27+
28+
public Task DisposeAsync()
29+
{
30+
StarWarsClient?.Dispose();
31+
return Task.CompletedTask;
32+
}
33+
34+
[Theory]
35+
[ClassData(typeof(StarWarsHumans))]
36+
public async void After_querying_all_starwars_humans_the_APQDisabledForSession_is_still_false_Async(int id, string name)
37+
{
38+
var query = new GraphQLQuery("""
39+
query Human($id: String!){
40+
human(id: $id) {
41+
name
42+
}
43+
}
44+
""");
45+
46+
var graphQLRequest = new GraphQLRequest(query, new { id = id.ToString() });
47+
48+
var response = await StarWarsClient.SendQueryAsync(graphQLRequest, () => new { Human = new { Name = string.Empty } });
49+
50+
Assert.Null(response.Errors);
51+
Assert.Equal(name, response.Data.Human.Name);
52+
StarWarsClient.APQDisabledForSession.Should().BeFalse("if APQ has worked it won't get disabled");
53+
}
54+
}

tests/IntegrationTestServer/Startup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void ConfigureServices(IServiceCollection services)
3838
})
3939
.AddErrorInfoProvider(opt => opt.ExposeExceptionDetails = Environment.IsDevelopment())
4040
.AddSystemTextJson()
41-
.UseAutomaticPersistedQueries()
41+
.UseAutomaticPersistedQueries(options => options.TrackLinkedCacheEntries = true)
4242
.AddGraphTypes(typeof(ChatSchema).Assembly));
4343
}
4444

0 commit comments

Comments
 (0)