Graphql-tools: how to write a mutation schema which returns null?

Created on 11 Feb 2017  Â·  4Comments  Â·  Source: ardatan/graphql-tools

I am trying to write a schema with a single mutation, which should return null. Problem is when I try to do that, I get this error:

/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:266
      throw new Error('Type "' + typeName + '" not found in document.');
      ^

Error: Type "null" not found in document.
    at typeDefNamed (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:266:13)
    at produceType (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:232:19)
    at produceOutputType (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:243:16)
    at /home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:318:15
    at /home/capaj/git_projects/tgm/api-mock/node_modules/graphql/jsutils/keyValMap.js:36:31
    at Array.reduce (native)
    at keyValMap (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/jsutils/keyValMap.js:35:15)
    at makeFieldDefMap (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:314:36)
    at fields (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/utilities/buildASTSchema.js:305:16)
    at resolveThunk (/home/capaj/git_projects/tgm/api-mock/node_modules/graphql/type/definition.js:162:40)

My schema:

type Mutation {
  forgottenPassword(email: String!): null
}

Is this a valid schema definition? If not how can I write it?

Most helpful comment

null is not a GraphQL type. You need to specify a return value as a type (e.g. String, Boolean etc). Types can be nullable, i.e. the value can be null, and, in fact, they are nullable by default (unless you define them with !).

Try:

type Mutation {
  forgottenPassword(email: String!): Boolean
}

All 4 comments

null is not a GraphQL type. You need to specify a return value as a type (e.g. String, Boolean etc). Types can be nullable, i.e. the value can be null, and, in fact, they are nullable by default (unless you define them with !).

Try:

type Mutation {
  forgottenPassword(email: String!): Boolean
}

Also, this sort of question should go to stackoverflow.

@petrbela thanks, that's ... surprising

@petrbela > Also, this sort of question should go to stackoverflow.

no

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benjaminhon picture benjaminhon  Â·  3Comments

tonyxiao picture tonyxiao  Â·  4Comments

Adherentman picture Adherentman  Â·  4Comments

ericclemmons picture ericclemmons  Â·  4Comments

dcworldwide picture dcworldwide  Â·  4Comments