Skip to content

Commit

Permalink
test APQ with websocket transport
Browse files Browse the repository at this point in the history
  • Loading branch information
rose-a committed Apr 22, 2024
1 parent 97312ee commit 77a6d7e
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
namespace GraphQL.Integration.Tests.APQ;

[SuppressMessage("ReSharper", "UseConfigureAwaitFalse")]
public class APQViaHttpRequests : IAsyncLifetime, IClassFixture<SystemTextJsonAutoNegotiateServerTestFixture>
public class AdvancedPersistentQueriesTest : IAsyncLifetime, IClassFixture<SystemTextJsonAutoNegotiateServerTestFixture>
{
public SystemTextJsonAutoNegotiateServerTestFixture Fixture { get; }
protected GraphQLHttpClient StarWarsClient;
protected GraphQLHttpClient StarWarsWebsocketClient;

public APQViaHttpRequests(SystemTextJsonAutoNegotiateServerTestFixture fixture)
public AdvancedPersistentQueriesTest(SystemTextJsonAutoNegotiateServerTestFixture fixture)
{
Fixture = fixture;
}
Expand All @@ -23,6 +24,11 @@ public async Task InitializeAsync()
{
await Fixture.CreateServer();
StarWarsClient = Fixture.GetStarWarsClient(options => options.EnableAutomaticPersistedQueries = _ => true);
StarWarsWebsocketClient = Fixture.GetStarWarsClient(options =>
{
options.EnableAutomaticPersistedQueries = _ => true;
options.UseWebSocketForQueriesAndMutations = true;
});
}

public Task DisposeAsync()
Expand Down Expand Up @@ -51,4 +57,25 @@ query Human($id: String!){
Assert.Equal(name, response.Data.Human.Name);
StarWarsClient.APQDisabledForSession.Should().BeFalse("if APQ has worked it won't get disabled");
}

[Theory]
[ClassData(typeof(StarWarsHumans))]
public async void After_querying_all_starwars_humans_using_websocket_transport_the_APQDisabledForSession_is_still_false_Async(int id, string name)
{
var query = new GraphQLQuery("""
query Human($id: String!){
human(id: $id) {
name
}
}
""");

var graphQLRequest = new GraphQLRequest(query, new { id = id.ToString() });

var response = await StarWarsWebsocketClient.SendQueryAsync(graphQLRequest, () => new { Human = new { Name = string.Empty } });

Assert.Null(response.Errors);
Assert.Equal(name, response.Data.Human.Name);
StarWarsWebsocketClient.APQDisabledForSession.Should().BeFalse("if APQ has worked it won't get disabled");
}
}

0 comments on commit 77a6d7e

Please sign in to comment.