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

GraphQL - DynamicContentTypeBuilder: Broken when typed part is registered #14592

Closed
MikeKry opened this issue Oct 27, 2023 · 4 comments · Fixed by #16151
Closed

GraphQL - DynamicContentTypeBuilder: Broken when typed part is registered #14592

MikeKry opened this issue Oct 27, 2023 · 4 comments · Fixed by #16151

Comments

@MikeKry
Copy link
Contributor

MikeKry commented Oct 27, 2023

Describe the bug

Dynamic content type builder generates duplicate fields directly to content type. This happens when you register custom content part as typed, when it has fields registered in CMS.

To Reproduce

Steps to reproduce the behavior:

  1. Create a part in CMS with fields, add to Content type
  2. Register custom ObjectGraphType for this part
  3. Open GraphiQL console
  4. View Content type - now it has fields both in registered custom part and directly in content type (as when you collapse part)

After debugging I think problem is here:
https://github.com/OrchardCMS/OrchardCore/blob/main/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/DynamicContentTypeBuilder.cs#L85

image

Builder already has handling for existing parts. But it does not add missing fields to part. Instead, it adds all fields, even when they are already in part, directly to content type. It checks missing fields against content type instead of content part.

Expected behavior

When custom ObjectGraphType is registered, dynamic builder...

  • Should not duplicate existing fields and place them directly under content type
  • Should either do nothing with existing part OR better - it should add only missing fields under given part.

Screenshots

image

Highlighted props are from dynamic content type builder.

@lampersky
Copy link
Contributor

@MikeKry please have a look if this is a similar problem to this one #13926 (comment)

@MikeKry
Copy link
Contributor Author

MikeKry commented Oct 27, 2023

@lampersky

The one you mention will not fix this issue - if field does not exist in part, it will still add it to base content type

image

this would need to be handled - add it to part instead of content type. Also not sure if the new GetField method would actually work for getting field from non-collapsed part.
(this issue refers to non-collapsed parts only)

@MikeKry
Copy link
Contributor Author

MikeKry commented Oct 27, 2023

For my current project I have done following:

  • copy DynamicContentTypeBuilder - comment out the line with adding fields to content type
  • removed default implementation from services
  • created publicly visible DynamicPartGraphType, so I can use it as a decorator around my custom content part

It works like this, but I guess it could be done better when handled directly in DynamicContentTypeBuilder

@sebastienros
Copy link
Member

Do you want to suggest a PR?

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

Successfully merging a pull request may close this issue.

5 participants