Skip to content

Commit a0e0ed7

Browse files
authored
GraphQL 7 (#768)
1 parent 0ea0744 commit a0e0ed7

File tree

12 files changed

+42
-66
lines changed

12 files changed

+42
-66
lines changed

docs/defining-graphs.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,9 @@ In some cases, it may be necessary to use `Field` instead of `AddQueryField`/`Ad
308308
<!-- snippet: ManuallyApplyWhere -->
309309
<a id='snippet-manuallyapplywhere'></a>
310310
```cs
311-
Field<ListGraphType<EmployeeSummaryGraphType>>(
312-
name: "employeeSummary",
313-
arguments: new(
314-
new QueryArgument<ListGraphType<WhereExpressionGraph>>
315-
{
316-
Name = "where"
317-
}
318-
),
319-
resolve: context =>
311+
Field<ListGraphType<EmployeeSummaryGraphType>>("employeeSummary")
312+
.Argument<ListGraphType<WhereExpressionGraph>>("where")
313+
.Resolve(context =>
320314
{
321315
var dbContext = ResolveDbContext(context);
322316
IQueryable<Employee> query = dbContext.Employees;
@@ -330,7 +324,10 @@ Field<ListGraphType<EmployeeSummaryGraphType>>(
330324
}
331325

332326
return from q in query
333-
group q by new {q.CompanyId}
327+
group q by new
328+
{
329+
q.CompanyId
330+
}
334331
into g
335332
select new EmployeeSummary
336333
{
@@ -339,7 +336,7 @@ Field<ListGraphType<EmployeeSummaryGraphType>>(
339336
};
340337
});
341338
```
342-
<sup><a href='/src/SampleWeb/Query.cs#L53-L86' title='Snippet source file'>snippet source</a> | <a href='#snippet-manuallyapplywhere' title='Start of snippet'>anchor</a></sup>
339+
<sup><a href='/src/SampleWeb/Query.cs#L53-L83' title='Snippet source file'>snippet source</a> | <a href='#snippet-manuallyapplywhere' title='Start of snippet'>anchor</a></sup>
343340
<!-- endSnippet -->
344341

345342

@@ -355,17 +352,16 @@ public class Query :
355352
{
356353
public Query(IEfGraphQLService<MyDbContext> graphQlService) :
357354
base(graphQlService) =>
358-
Field<ListGraphType<CompanyGraph>>(
359-
name: "oldCompanies",
360-
resolve: context =>
355+
Field<ListGraphType<CompanyGraph>>("oldCompanies")
356+
.Resolve(context =>
361357
{
362358
// uses the base QueryGraphType to resolve the db context
363359
var dbContext = ResolveDbContext(context);
364360
return dbContext.Companies.Where(x => x.Age > 10);
365361
});
366362
}
367363
```
368-
<sup><a href='/src/Snippets/ResolveDbContextQuery.cs#L7-L24' title='Snippet source file'>snippet source</a> | <a href='#snippet-queryresolvedbcontext' title='Start of snippet'>anchor</a></sup>
364+
<sup><a href='/src/Snippets/ResolveDbContextQuery.cs#L7-L23' title='Snippet source file'>snippet source</a> | <a href='#snippet-queryresolvedbcontext' title='Start of snippet'>anchor</a></sup>
369365
<!-- endSnippet -->
370366

371367

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;NU5104;CS1573</NoWarn>
5-
<Version>17.1.0</Version>
5+
<Version>18.0.0</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
88
<SignAssembly>false</SignAssembly>

src/GraphQL.EntityFramework/GraphQL.EntityFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.1" PrivateAssets="All" />
88
<PackageReference Include="Fody" Version="6.6.3" PrivateAssets="all" />
99
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
10-
<PackageReference Include="GraphQL" Version="5.3.3" />
10+
<PackageReference Include="GraphQL" Version="7.0.1" />
1111
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1212
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
1313
<PackageReference Include="NullabilityInfo" Version="1.0.7" PrivateAssets="all" />

src/GraphQL.EntityFramework/Mapping/Mapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ static void AddMember<TSource>(ComplexGraphType<TSource> graph, PropertyInfo pro
165165
{
166166
var (compile, propertyGraphType) = Compile<TSource>(property);
167167
var resolver = new SimpleFieldResolver<TSource>(compile);
168-
var graphQlField = graph.Field(type: propertyGraphType, name: property.Name);
169-
graphQlField.Resolver = resolver;
168+
graph.Field(type: propertyGraphType, name: property.Name)
169+
.Resolve(resolver);
170170
}
171171

172172
static bool ShouldIgnore(IComplexGraphType graphType, string name, Type propertyType, IReadOnlyList<string>? localIgnores = null)

src/GraphQL.EntityFramework/Where/Graphs/ArgumentGraphs.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@
44

55
static class ArgumentGraphs
66
{
7-
static Dictionary<Type, GraphType> entries = new();
8-
9-
[ModuleInitializer]
10-
public static void Initialize()
11-
{
12-
Add<EnumerationGraphType<StringComparison>>();
13-
Add<WhereExpressionGraph>();
14-
Add<OrderByGraph>();
15-
Add<ComparisonGraph>();
16-
Add<ConnectorGraph>();
17-
}
18-
197
public static void RegisterInContainer(IServiceCollection services)
208
{
21-
foreach (var entry in entries)
22-
{
23-
services.AddSingleton(entry.Key, entry.Value);
24-
}
25-
}
26-
27-
static void Add<T>()
28-
where T : GraphType, new()
29-
{
30-
var value = new T();
31-
entries.Add(typeof(T), value);
9+
services.AddSingleton<EnumerationGraphType<StringComparison>>();
10+
services.AddSingleton<WhereExpressionGraph>();
11+
services.AddSingleton<OrderByGraph>();
12+
services.AddSingleton<ComparisonGraph>();
13+
services.AddSingleton<ConnectorGraph>();
3214
}
3315
}

src/GraphQL.EntityFramework/Where/Graphs/WhereExpressionGraph.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ public WhereExpressionGraph()
99
{
1010
Name = nameof(WhereExpression);
1111
Field(x => x.Path, true);
12-
Field<ComparisonGraph>("comparison", null, null, _ => _.Source.Comparison);
12+
Field<ComparisonGraph>("comparison")
13+
.Resolve(_ => _.Source.Comparison);
1314
Field(x => x.Negate, true);
14-
Field<EnumerationGraphType<StringComparison>>("case", null, null, _ => _.Source.Case);
15+
Field<EnumerationGraphType<StringComparison>>("case")
16+
.Resolve( _ => _.Source.Case);
1517
Field(x => x.Value, true);
16-
Field<ConnectorGraph>("connector", null, null, _ => _.Source.Connector);
17-
Field<ListGraphType<WhereExpressionGraph>>(
18-
name: "GroupedExpressions");
18+
Field<ConnectorGraph>("connector")
19+
.Resolve(_ => _.Source.Connector);
20+
Field<ListGraphType<WhereExpressionGraph>>("GroupedExpressions");
1921
}
2022
}

src/SampleWeb.Tests/SampleWeb.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>net6.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="GraphQL" Version="5.3.3" />
6+
<PackageReference Include="GraphQL" Version="7.0.1" />
77
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.8" />
88
<PackageReference Include="Xunit" Version="2.4.2" />
99
<PackageReference Include="Verify.Xunit" Version="17.10.2" />

src/SampleWeb/Query.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ public Query(IEfGraphQLService<SampleDbContext> efGraphQlService) :
5252

5353
#region ManuallyApplyWhere
5454

55-
Field<ListGraphType<EmployeeSummaryGraphType>>(
56-
name: "employeeSummary",
57-
arguments: new(
58-
new QueryArgument<ListGraphType<WhereExpressionGraph>>
59-
{
60-
Name = "where"
61-
}
62-
),
63-
resolve: context =>
55+
Field<ListGraphType<EmployeeSummaryGraphType>>("employeeSummary")
56+
.Argument<ListGraphType<WhereExpressionGraph>>("where")
57+
.Resolve(context =>
6458
{
6559
var dbContext = ResolveDbContext(context);
6660
IQueryable<Employee> query = dbContext.Employees;
@@ -74,7 +68,10 @@ public Query(IEfGraphQLService<SampleDbContext> efGraphQlService) :
7468
}
7569

7670
return from q in query
77-
group q by new {q.CompanyId}
71+
group q by new
72+
{
73+
q.CompanyId
74+
}
7875
into g
7976
select new EmployeeSummary
8077
{

src/SampleWeb/SampleWeb.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Folder Include="wwwroot\" />
77
<PackageReference Include="EfLocalDb" Version="13.9.3" />
88
<PackageReference Include="graphiql" Version="2.0.0" />
9-
<PackageReference Include="GraphQL.SystemTextJson" Version="5.3.3" />
10-
<PackageReference Include="GraphQL" Version="5.3.3" />
9+
<PackageReference Include="GraphQL.SystemTextJson" Version="7.0.1" />
10+
<PackageReference Include="GraphQL" Version="7.0.1" />
1111
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
1212
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
1313
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

src/Snippets/ResolveDbContextQuery.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ public class Query :
1111
{
1212
public Query(IEfGraphQLService<MyDbContext> graphQlService) :
1313
base(graphQlService) =>
14-
Field<ListGraphType<CompanyGraph>>(
15-
name: "oldCompanies",
16-
resolve: context =>
14+
Field<ListGraphType<CompanyGraph>>("oldCompanies")
15+
.Resolve(context =>
1716
{
1817
// uses the base QueryGraphType to resolve the db context
1918
var dbContext = ResolveDbContext(context);

0 commit comments

Comments
 (0)