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

InvalidOperationException when visiting GraphQL explorer #15304

Closed
lampersky opened this issue Feb 11, 2024 · 10 comments · Fixed by #15319
Closed

InvalidOperationException when visiting GraphQL explorer #15304

lampersky opened this issue Feb 11, 2024 · 10 comments · Fixed by #15319
Labels
Milestone

Comments

@lampersky
Copy link
Contributor

lampersky commented Feb 11, 2024

I've just updated to the latest OC and getting this when visiting GraphiQL explorer:

System.InvalidOperationException: This graph type 'AutorouteInputObjectType' with name 'AutoroutePartInput' has already been initialized. Make sure that you do not use the same instance of a graph type in multiple schemas. It may be so if you registered this graph type as singleton; see https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/ for more info.
   at GraphQL.Types.GraphType.Initialize(ISchema schema) in /_/src/GraphQL/Types/GraphType.cs:line 44
   at GraphQL.Types.SchemaTypes.AddType(IGraphType type, TypeCollectionContext context) in /_/src/GraphQL/Types/Collections/SchemaTypes.cs:line 522
   at GraphQL.Types.SchemaTypes.AddTypeIfNotRegistered(IGraphType type, TypeCollectionContext context) in /_/src/GraphQL/Types/Collections/SchemaTypes.cs:line 776
   at GraphQL.Types.SchemaTypes.Initialize(ISchema schema, IServiceProvider serviceProvider, IEnumerable`1 graphTypeMappings) in /_/src/GraphQL/Types/Collections/SchemaTypes.cs:line 277
   at GraphQL.Types.SchemaTypes..ctor(ISchema schema, IServiceProvider serviceProvider, IEnumerable`1 graphTypeMappings) in /_/src/GraphQL/Types/Collections/SchemaTypes.cs:line 190
   at GraphQL.Types.SchemaTypes..ctor(ISchema schema, IServiceProvider serviceProvider) in /_/src/GraphQL/Types/Collections/SchemaTypes.cs:line 175
   at GraphQL.Types.Schema.CreateSchemaTypes() in /_/src/GraphQL/Types/Schema.cs:line 477
   at GraphQL.Types.Schema.CreateAndInitializeSchemaTypes() in /_/src/GraphQL/Types/Schema.cs:line 448
   at GraphQL.Types.Schema.Initialize() in /_/src/GraphQL/Types/Schema.cs:line 196
   at OrchardCore.Apis.GraphQL.Services.SchemaService.GetSchemaAsync() in C:\repo\OrchardCore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\Services\SchemaService.cs:line 116
   at OrchardCore.Apis.GraphQL.GraphQLMiddleware.ExecuteAsync(HttpContext context) in C:\repo\OrchardCore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\GraphQLMiddleware.cs:line 142
   at OrchardCore.Apis.GraphQL.GraphQLMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\repo\OrchardCore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\GraphQLMiddleware.cs:line 65
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()

image

Steps to reproduce:

  • create new ContentType, you don't need to add Parts nor Fields,
  • go to GraphQL explorer,
  • schema is not loading anymore.

I've just checked, and it looks like you don't need to create new ContentType, you can reconfigure existing one instead. This way you could also reproduce the issue.

@MikeAlhayek
Copy link
Member

@hyzx86 I think the upgrade PR #15129 is causing multiple GraphQL issue and this is one of them.

@MikeAlhayek MikeAlhayek added this to the 1.9 milestone Feb 12, 2024
@MikeAlhayek
Copy link
Member

@lampersky can you please pull the latest from main or use the latest previews and see if this is still an issue for you?

@lampersky
Copy link
Contributor Author

@MikeAlhayek same issue with latest changes from main:

image

@MikeAlhayek
Copy link
Member

I'll leave this to @hyzx86. I can't reproduce this issue on the main branch (tried existing site and create new site.)

Is this issue from the main branch or your project? If you are running your project, can you make sure you are not adding this into your project manually?

services.AddInputObjectGraphType<AutoroutePart, AutorouteInputObjectType>();

Also, search your project for any code that uses services.AddInputObjectGraphType<>()

I am also wondering if you have weird dependency that could be causing registering AutorouteInputObjectType more than once in the DI container. You may try to convert these to TryAddSingleton or check of they are already registered before registering them.

{
// 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>());
}
/// <summary>
/// Registers a type describing output arguments.
/// </summary>
/// <typeparam name="TInput"></typeparam>
/// <typeparam name="TInputType"></typeparam>
/// <param name="services"></param>
public static void AddObjectGraphType<TInput, TInputType>(this IServiceCollection services)
where TInput : class
where TInputType : ObjectGraphType<TInput>
{
// 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>());
}

@lampersky
Copy link
Contributor Author

@MikeAlhayek I'm using OrchardCore.Cms.Web project from OC repo. No custom modules. Also I'm not registering any additional dependecies.

image

@MikeAlhayek
Copy link
Member

Strange. Do you know if you are using a default recipe? I can't seems to reproduce the issue which is strange. I tried the blog recipe and enabled the GraphQL feature.

@lampersky
Copy link
Contributor Author

lampersky commented Feb 12, 2024

@MikeAlhayek did you try to reconfigure existing ContentPart? and then go to GraphQL editor?

I'm using Blank recipe with GraphQL enabled.

MikeAlhayek added a commit that referenced this issue Feb 13, 2024
@MikeAlhayek
Copy link
Member

Thanks I was able to reproduce. Check out the referenced PR if you have time to test it out.

@sebastienros
Copy link
Member

@MikeAlhayek couldn't repro, what exactly did you do?

@MikeAlhayek
Copy link
Member

First you have to visit the GraphiQL. Then edit any content type "like the articles content type".

Then refresh GraphiQL page again and you should encounter the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants