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

Fix GraphQL Explorer #15319

Merged
merged 6 commits into from
Feb 13, 2024
Merged

Fix GraphQL Explorer #15319

merged 6 commits into from
Feb 13, 2024

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Feb 13, 2024

Fix #15304

@lampersky can you please checkout this branch and confirm that it fixes your issues?

The exception states

System.InvalidOperationException: 'This graph type 'AliasInputObjectType' with name 'AliasPartInput' 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.'

@MikeAlhayek
Copy link
Member Author

@hyzx86 can you please review the changes in this PR?

@sebastienros
Copy link
Member

I did this change I believe (not even sure but seems familiar). And the comments states it is singleton, so the comment could be removed "if this is the correct thing to do". Have you tried to understand what the issue was with the resolution? It really can't be a singleton?

@MikeAlhayek
Copy link
Member Author

@sebastienros I updated the description in the PR to show the detailed in the exception. I am guessing after the upgrade, we no longer need it to be singleton. And after the change everything seems to be working as expected. These types are resolved once during the schema building.

@sebastienros
Copy link
Member

Tried on my side and came to the same solution, using Transient though. Each type shouldn't be resolved multiple time during a request that builds the schema.

@lampersky
Copy link
Contributor

@MikeAlhayek, @sebastienros I've just tried ma/fix-graphql branch, and can't repro the issue anymore, so it looks the fix is solving the issue. Scheme is reloaded properly and GraphiQL explorer works as expected.

I only can see plenty of exceptions, when navigating from Admin/GraphQL to /Admin/Contents/ContentItems, but this is not related to issue reported earlier:
image

@MikeAlhayek MikeAlhayek enabled auto-merge (squash) February 13, 2024 16:22
@MikeAlhayek MikeAlhayek merged commit d2275cd into main Feb 13, 2024
5 checks passed
@MikeAlhayek MikeAlhayek deleted the ma/fix-graphql branch February 13, 2024 16:29
urbanit pushed a commit to urbanit/OrchardCore that referenced this pull request Mar 18, 2024
@gvkries
Copy link
Contributor

gvkries commented Apr 8, 2024

Note that by making the graph types Scoped, it is not possible to resolve them automatically while building the schema. That means using something like

Field<[GraphType]>("Foo")
  .Description("bar")
  .ResolveAsync(x =>
  {
    [...]
  });

fails for complex types, because the ISchemaFactory is a singleton and a scoped [GraphType] cannot be resolved. This happens when a graph type depends on another one.
Also note that any scoped instance may still be referenced by the schema.

@hyzx86
Copy link
Contributor

hyzx86 commented Apr 8, 2024

@hyzx86 can you please review the changes in this PR?

Sorry, I didn't notice this PR. When I saw it in the message list, it was already merged and I turned it off.

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

Successfully merging this pull request may close these issues.

InvalidOperationException when visiting GraphQL explorer
5 participants