Skip to content

Commit

Permalink
Upgrade GraphQL to 8.2 (#16736)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Nov 22, 2024
1 parent e98ec92 commit 5dc244b
Show file tree
Hide file tree
Showing 49 changed files with 417 additions and 202 deletions.
17 changes: 13 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Project>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<PropertyGroup>
<!-- Special case - this property is used by a DotNetCliToolReference -->
<DotNetXunitVersion>2.3.0</DotNetXunitVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="AngleSharp" Version="1.1.2" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.405.14" />
Expand All @@ -22,10 +25,10 @@
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.1.1" />
<PackageVersion Include="Fluid.Core" Version="2.12.0" />
<PackageVersion Include="GraphQL" Version="7.9.0" />
<PackageVersion Include="GraphQL.DataLoader" Version="7.9.0" />
<PackageVersion Include="GraphQL.MicrosoftDI" Version="7.9.0" />
<PackageVersion Include="GraphQL.SystemTextJson" Version="7.9.0" />
<PackageVersion Include="GraphQL" Version="8.2.1" />
<PackageVersion Include="GraphQL.DataLoader" Version="8.2.1" />
<PackageVersion Include="GraphQL.MicrosoftDI" Version="8.2.1" />
<PackageVersion Include="GraphQL.SystemTextJson" Version="8.2.1" />
<PackageVersion Include="Jint" Version="4.1.0" />
<PackageVersion Include="JsonPath.Net" Version="1.1.6" />
<PackageVersion Include="HtmlSanitizer" Version="8.2.871-beta" />
Expand Down Expand Up @@ -88,6 +91,7 @@
<!-- dotnet/extensions -->
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.11.0" />
Expand All @@ -96,6 +100,7 @@
<!-- These versions are used for tansitive dependency forced upgrades only. E.g. when a package references a vulnerable version. -->
<!-- To list all vulnerable direct references run 'dotnet list package -vulnerable' (use double dash, just XML comments can't contain it) -->
<!-- To list all vulnerable transitive references run 'dotnet list package -vulnerable -include-transitive' (use double dash, just XML comments can't contain it) -->

<!-- The dependency graphs are generated using 'dotnet nuget why <.sln> <package id>' -->
<ItemGroup>
<!--
Expand All @@ -116,6 +121,7 @@
-->
<!-- When removing this, remove the corresponding ignore in dependabot.yml too. -->
<PackageVersion Include="System.Drawing.Common" Version="4.7.2" />

<!--
OrchardCore.Media.Indexing.OpenXML (v2.1.0-preview)
└─ DocumentFormat.OpenXml (v3.1.0)
Expand Down Expand Up @@ -147,6 +153,7 @@
<AspNetCorePackagesVersion>8.0.11</AspNetCorePackagesVersion>
<MicrosoftExtensionsPackagesVersion>8.0.11</MicrosoftExtensionsPackagesVersion>
</PropertyGroup>

<!-- When dual-targeting frameworks, add both of them to CommonTargetFrameworks above, when add PropertyGroups like
below. -->
<!--<PropertyGroup Condition="$(TargetFramework) == 'net7.0'">
Expand All @@ -167,7 +174,9 @@
</ItemGroup>
<!-- 'Microsoft.Extensions' packages that are not included in the ASP.NET Core shared framework -->
<ItemGroup>

<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="$(MicrosoftExtensionsPackagesVersion)" />
<!-- Microsoft.Extensions.Http.Resilience is not here because it diverged from the common Microsoft.Extensions versioning. -->
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ validation:
# Add files here that are intentionally not in the navigation and thus omitted_files shouldn't warn about them.
not_in_nav: |
samples/
releases/3.0.0.md
# Extensions
markdown_extensions:
- markdown.extensions.admonition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ private async Task ExecuteAsync(HttpContext context)
options.Variables = request.Variables;
options.UserContext = _settings.BuildUserContext?.Invoke(context);
options.ValidationRules = DocumentValidator.CoreRules
.Concat(context.RequestServices.GetServices<IValidationRule>())
.Append(new ComplexityValidationRule(new ComplexityConfiguration
{
MaxDepth = _settings.MaxDepth,
MaxComplexity = _settings.MaxComplexity,
FieldImpact = _settings.FieldImpact
}));
.Concat(context.RequestServices.GetServices<IValidationRule>())
.Append(new ComplexityValidationRule(new ComplexityOptions
{
MaxDepth = _settings.MaxDepth,
MaxComplexity = _settings.MaxComplexity,
DefaultObjectImpact = _settings.FieldImpact ?? 0,
}));
options.Listeners.Add(dataLoaderDocumentListener);
options.RequestServices = context.RequestServices;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Concurrent;
using GraphQL;
using GraphQL.MicrosoftDI;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Environment.Shell.Scope;

namespace OrchardCore.Apis.GraphQL.Services;

public class SchemaService : ISchemaFactory
public sealed class SchemaService : ISchemaFactory
{
private readonly IEnumerable<ISchemaBuilder> _schemaBuilders;
private readonly IServiceProvider _serviceProvider;
Expand All @@ -15,7 +16,9 @@ public class SchemaService : ISchemaFactory

private ISchema _schema;

public SchemaService(IEnumerable<ISchemaBuilder> schemaBuilders, IServiceProvider serviceProvider)
public SchemaService(
IEnumerable<ISchemaBuilder> schemaBuilders,
IServiceProvider serviceProvider)
{
_schemaBuilders = schemaBuilders;
_serviceProvider = serviceProvider;
Expand Down Expand Up @@ -61,21 +64,23 @@ public async Task<ISchema> GetSchemaAsync()

var schema = new Schema(new SelfActivatingServiceProvider(_serviceProvider))
{
Query = new ObjectGraphType { Name = "Query" },
Mutation = new ObjectGraphType { Name = "Mutation" },
Subscription = new ObjectGraphType { Name = "Subscription" },
Query = new ObjectGraphType
{
Name = "Query",
},
Mutation = new ObjectGraphType
{
Name = "Mutation",
},
Subscription = new ObjectGraphType
{
Name = "Subscription",
},
NameConverter = new OrchardFieldNameConverter(),
};

foreach (var type in serviceProvider.GetServices<IInputObjectGraphType>())
{
schema.RegisterType(type);
}

foreach (var type in serviceProvider.GetServices<IObjectGraphType>())
{
schema.RegisterType(type);
}
schema.RegisterTypes(serviceProvider.GetServices<IInputObjectGraphType>().ToArray());
schema.RegisterTypes(serviceProvider.GetServices<IObjectGraphType>().ToArray());

foreach (var builder in _schemaBuilders)
{
Expand All @@ -90,7 +95,6 @@ public async Task<ISchema> GetSchemaAsync()
await builder.BuildAsync(schema);
}


// Clean Query, Mutation and Subscription if they have no fields
// to prevent GraphQL configuration errors.

Expand All @@ -110,6 +114,7 @@ public async Task<ISchema> GetSchemaAsync()
}

schema.Initialize();

return _schema = schema;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MaxNumberOfResultsValidationRule(
_logger = logger;
}

public ValueTask<INodeVisitor> ValidateAsync(ValidationContext validationContext)
public ValueTask<INodeVisitor> GetPreNodeVisitorAsync(ValidationContext validationContext)
{
return ValueTask.FromResult((INodeVisitor)new NodeVisitors(
new MatchingNodeVisitor<GraphQLArgument>((arg, visitorContext) =>
Expand Down Expand Up @@ -68,4 +68,10 @@ public ValueTask<INodeVisitor> ValidateAsync(ValidationContext validationContext
}
})));
}

public ValueTask<IVariableVisitor> GetVariableVisitorAsync(ValidationContext context)
=> ValueTask.FromResult<IVariableVisitor>(null);

public ValueTask<INodeVisitor> GetPostNodeVisitorAsync(ValidationContext context)
=> ValueTask.FromResult<INodeVisitor>(null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RequiresPermissionValidationRule(
S = localizer;
}

public async ValueTask<INodeVisitor> ValidateAsync(ValidationContext validationContext)
public async ValueTask<INodeVisitor> GetPreNodeVisitorAsync(ValidationContext validationContext)
{
// shouldn't we access UserContext from validation-context inside MatchingNodeVisitor actions?
var userContext = (GraphQLUserContext)validationContext.UserContext;
Expand Down Expand Up @@ -121,4 +121,10 @@ private void AddPermissionValidationError(ValidationContext validationContext, A
S["Authorization is required to access the node. {0}", nodeName],
node));
}

public ValueTask<IVariableVisitor> GetVariableVisitorAsync(ValidationContext context)
=> ValueTask.FromResult<IVariableVisitor>(null);

public ValueTask<INodeVisitor> GetPostNodeVisitorAsync(ValidationContext context)
=> ValueTask.FromResult<INodeVisitor>(null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Boolean field",
FieldType = typeof(BooleanGraphType),
ResolvedType = new BooleanGraphType(),
UnderlyingType = typeof(BooleanField),
FieldAccessor = field => ((BooleanField)field).Value,
IndexType = typeof(BooleanFieldIndex),
Index = nameof(BooleanFieldIndex.Boolean)
Index = nameof(BooleanFieldIndex.Boolean),
}
},
{
Expand All @@ -32,10 +33,11 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Date field",
FieldType = typeof(DateGraphType),
ResolvedType = new DateGraphType(),
UnderlyingType = typeof(DateField),
FieldAccessor = field => ((DateField)field).Value,
IndexType = typeof(DateFieldIndex),
Index = nameof(DateFieldIndex.Date)
Index = nameof(DateFieldIndex.Date),
}
},
{
Expand All @@ -44,10 +46,11 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Date & time field",
FieldType = typeof(DateTimeGraphType),
ResolvedType = new DateTimeGraphType(),
UnderlyingType = typeof(DateTimeField),
FieldAccessor = field => ((DateTimeField)field).Value,
IndexType = typeof(DateTimeFieldIndex),
Index = nameof(DateTimeFieldIndex.DateTime)
Index = nameof(DateTimeFieldIndex.DateTime),
}
},
{
Expand All @@ -56,6 +59,7 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Numeric field",
FieldType = typeof(DecimalGraphType),
ResolvedType = new DecimalGraphType(),
UnderlyingType = typeof(NumericField),
FieldAccessor = field => ((NumericField)field).Value,
IndexType = typeof(NumericFieldIndex),
Expand All @@ -68,6 +72,7 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Text field",
FieldType = typeof(StringGraphType),
ResolvedType = new StringGraphType(),
UnderlyingType = typeof(TextField),
FieldAccessor = field => ((TextField)field).Text,
IndexType = typeof(TextFieldIndex),
Expand All @@ -80,6 +85,7 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Time field",
FieldType = typeof(TimeSpanGraphType),
ResolvedType = new TimeSpanGraphType(),
UnderlyingType = typeof(TimeField),
FieldAccessor = field => ((TimeField)field).Value,
IndexType = typeof(TimeFieldIndex),
Expand All @@ -92,6 +98,7 @@ public class ContentFieldsProvider : IContentFieldProvider
{
Description = "Multi text field",
FieldType = typeof(ListGraphType<StringGraphType>),
ResolvedType = new ListGraphType(new StringGraphType()),
UnderlyingType = typeof(MultiTextField),
FieldAccessor = field => ((MultiTextField)field).Values,
}
Expand All @@ -107,9 +114,10 @@ public FieldType GetField(ISchema schema, ContentPartFieldDefinition field, stri

return new FieldType
{
Name = customFieldName ?? field.Name,
Name = customFieldName ?? schema.NameConverter.NameForField(field.Name, null),
Description = fieldDescriptor.Description,
Type = fieldDescriptor.FieldType,
ResolvedType = fieldDescriptor.ResolvedType,
Resolver = new FuncFieldResolver<ContentElement, object>(context =>
{
// Check if part has been collapsed by trying to get the parent part.
Expand All @@ -127,7 +135,8 @@ public FieldType GetField(ISchema schema, ContentPartFieldDefinition field, stri
};
}

public bool HasField(ISchema schema, ContentPartFieldDefinition field) => _contentFieldTypeMappings.ContainsKey(field.FieldDefinition.Name);
public bool HasField(ISchema schema, ContentPartFieldDefinition field)
=> _contentFieldTypeMappings.ContainsKey(field.FieldDefinition.Name);

public FieldTypeIndexDescriptor GetFieldIndex(ContentPartFieldDefinition field)
{
Expand All @@ -141,22 +150,29 @@ public FieldTypeIndexDescriptor GetFieldIndex(ContentPartFieldDefinition field)
return new FieldTypeIndexDescriptor
{
Index = fieldDescriptor.Index,
IndexType = fieldDescriptor.IndexType
IndexType = fieldDescriptor.IndexType,
};
}

public bool HasFieldIndex(ContentPartFieldDefinition field) =>
_contentFieldTypeMappings.TryGetValue(field.FieldDefinition.Name, out var fieldTypeDescriptor) &&
public bool HasFieldIndex(ContentPartFieldDefinition field)
=> _contentFieldTypeMappings.TryGetValue(field.FieldDefinition.Name, out var fieldTypeDescriptor) &&
fieldTypeDescriptor.IndexType != null &&
!string.IsNullOrWhiteSpace(fieldTypeDescriptor.Index);

private sealed class FieldTypeDescriptor
{
public string Description { get; set; }

public Type FieldType { get; set; }

public Type UnderlyingType { get; set; }

public required IGraphType ResolvedType { get; set; }

public Func<ContentElement, object> FieldAccessor { get; set; }

public string Index { get; set; }

public Type IndexType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GraphQL.DataLoader;
using GraphQL;
using GraphQL.Types;
using OrchardCore.Apis.GraphQL;
using OrchardCore.ContentFields.Fields;
Expand Down Expand Up @@ -29,7 +29,7 @@ public ContentPickerFieldQueryObjectType()
{
var contentItemLoader = x.GetOrAddPublishedContentItemByIdDataLoader();
return (contentItemLoader.LoadAsync(x.Page(x.Source.ContentItemIds))).Then(itemResultSet =>
return contentItemLoader.LoadAsync(x.Page(x.Source.ContentItemIds)).Then(itemResultSet =>
{
return itemResultSet.SelectMany(x => x);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public void Build(ISchema schema, FieldType contentQuery, ContentTypeDefinition
contentItemType.Field<FlowMetadataQueryObjectType>("metadata")
.Resolve(context => context.Source.As<FlowMetadata>());
}

public void Clear()
{
}
}
Loading

0 comments on commit 5dc244b

Please sign in to comment.