Home > Blockchain >  GraphQL mutation Invalid payload
GraphQL mutation Invalid payload

Time:10-23

I have the following mutation

mutation createFoo {
    createFoo(data: {title: "Test"}) {
        foo {
            id
            title
        }
    }
}

When I ran I got the error

AssertionError: 'errors' unexpectedly found in ['errors', 'data'] : {'errors': [{'message': 'Invalid payload', 'locations': [{'line': 3, 'column': 17}], 'path': ['createFoo']}], 'data': {'createFoo': None}}

What can be?

CodePudding user response:

How is this mutation defined in your typeDefs? If you have:

mutation createFoo(title: String!): foo

then you need to invoke it with:

mutation createFoo {
    createFoo(title: "Test") {
        id
        title
    }
}

If on the other hand you have:

mutation createFoo(data: {title: String!}): foo

(which would be weird) then you need to invoke it with:

mutation createFoo {
    createFoo(data: {title: "Test"}) {
        id
        title
    }
}

One of the other or both of data: in the input or foo {…} in the output are likely redundant.

  • Related