Orchardcore: Edit Content Part, Add New Field, Kills GraphQL

Created on 12 Feb 2020  Â·  12Comments  Â·  Source: OrchardCMS/OrchardCore

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:projectsorchardcoresrcOrchardCoreOrchardCore.ContentManagement.GraphQLQueriesTypesDynamicContentTypeBuilder.cs:line 65
at OrchardCore.ContentManagement.GraphQL.Queries.ContentTypeQuery.BuildAsync(ISchema schema) in C:projectsorchardcoresrcOrchardCoreOrchardCore.ContentManagement.GraphQLQueriesContentTypeQuery.cs:line 63
at OrchardCore.Apis.GraphQL.Services.SchemaService.GetSchemaAsync() in C:projectsorchardcoresrcOrchardCore.ModulesOrchardCore.Apis.GraphQLServicesSchemaService.cs:line 56
at OrchardCore.Apis.GraphQL.GraphQLMiddleware.ExecuteAsync(HttpContext context, ISchemaFactory schemaService) in C:projectsorchardcoresrcOrchardCore.ModulesOrchardCore.Apis.GraphQLGraphQLMiddleware.cs:line 79
at OrchardCore.Apis.GraphQL.GraphQLMiddleware.Invoke(HttpContext context, IAuthorizationService authorizationService, IAuthenticationService authenticationService, ISchemaFactory schemaService) in C:projectsorchardcoresrcOrchardCore.ModulesOrchardCore.Apis.GraphQLGraphQLMiddleware.cs:line 70
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at OrchardCore.Diagnostics.DiagnosticsStartupFilter.<>c__DisplayClass3_0.<b__1>d.MoveNext() in C:projectsorchardcoresrcOrchardCore.ModulesOrchardCore.DiagnosticsDiagnosticsStartupFilter.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.

GraphQL P1

Most helpful comment

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

All 12 comments

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

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

@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.

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.

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

@carlwoodhouse

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

@carlwoodhouse Have you made any headway with this?

I looked into it a bit but I need to pick it back up.

There’s an easy fix (as suggested here; the check for did I already build
this part in another builder is checking the wrong case of the field name;
so it re-adds it; this is technically what breaks it ..) so the simplest
fix is to check the right case.

But this isn’t actually ideal; as you’d never be able to mix types and
dynamic parts; you’d only ever get the typed definition .. so we actually
need to merge them.

I’ll try take a proper look on Friday when I have some time.

Carl.

On Tue, 19 May 2020 at 19:24, Fermain notifications@github.com wrote:

@carlwoodhouse https://github.com/carlwoodhouse Have you made any
headway with this?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/OrchardCMS/OrchardCore/issues/5536#issuecomment-630997829,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AADRUEBJIKPXTDJNUQBD4ALRSLFFJANCNFSM4KUFLEEA
.

image

I have created a pull request , https://github.com/OrchardCMS/OrchardCore/pull/6477

Has it been fixed by #6536 ?

Not as far as I can see Antoine

On Thu, 13 Aug 2020 at 11:00, Antoine Griffard notifications@github.com
wrote:

Has it been fixed by #6536
https://github.com/OrchardCMS/OrchardCore/pull/6536 ?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/OrchardCMS/OrchardCore/issues/5536#issuecomment-673385221,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AADRUEFDN62XMNPMNHE4WSDSAO2SXANCNFSM4KUFLEEA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aghili371 picture aghili371  Â·  3Comments

chillibug picture chillibug  Â·  4Comments

jeffolmstead picture jeffolmstead  Â·  4Comments

khoshroomahdi picture khoshroomahdi  Â·  4Comments

cbadger360 picture cbadger360  Â·  4Comments