Skip to content

Commit

Permalink
Fix GraphQL Explorer
Browse files Browse the repository at this point in the history
Fix #15304
  • Loading branch information
MikeAlhayek committed Feb 13, 2024
1 parent a8bdd63 commit 63d1832
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ public static void AddInputObjectGraphType<TObject, TObjectType>(this IServiceCo
where TObject : class
where TObjectType : InputObjectGraphType<TObject>
{
// Instances are registered as singletons as their constructor holds the logic to configure the type
// and doesn't need to run every time
services.AddSingleton<TObjectType>();
services.AddSingleton<InputObjectGraphType<TObject>, TObjectType>(s => s.GetRequiredService<TObjectType>());
services.AddSingleton<IInputObjectGraphType, TObjectType>(s => s.GetRequiredService<TObjectType>());
services.AddScoped<TObjectType>();
services.AddScoped<InputObjectGraphType<TObject>, TObjectType>(s => s.GetRequiredService<TObjectType>());
services.AddScoped<IInputObjectGraphType, TObjectType>(s => s.GetRequiredService<TObjectType>());
}

/// <summary>
Expand All @@ -34,9 +32,9 @@ public static void AddObjectGraphType<TInput, TInputType>(this IServiceCollectio
{
// Instances are registered as singletons as their constructor holds the logic to configure the type
// and doesn't need to run every time
services.AddSingleton<TInputType>();
services.AddSingleton<ObjectGraphType<TInput>, TInputType>(s => s.GetRequiredService<TInputType>());
services.AddSingleton<IObjectGraphType, TInputType>(s => s.GetRequiredService<TInputType>());
services.AddScoped<TInputType>();
services.AddScoped<ObjectGraphType<TInput>, TInputType>(s => s.GetRequiredService<TInputType>());
services.AddScoped<IObjectGraphType, TInputType>(s => s.GetRequiredService<TInputType>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ namespace OrchardCore.ContentManagement.GraphQL.Queries.Types
{
public class TypedContentTypeBuilder : IContentTypeBuilder
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly GraphQLContentOptions _contentOptions;
private static readonly ConcurrentDictionary<string, Type> _partTypes = new();
private static readonly ConcurrentDictionary<string, IObjectGraphType> _partObjectGraphTypes = new();
private static readonly ConcurrentDictionary<string, IInputObjectGraphType> _partInputObjectGraphTypes = new();

private readonly IHttpContextAccessor _httpContextAccessor;
private readonly GraphQLContentOptions _contentOptions;

public TypedContentTypeBuilder(IHttpContextAccessor httpContextAccessor,
IOptions<GraphQLContentOptions> contentOptionsAccessor)
{
Expand Down Expand Up @@ -57,13 +58,14 @@ public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefin
}

var partType = _partTypes.GetOrAdd(part.PartDefinition.Name, key => typeActivator.GetTypeActivator(key).Type);
var queryGraphType = _partObjectGraphTypes.GetOrAdd(part.PartDefinition.Name,
partName =>
{
queryObjectGraphTypes ??= serviceProvider.GetService<IEnumerable<IObjectGraphType>>();
return queryObjectGraphTypes?.FirstOrDefault(x => x.GetType().BaseType.GetGenericArguments().First().Name == partName);
}
);
var queryGraphType = _partObjectGraphTypes
.GetOrAdd(part.PartDefinition.Name,
partName =>
{
queryObjectGraphTypes ??= serviceProvider.GetServices<IObjectGraphType>();
return queryObjectGraphTypes?.FirstOrDefault(x => x.GetType().BaseType.GetGenericArguments().First().Name == partName);
}
);

var collapsePart = _contentOptions.ShouldCollapse(part);

Expand All @@ -73,7 +75,10 @@ public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefin
{
foreach (var field in queryGraphType.Fields)
{
if (_contentOptions.ShouldSkip(queryGraphType.GetType(), field.Name)) continue;
if (_contentOptions.ShouldSkip(queryGraphType.GetType(), field.Name))
{
continue;
}

var rolledUpField = new FieldType
{
Expand Down Expand Up @@ -123,7 +128,7 @@ public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefin

var inputGraphTypeResolved = _partInputObjectGraphTypes.GetOrAdd(part.PartDefinition.Name, partName =>
{
queryInputGraphTypes ??= serviceProvider.GetService<IEnumerable<IInputObjectGraphType>>();
queryInputGraphTypes ??= serviceProvider.GetServices<IInputObjectGraphType>();
return queryInputGraphTypes?.FirstOrDefault(x => x.GetType().BaseType.GetGenericArguments().FirstOrDefault()?.Name == part.PartDefinition.Name);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IServiceCollection AddContentGraphQL(this IServiceCollection servi
{
services.AddSingleton<ISchemaBuilder, ContentItemQuery>();
services.AddSingleton<ISchemaBuilder, ContentTypeQuery>();
services.AddSingleton<ContentItemInterface>();
services.AddTransient<ContentItemInterface>();

services.AddTransient<ContentItemType>();

Expand Down

0 comments on commit 63d1832

Please sign in to comment.