-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes building the GraphQL schema. (#16184)
- Loading branch information
Showing
11 changed files
with
57 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 24 additions & 11 deletions
35
src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicPartGraphType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
using System; | ||
using System.Linq; | ||
using GraphQL.Types; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.ContentManagement.GraphQL.Queries.Types | ||
{ | ||
public sealed class DynamicPartGraphType : ObjectGraphType<ContentPart> | ||
{ | ||
public DynamicPartGraphType(IHttpContextAccessor httpContextAccessor, ContentTypePartDefinition part) | ||
private ContentTypePartDefinition _part; | ||
|
||
public DynamicPartGraphType(ContentTypePartDefinition part) | ||
{ | ||
Name = part.Name; | ||
_part = part; | ||
} | ||
|
||
var serviceProvider = httpContextAccessor.HttpContext.RequestServices; | ||
var contentFieldProviders = serviceProvider.GetServices<IContentFieldProvider>().ToList(); | ||
|
||
foreach (var field in part.PartDefinition.Fields) | ||
public override void Initialize(ISchema schema) | ||
{ | ||
if (schema is IServiceProvider serviceProvider) | ||
{ | ||
foreach (var fieldProvider in contentFieldProviders) | ||
var contentFieldProviders = serviceProvider.GetServices<IContentFieldProvider>().ToList(); | ||
|
||
foreach (var field in _part.PartDefinition.Fields) | ||
{ | ||
var fieldType = fieldProvider.GetField(field, part.Name); | ||
if (fieldType != null) | ||
foreach (var fieldProvider in contentFieldProviders) | ||
{ | ||
AddField(fieldType); | ||
break; | ||
var fieldType = fieldProvider.GetField(schema, field, _part.Name); | ||
if (fieldType != null) | ||
{ | ||
AddField(fieldType); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Part is not required here anymore, do not keep it alive. | ||
_part = null; | ||
|
||
base.Initialize(schema); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters