Skip to content

Commit f823574

Browse files
authored
Bump to GraphQL.NET v8 (#266)
1 parent bdc6033 commit f823574

File tree

16 files changed

+151
-110
lines changed

16 files changed

+151
-110
lines changed

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/DataLoaderWithEFCore.csproj

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

33
<PropertyGroup>
44
<TargetFrameworks>net6.0</TargetFrameworks>
@@ -15,8 +15,8 @@
1515
<ItemGroup>
1616
<PackageReference Include="AutoMapper" Version="11.0.1" />
1717
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
18-
<PackageReference Include="GraphQL.DataLoader" Version="7.8.0" />
19-
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="7.7.1" />
18+
<PackageReference Include="GraphQL.DataLoader" Version="8.0.0" />
19+
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="8.0.0" />
2020
<ProjectReference Include="../../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
2121
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
2222
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Actor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using AutoMapper;
44
using DataLoaderWithEFCore.Data.Repositories;
5+
using GraphQL;
56
using GraphQL.Conventions;
67
using GraphQL.DataLoader;
78
using Models = DataLoaderWithEFCore.Data.Models;

samples/DataLoaderWithEFCore/DataLoaderWithEFCore/GraphApi/Schema/OutputTypes/Movie.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using AutoMapper;
44
using DataLoaderWithEFCore.Data.Repositories;
5+
using GraphQL;
56
using GraphQL.Conventions;
67
using GraphQL.DataLoader;
78
using Models = DataLoaderWithEFCore.Data.Models;

samples/SubscriptionsGraphQLServer/SubscriptionExample/SubscriptionExample/SubscriptionExample.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="GraphQL.SystemTextJson" Version="7.8.0" />
13-
<PackageReference Include="GraphQL.MicrosoftDI" Version="7.8.0" />
14-
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="7.7.1" />
15-
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="7.7.1" />
12+
<PackageReference Include="GraphQL.SystemTextJson" Version="8.0.0" />
13+
<PackageReference Include="GraphQL.MicrosoftDI" Version="8.0.0" />
14+
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="8.0.0" />
15+
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="8.0.0" />
1616
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" />
1717
<PackageReference Include="System.Reactive" Version="5.0.0" />
1818
</ItemGroup>

src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using GraphQL.Validation;
1919
using GraphQL.Validation.Complexity;
2020
using GraphQL.Validation.Rules.Custom;
21-
using GraphQLParser.AST;
2221

2322
// ReSharper disable once CheckNamespace
2423
namespace GraphQL.Conventions
@@ -39,7 +38,7 @@ public class GraphQLEngine
3938

4039
private readonly GraphQLSerializer _documentSerializer = new GraphQLSerializer();
4140

42-
private SchemaPrinter _schemaPrinter;
41+
private PrintOptions _printOptions;
4342

4443
private ISchema _schema;
4544

@@ -56,24 +55,8 @@ public class GraphQLEngine
5655

5756
private bool _includeFieldDeprecationReasons;
5857

59-
private class NoopValidationRule : IValidationRule
58+
private class NoopValidationRule : ValidationRuleBase
6059
{
61-
public ValueTask<INodeVisitor> ValidateAsync(ValidationContext context) => new(new NoopNodeVisitor());
62-
}
63-
64-
private class NoopNodeVisitor : INodeVisitor
65-
{
66-
public ValueTask EnterAsync(ASTNode node, ValidationContext context)
67-
{
68-
/* Noop */
69-
return default;
70-
}
71-
72-
public ValueTask LeaveAsync(ASTNode node, ValidationContext context)
73-
{
74-
/* Noop */
75-
return default;
76-
}
7760
}
7861

7962
private class WrappedDependencyInjector : IDependencyInjector
@@ -234,7 +217,7 @@ public GraphQLEngine BuildSchema(params Type[] types)
234217
return BuildSchema(null, types);
235218
}
236219

237-
public GraphQLEngine BuildSchema(SchemaPrinterOptions options, params Type[] types)
220+
public GraphQLEngine BuildSchema(PrintOptions options, params Type[] types)
238221
{
239222
if (_schema != null)
240223
return this;
@@ -244,20 +227,19 @@ public GraphQLEngine BuildSchema(SchemaPrinterOptions options, params Type[] typ
244227
}
245228
lock (_schemaLock)
246229
_schema = _constructor.Build(_schemaTypes.ToArray());
247-
_schemaPrinter = new SchemaPrinter(_schema, options ?? new SchemaPrinterOptions
230+
_printOptions = options ?? new PrintOptions()
248231
{
249232
IncludeDescriptions = _includeFieldDescriptions,
250233
IncludeDeprecationReasons = _includeFieldDeprecationReasons,
251-
});
234+
StringComparison = StringComparison.InvariantCultureIgnoreCase,
235+
};
252236
return this;
253237
}
254238

255-
public string Describe(Func<ISchema, SchemaPrinter> ctor = null)
239+
public string Describe(PrintOptions printOptions = null)
256240
{
257241
BuildSchema(); // Ensure that the schema has been constructed
258-
if (ctor != null)
259-
_schemaPrinter = ctor(_schema);
260-
return _schemaPrinter.Print();
242+
return _schema.Print(_printOptions = printOptions ?? _printOptions);
261243
}
262244

263245
public ISchema GetSchema()
@@ -288,7 +270,8 @@ internal async Task<ExecutionResult> ExecuteAsync(
288270
Inputs variables,
289271
IUserContext userContext,
290272
IDependencyInjector dependencyInjector,
291-
ComplexityConfiguration complexityConfiguration,
273+
LegacyComplexityConfiguration complexityConfiguration,
274+
ComplexityOptions complexityOptions,
292275
bool enableValidation = true,
293276
bool enableProfiling = false,
294277
IEnumerable<IValidationRule> rules = null,
@@ -309,7 +292,11 @@ internal async Task<ExecutionResult> ExecuteAsync(
309292

310293
if (complexityConfiguration != null)
311294
{
312-
rules = rules.Append(new ComplexityValidationRule(complexityConfiguration));
295+
rules = rules.Append(new LegacyComplexityValidationRule(complexityConfiguration));
296+
}
297+
if (complexityOptions != null)
298+
{
299+
rules = rules.Append(new ComplexityValidationRule(complexityOptions));
313300
}
314301

315302
var configuration = new ExecutionOptions
@@ -370,7 +357,7 @@ internal async Task<IValidationResult> ValidateAsync(string queryString)
370357
Document = document
371358
});
372359

373-
return result.validationResult;
360+
return result;
374361
}
375362

376363
private object CreateInstance(Type type)

src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Threading;
34
using System.Threading.Tasks;
@@ -34,7 +35,8 @@ public class GraphQLExecutor : IGraphQLExecutor<ExecutionResult>
3435

3536
private IEnumerable<IValidationRule> _validationRules;
3637

37-
private ComplexityConfiguration _complexityConfiguration;
38+
private LegacyComplexityConfiguration _complexityConfiguration;
39+
private ComplexityOptions _complexityOptions;
3840

3941
private IEnumerable<IDocumentExecutionListener> _documentExecutionListeners;
4042

@@ -117,12 +119,19 @@ public IGraphQLExecutor<ExecutionResult> EnableValidation(bool enableValidation
117119
return this;
118120
}
119121

120-
public IGraphQLExecutor<ExecutionResult> WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration)
122+
[Obsolete("Please use the WithComplexityOptions method instead.")]
123+
public IGraphQLExecutor<ExecutionResult> WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration)
121124
{
122125
_complexityConfiguration = complexityConfiguration;
123126
return this;
124127
}
125128

129+
public IGraphQLExecutor<ExecutionResult> WithComplexityOptions(ComplexityOptions complexityOptions)
130+
{
131+
_complexityOptions = complexityOptions;
132+
return this;
133+
}
134+
126135
public IGraphQLExecutor<ExecutionResult> DisableValidation()
127136
{
128137
return EnableValidation(false);
@@ -146,6 +155,7 @@ public Task<ExecutionResult> ExecuteAsync()
146155
enableProfiling: _enableProfiling,
147156
rules: _validationRules,
148157
complexityConfiguration: _complexityConfiguration,
158+
complexityOptions: _complexityOptions,
149159
cancellationToken: _cancellationToken,
150160
listeners: _documentExecutionListeners);
151161

src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Threading;
34
using System.Threading.Tasks;
@@ -30,7 +31,10 @@ public interface IGraphQLExecutor<TResult>
3031

3132
IGraphQLExecutor<TResult> WithValidationRules(IEnumerable<IValidationRule> rules);
3233

33-
IGraphQLExecutor<TResult> WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration);
34+
[Obsolete("Please use the WithComplexityOptions method instead.")]
35+
IGraphQLExecutor<TResult> WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration);
36+
37+
IGraphQLExecutor<TResult> WithComplexityOptions(ComplexityOptions complexityOptions);
3438

3539
IGraphQLExecutor<TResult> WithListeners(params IDocumentExecutionListener[] listeners);
3640

src/GraphQL.Conventions/Adapters/Types/IdGraphType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ public override object ParseValue(object value)
1111
}
1212
return new Id(value.ToString());
1313
}
14+
15+
public override object Serialize(object value)
16+
=> value is Id idValue ? idValue.ToString() : base.Serialize(value);
1417
}
1518
}

src/GraphQL.Conventions/GraphQL.Conventions.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="GraphQL.DataLoader" Version="7.8.0" />
31-
<PackageReference Include="GraphQL.NewtonsoftJson" Version="7.8.0" />
30+
<PackageReference Include="GraphQL" Version="8.0.1" />
31+
<PackageReference Include="GraphQL.DataLoader" Version="8.0.0" />
32+
<PackageReference Include="GraphQL.NewtonsoftJson" Version="8.0.0" />
3233
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
3334
</ItemGroup>
3435

src/GraphQL.Conventions/Web/RequestHandler.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class RequestHandlerBuilder : IDependencyInjector
3131
private bool _useValidation = true;
3232
private bool _useProfiling;
3333
private FieldResolutionStrategy _fieldResolutionStrategy = FieldResolutionStrategy.Normal;
34-
private ComplexityConfiguration _complexityConfiguration;
34+
private LegacyComplexityConfiguration _complexityConfiguration;
35+
private ComplexityOptions _complexityOptions;
3536

3637
internal RequestHandlerBuilder()
3738
{
@@ -139,12 +140,19 @@ public RequestHandlerBuilder WithFieldResolutionStrategy(FieldResolutionStrategy
139140
return this;
140141
}
141142

142-
public RequestHandlerBuilder WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration)
143+
[Obsolete("Please use the WithComplexityOptions method instead.")]
144+
public RequestHandlerBuilder WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration)
143145
{
144146
_complexityConfiguration = complexityConfiguration;
145147
return this;
146148
}
147149

150+
public RequestHandlerBuilder WithComplexityOptions(ComplexityOptions complexityOptions)
151+
{
152+
_complexityOptions = complexityOptions;
153+
return this;
154+
}
155+
148156
public RequestHandlerBuilder WithMiddleware<T>()
149157
{
150158
_middleware.Add(typeof(T));
@@ -168,6 +176,7 @@ public IRequestHandler Generate()
168176
_useProfiling,
169177
_fieldResolutionStrategy,
170178
_complexityConfiguration,
179+
_complexityOptions,
171180
_middleware,
172181
_typeResolver);
173182
}
@@ -185,7 +194,8 @@ private class RequestHandlerImpl : IRequestHandler
185194
private readonly List<Type> _exceptionsTreatedAsWarnings = new List<Type>();
186195
private readonly bool _useValidation;
187196
private readonly bool _useProfiling;
188-
private readonly ComplexityConfiguration _complexityConfiguration;
197+
private readonly LegacyComplexityConfiguration _complexityConfiguration;
198+
private readonly ComplexityOptions _complexityOptions;
189199

190200
internal RequestHandlerImpl(
191201
IDependencyInjector dependencyInjector,
@@ -195,7 +205,8 @@ internal RequestHandlerImpl(
195205
bool useValidation,
196206
bool useProfiling,
197207
FieldResolutionStrategy fieldResolutionStrategy,
198-
ComplexityConfiguration complexityConfiguration,
208+
LegacyComplexityConfiguration complexityConfiguration,
209+
ComplexityOptions complexityOptions,
199210
IEnumerable<Type> middleware,
200211
ITypeResolver typeResolver)
201212
{
@@ -208,6 +219,7 @@ internal RequestHandlerImpl(
208219
_engine.WithFieldResolutionStrategy(fieldResolutionStrategy);
209220
_engine.BuildSchema(schemaTypes.ToArray());
210221
_complexityConfiguration = complexityConfiguration;
222+
_complexityOptions = complexityOptions;
211223

212224
foreach (var type in middleware)
213225
{
@@ -227,6 +239,7 @@ public async Task<Response> ProcessRequestAsync(Request request, IUserContext us
227239
.WithDependencyInjector(dependencyInjector ?? _dependencyInjector)
228240
.WithUserContext(userContext)
229241
.WithComplexityConfiguration(_complexityConfiguration)
242+
.WithComplexityOptions(_complexityOptions)
230243
.EnableValidation(_useValidation)
231244
.EnableProfiling(_useProfiling)
232245
.ExecuteAsync()

0 commit comments

Comments
 (0)