Skip to content

Commit

Permalink
Bump to GraphQL.NET v8 (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Aug 24, 2024
1 parent bdc6033 commit f823574
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
Expand All @@ -15,8 +15,8 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="GraphQL.DataLoader" Version="7.8.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="7.7.1" />
<PackageReference Include="GraphQL.DataLoader" Version="8.0.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="8.0.0" />
<ProjectReference Include="../../../src/GraphQL.Conventions/GraphQL.Conventions.csproj" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using AutoMapper;
using DataLoaderWithEFCore.Data.Repositories;
using GraphQL;
using GraphQL.Conventions;
using GraphQL.DataLoader;
using Models = DataLoaderWithEFCore.Data.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using AutoMapper;
using DataLoaderWithEFCore.Data.Repositories;
using GraphQL;
using GraphQL.Conventions;
using GraphQL.DataLoader;
using Models = DataLoaderWithEFCore.Data.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.SystemTextJson" Version="7.8.0" />
<PackageReference Include="GraphQL.MicrosoftDI" Version="7.8.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="7.7.1" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="7.7.1" />
<PackageReference Include="GraphQL.SystemTextJson" Version="8.0.0" />
<PackageReference Include="GraphQL.MicrosoftDI" Version="8.0.0" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="8.0.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>
Expand Down
45 changes: 16 additions & 29 deletions src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using GraphQL.Validation;
using GraphQL.Validation.Complexity;
using GraphQL.Validation.Rules.Custom;
using GraphQLParser.AST;

// ReSharper disable once CheckNamespace
namespace GraphQL.Conventions
Expand All @@ -39,7 +38,7 @@ public class GraphQLEngine

private readonly GraphQLSerializer _documentSerializer = new GraphQLSerializer();

private SchemaPrinter _schemaPrinter;
private PrintOptions _printOptions;

private ISchema _schema;

Expand All @@ -56,24 +55,8 @@ public class GraphQLEngine

private bool _includeFieldDeprecationReasons;

private class NoopValidationRule : IValidationRule
private class NoopValidationRule : ValidationRuleBase
{
public ValueTask<INodeVisitor> ValidateAsync(ValidationContext context) => new(new NoopNodeVisitor());
}

private class NoopNodeVisitor : INodeVisitor
{
public ValueTask EnterAsync(ASTNode node, ValidationContext context)
{
/* Noop */
return default;
}

public ValueTask LeaveAsync(ASTNode node, ValidationContext context)
{
/* Noop */
return default;
}
}

private class WrappedDependencyInjector : IDependencyInjector
Expand Down Expand Up @@ -234,7 +217,7 @@ public GraphQLEngine BuildSchema(params Type[] types)
return BuildSchema(null, types);
}

public GraphQLEngine BuildSchema(SchemaPrinterOptions options, params Type[] types)
public GraphQLEngine BuildSchema(PrintOptions options, params Type[] types)
{
if (_schema != null)
return this;
Expand All @@ -244,20 +227,19 @@ public GraphQLEngine BuildSchema(SchemaPrinterOptions options, params Type[] typ
}
lock (_schemaLock)
_schema = _constructor.Build(_schemaTypes.ToArray());
_schemaPrinter = new SchemaPrinter(_schema, options ?? new SchemaPrinterOptions
_printOptions = options ?? new PrintOptions()
{
IncludeDescriptions = _includeFieldDescriptions,
IncludeDeprecationReasons = _includeFieldDeprecationReasons,
});
StringComparison = StringComparison.InvariantCultureIgnoreCase,
};
return this;
}

public string Describe(Func<ISchema, SchemaPrinter> ctor = null)
public string Describe(PrintOptions printOptions = null)
{
BuildSchema(); // Ensure that the schema has been constructed
if (ctor != null)
_schemaPrinter = ctor(_schema);
return _schemaPrinter.Print();
return _schema.Print(_printOptions = printOptions ?? _printOptions);
}

public ISchema GetSchema()
Expand Down Expand Up @@ -288,7 +270,8 @@ internal async Task<ExecutionResult> ExecuteAsync(
Inputs variables,
IUserContext userContext,
IDependencyInjector dependencyInjector,
ComplexityConfiguration complexityConfiguration,
LegacyComplexityConfiguration complexityConfiguration,

Check warning on line 273 in src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 273 in src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 273 in src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'
ComplexityOptions complexityOptions,
bool enableValidation = true,
bool enableProfiling = false,
IEnumerable<IValidationRule> rules = null,
Expand All @@ -309,7 +292,11 @@ internal async Task<ExecutionResult> ExecuteAsync(

if (complexityConfiguration != null)
{
rules = rules.Append(new ComplexityValidationRule(complexityConfiguration));
rules = rules.Append(new LegacyComplexityValidationRule(complexityConfiguration));

Check warning on line 295 in src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityValidationRule' is obsolete: 'Please use the new complexity analyzer. The v7 complexity analyzer will be removed in v9.'

Check warning on line 295 in src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityValidationRule' is obsolete: 'Please use the new complexity analyzer. The v7 complexity analyzer will be removed in v9.'
}
if (complexityOptions != null)
{
rules = rules.Append(new ComplexityValidationRule(complexityOptions));
}

var configuration = new ExecutionOptions
Expand Down Expand Up @@ -370,7 +357,7 @@ internal async Task<IValidationResult> ValidateAsync(string queryString)
Document = document
});

return result.validationResult;
return result;
}

private object CreateInstance(Type type)
Expand Down
14 changes: 12 additions & 2 deletions src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -34,7 +35,8 @@ public class GraphQLExecutor : IGraphQLExecutor<ExecutionResult>

private IEnumerable<IValidationRule> _validationRules;

private ComplexityConfiguration _complexityConfiguration;
private LegacyComplexityConfiguration _complexityConfiguration;

Check warning on line 38 in src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 38 in src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 38 in src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'
private ComplexityOptions _complexityOptions;

private IEnumerable<IDocumentExecutionListener> _documentExecutionListeners;

Expand Down Expand Up @@ -117,12 +119,19 @@ public IGraphQLExecutor<ExecutionResult> EnableValidation(bool enableValidation
return this;
}

public IGraphQLExecutor<ExecutionResult> WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration)
[Obsolete("Please use the WithComplexityOptions method instead.")]
public IGraphQLExecutor<ExecutionResult> WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration)
{
_complexityConfiguration = complexityConfiguration;
return this;
}

public IGraphQLExecutor<ExecutionResult> WithComplexityOptions(ComplexityOptions complexityOptions)
{
_complexityOptions = complexityOptions;
return this;
}

public IGraphQLExecutor<ExecutionResult> DisableValidation()
{
return EnableValidation(false);
Expand All @@ -146,6 +155,7 @@ public Task<ExecutionResult> ExecuteAsync()
enableProfiling: _enableProfiling,
rules: _validationRules,
complexityConfiguration: _complexityConfiguration,
complexityOptions: _complexityOptions,
cancellationToken: _cancellationToken,
listeners: _documentExecutionListeners);

Expand Down
6 changes: 5 additions & 1 deletion src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -30,7 +31,10 @@ public interface IGraphQLExecutor<TResult>

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

IGraphQLExecutor<TResult> WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration);
[Obsolete("Please use the WithComplexityOptions method instead.")]
IGraphQLExecutor<TResult> WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration);

IGraphQLExecutor<TResult> WithComplexityOptions(ComplexityOptions complexityOptions);

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

Expand Down
3 changes: 3 additions & 0 deletions src/GraphQL.Conventions/Adapters/Types/IdGraphType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public override object ParseValue(object value)
}
return new Id(value.ToString());
}

public override object Serialize(object value)
=> value is Id idValue ? idValue.ToString() : base.Serialize(value);
}
}
5 changes: 3 additions & 2 deletions src/GraphQL.Conventions/GraphQL.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.DataLoader" Version="7.8.0" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="7.8.0" />
<PackageReference Include="GraphQL" Version="8.0.1" />
<PackageReference Include="GraphQL.DataLoader" Version="8.0.0" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

Expand Down
21 changes: 17 additions & 4 deletions src/GraphQL.Conventions/Web/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class RequestHandlerBuilder : IDependencyInjector
private bool _useValidation = true;
private bool _useProfiling;
private FieldResolutionStrategy _fieldResolutionStrategy = FieldResolutionStrategy.Normal;
private ComplexityConfiguration _complexityConfiguration;
private LegacyComplexityConfiguration _complexityConfiguration;

Check warning on line 34 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 34 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 34 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 34 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'
private ComplexityOptions _complexityOptions;

internal RequestHandlerBuilder()
{
Expand Down Expand Up @@ -139,12 +140,19 @@ public RequestHandlerBuilder WithFieldResolutionStrategy(FieldResolutionStrategy
return this;
}

public RequestHandlerBuilder WithComplexityConfiguration(ComplexityConfiguration complexityConfiguration)
[Obsolete("Please use the WithComplexityOptions method instead.")]
public RequestHandlerBuilder WithComplexityConfiguration(LegacyComplexityConfiguration complexityConfiguration)
{
_complexityConfiguration = complexityConfiguration;
return this;
}

public RequestHandlerBuilder WithComplexityOptions(ComplexityOptions complexityOptions)
{
_complexityOptions = complexityOptions;
return this;
}

public RequestHandlerBuilder WithMiddleware<T>()
{
_middleware.Add(typeof(T));
Expand All @@ -168,6 +176,7 @@ public IRequestHandler Generate()
_useProfiling,
_fieldResolutionStrategy,
_complexityConfiguration,
_complexityOptions,
_middleware,
_typeResolver);
}
Expand All @@ -185,7 +194,8 @@ private class RequestHandlerImpl : IRequestHandler
private readonly List<Type> _exceptionsTreatedAsWarnings = new List<Type>();
private readonly bool _useValidation;
private readonly bool _useProfiling;
private readonly ComplexityConfiguration _complexityConfiguration;
private readonly LegacyComplexityConfiguration _complexityConfiguration;

Check warning on line 197 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 197 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 197 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'
private readonly ComplexityOptions _complexityOptions;

internal RequestHandlerImpl(
IDependencyInjector dependencyInjector,
Expand All @@ -195,7 +205,8 @@ internal RequestHandlerImpl(
bool useValidation,
bool useProfiling,
FieldResolutionStrategy fieldResolutionStrategy,
ComplexityConfiguration complexityConfiguration,
LegacyComplexityConfiguration complexityConfiguration,

Check warning on line 208 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 208 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'

Check warning on line 208 in src/GraphQL.Conventions/Web/RequestHandler.cs

View workflow job for this annotation

GitHub Actions / build

'LegacyComplexityConfiguration' is obsolete: 'Please use the new complexity analyzer. This class will be removed in v9.'
ComplexityOptions complexityOptions,
IEnumerable<Type> middleware,
ITypeResolver typeResolver)
{
Expand All @@ -208,6 +219,7 @@ internal RequestHandlerImpl(
_engine.WithFieldResolutionStrategy(fieldResolutionStrategy);
_engine.BuildSchema(schemaTypes.ToArray());
_complexityConfiguration = complexityConfiguration;
_complexityOptions = complexityOptions;

foreach (var type in middleware)
{
Expand All @@ -227,6 +239,7 @@ public async Task<Response> ProcessRequestAsync(Request request, IUserContext us
.WithDependencyInjector(dependencyInjector ?? _dependencyInjector)
.WithUserContext(userContext)
.WithComplexityConfiguration(_complexityConfiguration)
.WithComplexityOptions(_complexityOptions)
.EnableValidation(_useValidation)
.EnableProfiling(_useProfiling)
.ExecuteAsync()
Expand Down
Loading

0 comments on commit f823574

Please sign in to comment.