Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to GraphQL.NET v8 #266

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

private readonly GraphQLSerializer _documentSerializer = new GraphQLSerializer();

private SchemaPrinter _schemaPrinter;
private PrintOptions _printOptions;

private ISchema _schema;

Expand All @@ -56,24 +55,8 @@

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 @@
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 @@
}
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 @@
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 / test

'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 / test

'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 / test

'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 @@

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 / test

'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 / test

'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 @@
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 @@

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 / test

'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 / test

'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 / test

'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 @@
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 @@
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 @@
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 / test

'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 / test

'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 / test

'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 / test

'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 @@
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 @@
_useProfiling,
_fieldResolutionStrategy,
_complexityConfiguration,
_complexityOptions,
_middleware,
_typeResolver);
}
Expand All @@ -185,7 +194,8 @@
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 / test

'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 / test

'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 / test

'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 @@
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 / test

'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 / test

'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 / test

'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 @@
_engine.WithFieldResolutionStrategy(fieldResolutionStrategy);
_engine.BuildSchema(schemaTypes.ToArray());
_complexityConfiguration = complexityConfiguration;
_complexityOptions = complexityOptions;

foreach (var type in middleware)
{
Expand All @@ -219,7 +231,7 @@
{
var start = DateTime.UtcNow;

var result = await _engine

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

View workflow job for this annotation

GitHub Actions / test

'IGraphQLExecutor<ExecutionResult>.WithComplexityConfiguration(LegacyComplexityConfiguration)' is obsolete: 'Please use the WithComplexityOptions method instead.'

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

View workflow job for this annotation

GitHub Actions / test

'IGraphQLExecutor<ExecutionResult>.WithComplexityConfiguration(LegacyComplexityConfiguration)' is obsolete: 'Please use the WithComplexityOptions method instead.'
.NewExecutor()
.WithQueryString(request.QueryString)
.WithVariables(request.Variables)
Expand All @@ -227,6 +239,7 @@
.WithDependencyInjector(dependencyInjector ?? _dependencyInjector)
.WithUserContext(userContext)
.WithComplexityConfiguration(_complexityConfiguration)
.WithComplexityOptions(_complexityOptions)
.EnableValidation(_useValidation)
.EnableProfiling(_useProfiling)
.ExecuteAsync()
Expand Down
Loading
Loading