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

Upgrade GraphQL to 8.2 #16736

Merged
merged 37 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1d4c524
Upgrade GraphQL to 8.0.2
MikeAlhayek Sep 16, 2024
d02bfa3
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 16, 2024
2b428fe
spaces
MikeAlhayek Sep 17, 2024
a9d42d1
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 18, 2024
2258a86
use DefaultObjectImpact
MikeAlhayek Sep 18, 2024
6a87cfd
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 18, 2024
1a3f3d6
don't resolve services from ISchema
MikeAlhayek Sep 18, 2024
d038e25
Merge branch 'ma/upgeade-graphql' of https://github.com/OrchardCMS/Or…
MikeAlhayek Sep 18, 2024
44a1340
DynamicPartGraphType should define fields in the constructor
MikeAlhayek Sep 18, 2024
ca7d97e
cleanup
MikeAlhayek Sep 18, 2024
7372822
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 18, 2024
6698d69
Adding ResolvedType
MikeAlhayek Sep 18, 2024
56090bc
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 19, 2024
87bfdc2
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 23, 2024
de86304
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Sep 30, 2024
336249a
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 19, 2024
1bdb795
attempt to register.
MikeAlhayek Nov 20, 2024
ecf7210
fix more issues
MikeAlhayek Nov 20, 2024
d0f317a
simplify the schema service
MikeAlhayek Nov 20, 2024
11661c6
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 20, 2024
ce76ac2
cleanup
MikeAlhayek Nov 20, 2024
5340244
Fix Schema validations
MikeAlhayek Nov 21, 2024
fcae801
cleanup
MikeAlhayek Nov 21, 2024
3b0c7ea
seal classes, and document the changes.
MikeAlhayek Nov 21, 2024
b37c1c4
finalize
MikeAlhayek Nov 21, 2024
ad5e58c
fix build
MikeAlhayek Nov 21, 2024
185f8ad
Fix tests
MikeAlhayek Nov 21, 2024
06e70fd
don't use partial
MikeAlhayek Nov 21, 2024
744fb91
Use latest packages
MikeAlhayek Nov 21, 2024
7810075
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 21, 2024
521c875
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 21, 2024
f00f520
Fix warning
MikeAlhayek Nov 21, 2024
c664d84
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 21, 2024
9fa8e6b
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 21, 2024
82d54bd
Merge branch 'main' into ma/upgeade-graphql
MikeAlhayek Nov 22, 2024
2e25e4a
address feedback
MikeAlhayek Nov 22, 2024
38c538c
fix warning
MikeAlhayek Nov 22, 2024
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
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,
gvkries marked this conversation as resolved.
Show resolved Hide resolved
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; }
}
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
}
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