Skip to content

Instantly share code, notes, and snippets.

@benmccallum
Last active August 26, 2021 10:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmccallum/9238cbadc558af9cc4491238f5104a41 to your computer and use it in GitHub Desktop.
Save benmccallum/9238cbadc558af9cc4491238f5104a41 to your computer and use it in GitHub Desktop.
Verify your GraphQL schema changes
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Testing;
using Snapshooter.Json;
using Xunit;
namespace MyCompany.MyService
{
public class GraphQLSchemaTests
: IClassFixture<WebApplicationFactory<Startup>>
{
private readonly WebApplicationFactory<Startup> _factory;
public GraphQLSchemaTests(WebApplicationFactory<Startup> factory) => _factory = factory;
[Fact]
public async Task Is_Approved_GraphQL_Schema()
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync("/graphql?SDL"); // formerly /graphql/schema on v10
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var schema = await response.Content.ReadAsStringAsync();
Snapshot.Match(schema);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment