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

Edit Content Part, Add New Field, Kills GraphQL #5536

Closed
kef7 opened this issue Feb 12, 2020 · 14 comments · Fixed by #8669
Closed

Edit Content Part, Add New Field, Kills GraphQL #5536

kef7 opened this issue Feb 12, 2020 · 14 comments · Fixed by #8669
Milestone

Comments

@kef7
Copy link

kef7 commented Feb 12, 2020

Adding "OpenInNewWindow" Bool field to LinkMenuItemPart from Orchard Core Admin breaks GraphQL. (I believe the content part definition for LinkMenuItemPart came from The Agency theme.)

  • Accessing /api/graphql gives 400 Bad Request

  • GraphQL admin area shows "No Schema" message; can't execute queries

  • IIS error in Windows Event Log:
    Category: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
    EventId: 1
    RequestId: 80000d14-0400-f900-b63f-84710c7967bb
    RequestPath: /api/graphql
    SpanId: |c69cdb0c-44c6865f99a2049c.
    TraceId: c69cdb0c-44c6865f99a2049c
    ParentId:

An unhandled exception has occurred while executing the request.

Exception:
System.ArgumentOutOfRangeException: A field with the name: linkMenuItem is already registered for GraphType: LinkMenuItem (Parameter 'Name')
at GraphQL.Types.ComplexGraphType`1.AddField(FieldType fieldType)
at OrchardCore.ContentManagement.GraphQL.Queries.Types.DynamicContentTypeBuilder.Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefinition, ContentItemType contentItemType) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.ContentManagement.GraphQL\Queries\Types\DynamicContentTypeBuilder.cs:line 65
at OrchardCore.ContentManagement.GraphQL.Queries.ContentTypeQuery.BuildAsync(ISchema schema) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.ContentManagement.GraphQL\Queries\ContentTypeQuery.cs:line 63
at OrchardCore.Apis.GraphQL.Services.SchemaService.GetSchemaAsync() in C:\projects\orchardcore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\Services\SchemaService.cs:line 56
at OrchardCore.Apis.GraphQL.GraphQLMiddleware.ExecuteAsync(HttpContext context, ISchemaFactory schemaService) in C:\projects\orchardcore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\GraphQLMiddleware.cs:line 79
at OrchardCore.Apis.GraphQL.GraphQLMiddleware.Invoke(HttpContext context, IAuthorizationService authorizationService, IAuthenticationService authenticationService, ISchemaFactory schemaService) in C:\projects\orchardcore\src\OrchardCore.Modules\OrchardCore.Apis.GraphQL\GraphQLMiddleware.cs:line 70
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at OrchardCore.Diagnostics.DiagnosticsStartupFilter.<>c__DisplayClass3_0.<b__1>d.MoveNext() in C:\projects\orchardcore\src\OrchardCore.Modules\OrchardCore.Diagnostics\DiagnosticsStartupFilter.cs:line 47
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

Fixed by removing the added ContentPartFieldDefinitonRecord from the LinkMenuItemPart item under ContentPartDefinitionRecords in file ContentDefinition.json. It's possible there are in fact two definitions for LinkMenuItemPart and they are conflicting; not sure how to check this accurately.

@jtkech
Copy link
Member

jtkech commented Feb 13, 2020

Okay, i can repro, i will dig into it asap

@jtkech
Copy link
Member

jtkech commented Feb 13, 2020

So, it doesn't happen if you add a field to a content type, but it happens for any field that you add dynamically to any part.

I think it is because of DynamicContentTypeBuilder that allows to take into account a part that you create dynamically through the admin but also when you add a field to an existing part.

I'm working on it

@jtkech
Copy link
Member

jtkech commented Feb 13, 2020

@carlwoodhouse or another GraphQL expert

So, if we add a field to an existing part (e.g a TextField to the HtmlBodyPart) that is used in a content type, we get the above issue saying that the GraphQL element is already registered. This because in DynamicContentTypeBuilder the related element is already registered by TypedContentTypeBuilder.

So, in this case i thought about forcing the collapsing of fields, so just to show what i needed to prevent it from failing, in DynamicContentTypeBuilder i added for testing the following check

            var test = contentItemType.GetField(partName.ToFieldName());

            if (_contentOptions.ShouldCollapse(part) || test != null)
            {
                 ... 

I also noticed that in both builders we check

            // Check if another builder has already added a field for this part.
            if (contentItemType.HasField(partName)) continue; // Never true

Just for confirmation because it is never true, should we use partName.ToFieldName() as used for registering? Notice that if i use partName.ToFieldName() it doesn't fail because the HtmlBody is not registered twice but then the TextField that has been added dynamically is not resolved.

@carlwoodhouse
Copy link
Member

heh, for sure that check is wrong ... but probably what we should be doing is checking if it has the field already, if it does then just add the dynamic fields to the existing field.

@carlwoodhouse
Copy link
Member

if you don't have time to work on it @jtkech i can take it if you like

@jtkech
Copy link
Member

jtkech commented Feb 14, 2020

@carlwoodhouse

Yes thanks, it was just to show my findings but you are better placed to fix it in the right way

@sebastienros sebastienros added this to the 1.0.x milestone Feb 27, 2020
@Fermain
Copy link

Fermain commented May 19, 2020

@carlwoodhouse Have you made any headway with this?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented May 19, 2020 via email

@hyzx86
Copy link
Contributor

hyzx86 commented Jun 19, 2020

image

@hyzx86
Copy link
Contributor

hyzx86 commented Jun 26, 2020

I have created a pull request , #6477

@agriffard
Copy link
Member

Has it been fixed by #6536 ?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Aug 13, 2020 via email

@agriffard
Copy link
Member

@carlwoodhouse Can you see a way to fix the issue?

@carlwoodhouse
Copy link
Member

carlwoodhouse commented Jan 28, 2021 via email

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