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

Update ContentItemVersionId nullable in graphql #16030

Merged
merged 6 commits into from
May 15, 2024

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented May 11, 2024

In the me field, the user may check contentItemVersionId, but we don't assign a value to it.

{
  "errors": [
    {
      "message": "Error trying to resolve field 'contentItemVersionId'.",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "me",
        "testProfile2",
        "contentItemVersionId"
      ],
      "extensions": {
        "code": "INVALID_OPERATION",
        "codes": [
          "INVALID_OPERATION"
        ],
        "details": "GraphQL.Execution.UnhandledError: Error trying to resolve field 'contentItemVersionId'.\r\n ---> System.InvalidOperationException: Cannot return null for a non-null type. Field: contentItemVersionId, Type: String!.\r\n   at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 635\r\n   at GraphQL.Execution.ExecutionStrategy.CompleteNodeAsync(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 551\r\n   --- End of inner exception stack trace ---"
      }
    },
    {
      "message": "Error trying to resolve field 'contentItemVersionId'.",
      "locations": [
        {
          "line": 9,
          "column": 7
        }
      ],
      "path": [
        "me",
        "testUserProfile",
        "contentItemVersionId"
      ],
      "extensions": {
        "code": "INVALID_OPERATION",
        "codes": [
          "INVALID_OPERATION"
        ],
        "details": "GraphQL.Execution.UnhandledError: Error trying to resolve field 'contentItemVersionId'.\r\n ---> System.InvalidOperationException: Cannot return null for a non-null type. Field: contentItemVersionId, Type: String!.\r\n   at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 635\r\n   at GraphQL.Execution.ExecutionStrategy.CompleteNodeAsync(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 551\r\n   --- End of inner exception stack trace ---"
      }
    },
    {
      "message": "Error trying to resolve field 'render'.",
      "locations": [
        {
          "line": 11,
          "column": 7
        }
      ],
      "path": [
        "me",
        "testUserProfile",
        "render"
      ],
      "extensions": {
        "code": "INVALID_OPERATION",
        "codes": [
          "INVALID_OPERATION"
        ],
        "details": "GraphQL.Execution.UnhandledError: Error trying to resolve field 'render'.\r\n ---> System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'OrchardCore.DisplayManagement.Zones.ZoneHolding', but this ViewDataDictionary instance requires a model item of type 'OrchardCore.Users.ViewModels.CustomUserSettingsEditViewModel'.\r\n   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary..ctor(ViewDataDictionary source, Object model, Type declaredModelType)\r\n   at lambda_method702(Closure, ViewDataDictionary)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)\r\n   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)\r\n   at OrchardCore.DisplayManagement.Razor.RazorShapeTemplateViewEngine.RenderViewToStringAsync(String viewName, Object model, IViewEngine viewEngine) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.DisplayManagement\\Razor\\RazorShapeTemplateViewEngine.cs:line 123\r\n   at OrchardCore.DisplayManagement.Razor.RazorShapeTemplateViewEngine.RenderRazorViewAsync(String viewName, DisplayContext displayContext) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.DisplayManagement\\Razor\\RazorShapeTemplateViewEngine.cs:line 97\r\n   at OrchardCore.DisplayManagement.Implementation.DefaultHtmlDisplay.<ProcessAsync>g__Awaited|13_0(Task`1 task) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.DisplayManagement\\Implementation\\DefaultHtmlDisplay.cs:line 300\r\n   at OrchardCore.DisplayManagement.Implementation.DefaultHtmlDisplay.ExecuteAsync(DisplayContext context) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.DisplayManagement\\Implementation\\DefaultHtmlDisplay.cs:line 135\r\n   at OrchardCore.DisplayManagement.Implementation.DefaultHtmlDisplay.ExecuteAsync(DisplayContext context) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.DisplayManagement\\Implementation\\DefaultHtmlDisplay.cs:line 189\r\n   at OrchardCore.ContentManagement.GraphQL.Queries.Types.ContentItemType.RenderShapeAsync(IResolveFieldContext`1 context) in D:\\SourceCodes\\JZSoft\\EasyOC.OrchardCore\\OrchardCore\\src\\OrchardCore\\OrchardCore.ContentManagement.GraphQL\\Queries\\Types\\ContentItemType.cs:line 74\r\n   at GraphQL.Resolvers.FuncFieldResolver`2.<>c__DisplayClass3_0.<<-ctor>b__1>d.MoveNext() in /_/src/GraphQL/Resolvers/FuncFieldResolver.cs:line 70\r\n--- End of stack trace from previous location ---\r\n   at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node) in /_/src/GraphQL/Execution/ExecutionStrategy.cs:line 472\r\n   --- End of inner exception stack trace ---"
      }
    }
  ],
  "data": {
    "me": {
      "testProfile2": null,
      "testUserProfile": null
    }
  }
}

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 11, 2024

image

@Piedone
Copy link
Member

Piedone commented May 13, 2024

How do you get to this point, what's testProfile2?

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 14, 2024

How do you get to this point, what's testProfile2?

Ha, in case you haven't noticed, OC's graphql Api already supports me fields #15215,
and me fields also support linking CustomUserSettings here

@Piedone
Copy link
Member

Piedone commented May 14, 2024

Yeah, but what exactly is testProfile2? A CustomSettings content item? Please share an export file or reproduction steps.

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 14, 2024

Hi @Piedone
To reproduce the problem in my screenshot, you'll need to import the recipe below, click on the user info in the upper right corner, and then make some random changes and submit to save it.

{
  "name": "",
  "displayName": "",
  "description": "",
  "author": "",
  "website": "",
  "version": "",
  "issetuprecipe": false,
  "categories": [],
  "tags": [],
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Users.CustomUserSettings",
        "OrchardCore.Apis.GraphQL"
      ]
    },
    {
      "name": "ContentDefinition",
      "ContentTypes": [
        {
          "Name": "UserProfile",
          "DisplayName": "UserProfile",
          "Settings": {
            "ContentTypeSettings": {
              "Creatable": true,
              "Listable": true,
              "Draftable": true,
              "Versionable": true,
              "Stereotype": "CustomUserSettings",
              "Securable": true
            },
            "FullTextAspectSettings": {
              "IncludeFullTextTemplate": false,
              "IncludeBodyAspect": true,
              "IncludeDisplayText": true
            },
            "GraphQLContentTypeSettings": {
              "Hidden": false
            }
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "UserProfile",
              "Name": "UserProfile",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            }
          ]
        },
        {
          "Name": "UserProfile2",
          "DisplayName": "UserProfile2",
          "Settings": {
            "ContentTypeSettings": {
              "Creatable": true,
              "Listable": true,
              "Draftable": true,
              "Versionable": true,
              "Stereotype": "CustomUserSettings",
              "Securable": true
            },
            "FullTextAspectSettings": {
              "IncludeFullTextTemplate": false,
              "IncludeBodyAspect": true,
              "IncludeDisplayText": true
            },
            "GraphQLContentTypeSettings": {
              "Hidden": false
            }
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "UserProfile2",
              "Name": "UserProfile2",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            }
          ]
        }
      ],
      "ContentParts": [
        {
          "Name": "UserProfile",
          "Settings": {},
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "TextField",
              "Name": "Field1",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Field1",
                  "Position": "0"
                }
              }
            },
            {
              "FieldName": "TextField",
              "Name": "Field2"
            }
          ]
        },
        {
          "Name": "UserProfile2",
          "Settings": {},
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "TextField",
              "Name": "TextField1",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "TextField1",
                  "Position": "0"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

@Piedone
Copy link
Member

Piedone commented May 14, 2024

Thanks! I did this, but BTW since there's nothing from these content types in the user editor, nothing was saved to them:

image

And, expectedly userProfile and userProfile2 are null:

image

How exactly did you save content to them?

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 15, 2024

How exactly did you save content to them?

Have you enabled the "Custom User Settings" feature?

Or use the above my updated recipe

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 15, 2024

Because you haven't enabled the "Custom User Settings" feature, the user information page doesn't display these panels, but when you do enable it, you'll be able to see these panels, and the display driver will automatically handle the save logic,
but it won't assign a value to the ContentItemVersinId property of the ContentItem.

Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course, I see. Looks good, then!

@Piedone Piedone merged commit 768459c into OrchardCMS:main May 15, 2024
10 checks passed
@sebastienros
Copy link
Member

Why not assign a new id to it then and let it non-nullable?

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.

3 participants