-
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 several minor issues when building the GraphQL schema (#16151)
Co-authored-by: Hisham Bin Ateya <[email protected]>
- Loading branch information
Showing
5 changed files
with
100 additions
and
56 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/FieldTypeExtensions.cs
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Extensions/GraphQLTypeExtensions.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Linq; | ||
using GraphQL.Types; | ||
|
||
namespace OrchardCore.ContentManagement.GraphQL; | ||
|
||
public static class GraphQLTypeExtensions | ||
{ | ||
public static FieldType WithPartCollapsedMetaData(this FieldType fieldType, bool collapsed = true) | ||
=> fieldType.WithMetaData("PartCollapsed", collapsed); | ||
|
||
public static FieldType WithPartNameMetaData(this FieldType fieldType, string partName) | ||
=> fieldType.WithMetaData("PartName", partName); | ||
|
||
/// <summary> | ||
/// Checks if the field exists in the GraphQL type in a case-insensitive way. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This is the same as calling <see cref="IComplexGraphType.HasField(string)"/> but in a case-insensitive way. OC | ||
/// fields may be added with different casings, and we want to avoid collisions even then. | ||
/// </para> | ||
/// <para> | ||
/// See <see href="https://github.com/OrchardCMS/OrchardCore/pull/16151"/> and its corresponding issues for context. | ||
/// </para> | ||
/// </remarks> | ||
public static bool HasFieldIgnoreCase(this IComplexGraphType graphType, string fieldName) | ||
=> graphType.Fields.Any(field => field.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)); | ||
|
||
private static FieldType WithMetaData(this FieldType fieldType, string name, object value) | ||
{ | ||
// TODO: Understand if locking is the best solution to https://github.com/OrchardCMS/OrchardCore/issues/15308 | ||
lock (fieldType.Metadata) | ||
{ | ||
fieldType.Metadata.TryAdd(name, value); | ||
} | ||
|
||
return fieldType; | ||
} | ||
} |
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