arroyo / grutil

Headless CMS CLI
MIT License
3 stars 1 forks source link

GraphCMS server error: 400 Bad Request #3

Open xbra opened 3 years ago

xbra commented 3 years ago

Hi @arroyo - I am testing your program again. Unfortunately, it stops with an error and I cannot debug it.

> cmsutil-graphcms download content
Download content
2021/06/08 11:28:55 Get Article nodes
[…]
2021/06/08 11:29:05 Get PushNotification nodes
2021/06/08 11:29:06 GraphCMS server error: 400 Bad Request

How do I debug the tool? Any help is highly appreciated.

Best regards, Max

arroyo commented 3 years ago

Hi Max,

Try the backup feature and see if it works...cmsutil backup

looking at your output it seems as though the articles downloaded but it died with the PushNotification download. One common failure is when the schema has an irregular plural name. If the schema plural is PushNotifications then it should work. Plural naming special cases like Person/People would need to be called out in the config.

the tool doesn't have a debug mode...but I can add one. When it does die it's usually from a bad graphql query. Since GraphCMS is an evolving system new schema options may throw off the schema builder. I think a debug mode could help me maintain the exceptions.

Let me add a debug mode and then you can paste any finding here...assuming it's a query issue.

arroyo commented 3 years ago

I pushed up a new version. Let me know if the debug data helps...also if it ends up being a cmsutil bug let me know.

xbra commented 3 years ago

Hi @arroyo - thanks a lot.

  1. No query variables are printed to debug, e.g.

    {
    "nodetype": "PushNotificationGroup"
    }
  2. Results look good. And suddenly it ends. I guess the error is thrown before the failing query is printed. Could that be the case?

The end of a cmsutil-graphcms --debug backup looks like so:

2021/06/14 17:02:39 Get PushNotification nodes
2021/06/14 17:02:39 API query: query GetNodeByTypeVerbose($nodetype: String!) {
        __type(name: $nodetype) {
          name
          kind
          fields {
            name
            description
            args {
              name
              description
              defaultValue
            }
            type {
              name
              kind
              description
              fields {
                name
                description
                args {
                    name
                    description
                    defaultValue
                }
                type {
                    fields {
                        name
                        description
                        args {
                            name
                            description
                        }
                    }
                }
              }
              possibleTypes {
                name
                description
              }
              ofType {
                name
                description
              }
              interfaces {
                name
                description
                __typename
              }
            }
          }
        }
      }
2021/06/14 17:02:39 API response: {map[__type:map[fields:[map[args:[] description:System stage field name:stage type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description:Stage system enumeration name:Stage] possibleTypes:[]]] map[args:[] description:System Locale field name:locale type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description:Locale system enumeration name:Locale] possibleTypes:[]]] map[args:[map[defaultValue:[de,en] description:Potential locales that should be returned name:locales] map[defaultValue:false description:Decides if the current locale should be included or not name:includeCurrent]] description:Get the other localizations for this document name:localizations type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description: name:<nil>] possibleTypes:[]]] map[args:[map[defaultValue:[PUBLISHED,DRAFT] description:Potential stages that should be returned name:stages] map[defaultValue:false description:Decides if the current stage should be included or not name:includeCurrent] map[defaultValue:false description:Decides if the documents should match the parent documents locale or should use the fallback order defined in the tree name:inheritLocale]] description:Get the document in other stages name:documentInStages type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description: name:<nil>] possibleTypes:[]]] map[args:[] description:The unique identifier name:id type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description:The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID. name:ID] possibleTypes:[]]] map[args:[map[defaultValue:COMBINED description:Variation of DateTime field to return, allows value from base document, current localization, or combined by returning the newer value of both name:variation]] description:The time the document was created name:createdAt type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description:A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the date-timeformat outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representationof dates and times using the Gregorian calendar. name:DateTime] possibleTypes:[]]] map[args:[map[defaultValue:<nil> description:Allows to optionally override locale filtering behaviour in the query's subtree.

Note that `createdBy` is a model without localized fields and will not be affected directly by this argument, however the locales will be passed on to any relational fields in the query's subtree for filtering.
For related models with localized fields in the query's subtree, the first locale matching the provided list of locales will be returned, entries with non matching locales will be filtered out.

This argument will overwrite any existing locale filtering defined in the query's tree for the subtree. name:locales]] description:User that created this document name:createdBy type:map[description:User system model fields:[map[args:[] description:System stage field name:stage type:map[fields:[]]] map[args:[map[defaultValue:[PUBLISHED,DRAFT] description:Potential stages that should be returned name:stages] map[defaultValue:false description:Decides if the current stage should be included or not name:includeCurrent] map[defaultValue:false description:Decides if the documents should match the parent documents locale or should use the fallback order defined in the tree name:inheritLocale]] description:Get the document in other stages name:documentInStages type:map[fields:[]]] map[args:[] description:The unique identifier name:id type:map[fields:[]]] map[args:[] description:The time the document was created name:createdAt type:map[fields:[]]] map[args:[] description:The time the document was updated name:updatedAt type:map[fields:[]]] map[args:[] description:The time the document was published. Null on documents in draft stage. name:publishedAt type:map[fields:[]]] map[args:[] description:The username name:name type:map[fields:[]]] map[args:[] description:Profile Picture url name:picture type:map[fields:[]]] map[args:[] description:User Kind. Can be either MEMBER, PAT or PUBLIC name:kind type:map[fields:[]]] map[args:[] description:Flag to determine if user is active or not name:isActive type:map[fields:[]]]] interfaces:[map[__typename:__Type description:An object with an ID name:Node]] kind:OBJECT name:User ofType:<nil> possibleTypes:[]]] map[args:[map[defaultValue:COMBINED description:Variation of DateTime field to return, allows value from base document, current localization, or combined by returning the newer value of both name:variation]] description:The time the document was updated name:updatedAt type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description:A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the date-timeformat outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representationof dates and times using the Gregorian calendar. name:DateTime] possibleTypes:[]]] map[args:[map[defaultValue:<nil> description:Allows to optionally override locale filtering behaviour in the query's subtree.

[…]

Note that `filter` is a model without localized fields and will not be affected directly by this argument, however the locales will be passed on to any relational fields in the query's subtree for filtering.
For related models with localized fields in the query's subtree, the first locale matching the provided list of locales will be returned, entries with non matching locales will be filtered out.

This argument will overwrite any existing locale filtering defined in the query's tree for the subtree. name:locales]] description: name:filter type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description: name:<nil>] possibleTypes:[]]] map[args:[map[defaultValue:10 description: name:limit] map[defaultValue:0 description: name:skip] map[defaultValue:<nil> description:This is optional and can be used to fetch the document version history for a specific stage instead of the current one name:stageOverride]] description:List of PushNotification versions name:history type:map[description: fields:[] interfaces:[] kind:NON_NULL name:<nil> ofType:map[description: name:<nil>] possibleTypes:[]]]] kind:OBJECT name:PushNotification]] []}
2021/06/14 17:02:39 GraphCMS server error: 400 Bad Request
arroyo commented 3 years ago

Sorry for the radio silence. If you were to copy this query and run it in the graphcms api playground, do you get any specific errors?

BTW I renamed cmsutil to grutil. Hopefully that will clear up any name conflicts.

xbra commented 3 years ago

The GraphCMS docs show, that 400 Bad Request is “typically due to invalid query arguments”. So, printing query arguments in debug mode would be great. Can you please add this?

The last query should be this one:

query GetNodeByTypeVerbose($nodetype: String!) {
  __type(name: $nodetype) {
    name
    kind
    fields {
      name
      description
      args {
        name
        description
        defaultValue
      }
      type {
        name
        kind
        description
        fields {
          name
          description
          args {
            name
            description
            defaultValue
          }
          type {
            fields {
              name
              description
              args {
                name
                description
              }
            }
          }
        }
        possibleTypes {
          name
          description
        }
        ofType {
          name
          description
        }
        interfaces {
          name
          description
          __typename
        }
      }
    }
  }
}

With the following query arguments

{
  "nodetype": "PushNotificationGroup"
}

And the result in the play ground looks pretty okay.