-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix uniqueness of constructed graph types (#242)
Co-authored-by: Shane Krueger <[email protected]>
- Loading branch information
Showing
16 changed files
with
244 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Net; | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.AspNetCore.TestHost; | ||
|
||
namespace SimpleWebApp.Tests; | ||
|
||
public class EndToEndTests | ||
{ | ||
[Fact] | ||
public async Task Search() | ||
{ | ||
var query = """ | ||
{ | ||
search (forString:"") { | ||
items { | ||
__typename | ||
... on Book { | ||
id | ||
title | ||
} | ||
... on Author { | ||
id | ||
firstName | ||
lastName | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var expected = """ | ||
{ | ||
"data": { | ||
"search": { | ||
"items": [ | ||
{ | ||
"__typename": "Book", | ||
"id": "Qm9vazox", | ||
"title": "A Lone Wolf in the Forest" | ||
}, | ||
{ | ||
"__typename": "Book", | ||
"id": "Qm9vazoy", | ||
"title": "Surfer Boy" | ||
}, | ||
{ | ||
"__typename": "Book", | ||
"id": "Qm9vazoz", | ||
"title": "GraphQL, a Love Story" | ||
}, | ||
{ | ||
"__typename": "Book", | ||
"id": "Qm9vazo0", | ||
"title": "Dare I Say What?" | ||
}, | ||
{ | ||
"__typename": "Author", | ||
"id": "QXV0aG9yOjE=", | ||
"firstName": "Benny", | ||
"lastName": "Frank" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
using var webApp = new WebApplicationFactory<GraphQL.Conventions.Tests.Server.Program>(); | ||
using var server = webApp.Server; | ||
server.AllowSynchronousIO = true; // for Newtonsoft.Json support | ||
await VerifyGraphQLPostAsync(server, "/graphql", query, expected).ConfigureAwait(false); | ||
} | ||
|
||
private static async Task VerifyGraphQLPostAsync( | ||
TestServer server, | ||
string url, | ||
string query, | ||
string expected, | ||
HttpStatusCode statusCode = HttpStatusCode.OK) | ||
{ | ||
using var client = server.CreateClient(); | ||
var body = JsonSerializer.Serialize(new { query }); | ||
var content = new StringContent(body, System.Text.Encoding.UTF8, "application/json"); | ||
using var request = new HttpRequestMessage(HttpMethod.Post, url); | ||
request.Content = content; | ||
using var response = await client.SendAsync(request).ConfigureAwait(false); | ||
Assert.Equal(statusCode, response.StatusCode); | ||
var ret = await response.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
var jsonExpected = JsonSerializer.Serialize(JsonSerializer.Deserialize<JsonElement>(expected)); | ||
var jsonActual = JsonSerializer.Serialize(JsonSerializer.Deserialize<JsonElement>(ret)); | ||
Assert.Equal(jsonExpected, jsonActual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SimpleWebApp\SimpleWebApp.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using GraphQL.Conventions; | ||
using GraphQL.Conventions.Tests.Server; | ||
using GraphQL.Conventions.Tests.Server.Data.Repositories; | ||
using GraphQL.Conventions.Tests.Server.Schema; | ||
using GraphQL.Conventions.Web; | ||
|
||
namespace SimpleWebApp.Tests; | ||
|
||
public class SimpleWebAppSchemaCreationTests | ||
{ | ||
[Fact] | ||
public async Task TestSimpleWebAppAsync() | ||
{ | ||
var dependencyInjector = new DependencyInjector(); | ||
dependencyInjector.Register<IBookRepository>(new BookRepository()); | ||
dependencyInjector.Register<IAuthorRepository>(new AuthorRepository()); | ||
|
||
var requestHandler = RequestHandler | ||
.New() | ||
.WithDependencyInjector(dependencyInjector) | ||
.WithQueryAndMutation<Query, Mutation>() | ||
.Generate(); | ||
|
||
var request = Request.New(new QueryInput { QueryString = "{ __schema { types { name } } }" }); | ||
var result = await requestHandler.ProcessRequestAsync(request, null, dependencyInjector); | ||
|
||
Assert.False(result.HasErrors); | ||
Assert.True(result.IsValid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.