Validation error of type FieldUndefined: Field 'register' in type 'Query' is undefined

邮差的信 提交于 2019-12-06 07:39:16

You are telling GraphQL that you are requesting a Query, while in fact register is a Mutation. When composing a GraphQL request, the syntax typically follows this format for Queries:

query someOperationName {
  login {
    # other fields
  }
}

When writing a mutation, you simply specify that instead:

mutation someOperationName {
  register {
    # other fields
  }
}

You can leave the operation name out, although it's good practice to include it. You may see examples in this format:

{
  someQuery {
    # other fields
  }
}

In this case both the operation name and the operation type (query vs mutation) were left off. This is still a valid request, since GraphQL simply assumes you meant query when you leave off the operation type. From the spec:

If a document contains only one operation, that operation may be unnamed or represented in the shorthand form, which omits both the query keyword and operation name.

So in your request, GraphQL is assuming register is a query, while in fact it's a mutation, and it's returning an error as a result.

Again, when writing requests, it's good practice to always include both the operation name and query/mutation keyword.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!