Skip to content

Commit ddf3306

Browse files
tlilShane32
andauthored
Fix uniqueness of constructed graph types (#242)
Co-authored-by: Shane Krueger <shane@acdmail.com>
1 parent b584710 commit ddf3306

File tree

16 files changed

+244
-35
lines changed

16 files changed

+244
-35
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup .NET SDK
2121
uses: actions/setup-dotnet@v3
2222
with:
23-
dotnet-version: 6.0.x
23+
dotnet-version: 7.0.x
2424
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
2525
env:
2626
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/formatting.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Check formatting
22

3-
on:
4-
pull_request:
5-
branches:
6-
- master
7-
- develop
3+
on: [pull_request]
84

95
env:
106
DOTNET_NOLOGO: true
@@ -19,7 +15,7 @@ jobs:
1915
- name: Setup .NET SDK
2016
uses: actions/setup-dotnet@v3
2117
with:
22-
dotnet-version: 6.0.x
18+
dotnet-version: 7.0.x
2319
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
2420
env:
2521
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup .NET SDK
3131
uses: actions/setup-dotnet@v3
3232
with:
33-
dotnet-version: 6.0.x
33+
dotnet-version: 7.0.x
3434
source-url: https://api.nuget.org/v3/index.json
3535
env:
3636
NUGET_AUTH_TOKEN: ${{secrets.CONV_NUGET_AUTH_TOKEN}}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup .NET SDK
1616
uses: actions/setup-dotnet@v3
1717
with:
18-
dotnet-version: 6.0.x
18+
dotnet-version: 7.0.x
1919
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
2020
env:
2121
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Conventions.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples' Tests", "Samples'
4141
EndProject
4242
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubscriptionExample.Tests", "test\SubscriptionExample.Tests\SubscriptionExample.Tests.csproj", "{0BDE134F-0332-4D46-B762-DC861B6B126D}"
4343
EndProject
44+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleWebApp.Tests", "samples\SimpleWebApp.Tests\SimpleWebApp.Tests.csproj", "{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}"
45+
EndProject
4446
Global
4547
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4648
Debug|Any CPU = Debug|Any CPU
@@ -123,6 +125,18 @@ Global
123125
{0BDE134F-0332-4D46-B762-DC861B6B126D}.Release|x64.Build.0 = Release|Any CPU
124126
{0BDE134F-0332-4D46-B762-DC861B6B126D}.Release|x86.ActiveCfg = Release|Any CPU
125127
{0BDE134F-0332-4D46-B762-DC861B6B126D}.Release|x86.Build.0 = Release|Any CPU
128+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|Any CPU.Build.0 = Debug|Any CPU
130+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|x64.ActiveCfg = Debug|Any CPU
131+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|x64.Build.0 = Debug|Any CPU
132+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|x86.ActiveCfg = Debug|Any CPU
133+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Debug|x86.Build.0 = Debug|Any CPU
134+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|Any CPU.Build.0 = Release|Any CPU
136+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|x64.ActiveCfg = Release|Any CPU
137+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|x64.Build.0 = Release|Any CPU
138+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|x86.ActiveCfg = Release|Any CPU
139+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19}.Release|x86.Build.0 = Release|Any CPU
126140
EndGlobalSection
127141
GlobalSection(SolutionProperties) = preSolution
128142
HideSolutionNode = FALSE
@@ -133,6 +147,7 @@ Global
133147
{E7DA8A82-3914-41E5-B5BE-D0BB3F234CE3} = {117AB27B-C4F4-4072-A857-4D2B868BEB80}
134148
{67DFCB1B-6331-41E5-8FD3-03964526EDDD} = {60A6D426-6E98-45CA-B5C4-59B27C4EFD81}
135149
{0BDE134F-0332-4D46-B762-DC861B6B126D} = {F9132124-0747-427F-B607-B7BAD25332F7}
150+
{70202B0F-F2E3-470D-AE0F-B2F5966E4B19} = {F9132124-0747-427F-B607-B7BAD25332F7}
136151
EndGlobalSection
137152
GlobalSection(ExtensibilityGlobals) = postSolution
138153
SolutionGuid = {BBCC6FB7-C0AE-43E0-866B-CA12D6D121DC}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Net;
2+
using System.Text.Json;
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
using Microsoft.AspNetCore.TestHost;
5+
6+
namespace SimpleWebApp.Tests;
7+
8+
public class EndToEndTests
9+
{
10+
[Fact]
11+
public async Task Search()
12+
{
13+
var query = """
14+
{
15+
search (forString:"") {
16+
items {
17+
__typename
18+
... on Book {
19+
id
20+
title
21+
}
22+
... on Author {
23+
id
24+
firstName
25+
lastName
26+
}
27+
}
28+
}
29+
}
30+
""";
31+
32+
var expected = """
33+
{
34+
"data": {
35+
"search": {
36+
"items": [
37+
{
38+
"__typename": "Book",
39+
"id": "Qm9vazox",
40+
"title": "A Lone Wolf in the Forest"
41+
},
42+
{
43+
"__typename": "Book",
44+
"id": "Qm9vazoy",
45+
"title": "Surfer Boy"
46+
},
47+
{
48+
"__typename": "Book",
49+
"id": "Qm9vazoz",
50+
"title": "GraphQL, a Love Story"
51+
},
52+
{
53+
"__typename": "Book",
54+
"id": "Qm9vazo0",
55+
"title": "Dare I Say What?"
56+
},
57+
{
58+
"__typename": "Author",
59+
"id": "QXV0aG9yOjE=",
60+
"firstName": "Benny",
61+
"lastName": "Frank"
62+
}
63+
]
64+
}
65+
}
66+
}
67+
""";
68+
69+
using var webApp = new WebApplicationFactory<GraphQL.Conventions.Tests.Server.Program>();
70+
using var server = webApp.Server;
71+
server.AllowSynchronousIO = true; // for Newtonsoft.Json support
72+
await VerifyGraphQLPostAsync(server, "/graphql", query, expected).ConfigureAwait(false);
73+
}
74+
75+
private static async Task VerifyGraphQLPostAsync(
76+
TestServer server,
77+
string url,
78+
string query,
79+
string expected,
80+
HttpStatusCode statusCode = HttpStatusCode.OK)
81+
{
82+
using var client = server.CreateClient();
83+
var body = JsonSerializer.Serialize(new { query });
84+
var content = new StringContent(body, System.Text.Encoding.UTF8, "application/json");
85+
using var request = new HttpRequestMessage(HttpMethod.Post, url);
86+
request.Content = content;
87+
using var response = await client.SendAsync(request).ConfigureAwait(false);
88+
Assert.Equal(statusCode, response.StatusCode);
89+
var ret = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
90+
var jsonExpected = JsonSerializer.Serialize(JsonSerializer.Deserialize<JsonElement>(expected));
91+
var jsonActual = JsonSerializer.Serialize(JsonSerializer.Deserialize<JsonElement>(ret));
92+
Assert.Equal(jsonExpected, jsonActual);
93+
}
94+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
12+
<PackageReference Include="xunit" Version="2.4.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
<PrivateAssets>all</PrivateAssets>
16+
</PackageReference>
17+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.*" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\SimpleWebApp\SimpleWebApp.csproj" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Using Include="Xunit"/>
26+
</ItemGroup>
27+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using GraphQL.Conventions;
2+
using GraphQL.Conventions.Tests.Server;
3+
using GraphQL.Conventions.Tests.Server.Data.Repositories;
4+
using GraphQL.Conventions.Tests.Server.Schema;
5+
using GraphQL.Conventions.Web;
6+
7+
namespace SimpleWebApp.Tests;
8+
9+
public class SimpleWebAppSchemaCreationTests
10+
{
11+
[Fact]
12+
public async Task TestSimpleWebAppAsync()
13+
{
14+
var dependencyInjector = new DependencyInjector();
15+
dependencyInjector.Register<IBookRepository>(new BookRepository());
16+
dependencyInjector.Register<IAuthorRepository>(new AuthorRepository());
17+
18+
var requestHandler = RequestHandler
19+
.New()
20+
.WithDependencyInjector(dependencyInjector)
21+
.WithQueryAndMutation<Query, Mutation>()
22+
.Generate();
23+
24+
var request = Request.New(new QueryInput { QueryString = "{ __schema { types { name } } }" });
25+
var result = await requestHandler.ProcessRequestAsync(request, null, dependencyInjector);
26+
27+
Assert.False(result.HasErrors);
28+
Assert.True(result.IsValid);
29+
}
30+
}

samples/SimpleWebApp/Program.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.IO;
21
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
33
using Microsoft.Extensions.Logging;
44

55
namespace GraphQL.Conventions.Tests.Server
@@ -8,15 +8,16 @@ public class Program
88
{
99
public static void Main(string[] args)
1010
{
11-
var host = new WebHostBuilder()
12-
.UseKestrel(options => options.AllowSynchronousIO = true) // for Newtonsoft.Json support
13-
.UseContentRoot(Directory.GetCurrentDirectory())
14-
.UseIISIntegration()
15-
.UseStartup<Startup>()
16-
.ConfigureLogging(l => l.AddConsole())
17-
.Build();
11+
var host = CreateHostBuilder(args).Build();
1812

1913
host.Run();
2014
}
15+
16+
public static IHostBuilder CreateHostBuilder(string[] args) => Host
17+
.CreateDefaultBuilder(args)
18+
.ConfigureWebHostDefaults(webBuilder => webBuilder
19+
.UseStartup<Startup>()
20+
.ConfigureKestrel(options => options.AllowSynchronousIO = true)) // for Newtonsoft.Json support
21+
.ConfigureLogging(l => l.AddConsole());
2122
}
2223
}

samples/SimpleWebApp/SimpleWebApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<LangVersion>9.0</LangVersion>
66
<RootNamespace>GraphQL.Conventions.Tests.Server</RootNamespace>
77
</PropertyGroup>

0 commit comments

Comments
 (0)