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

how to write a mutation schema which returns null? #277

Closed
capaj opened this issue Feb 11, 2017 · 4 comments
Closed

how to write a mutation schema which returns null? #277

capaj opened this issue Feb 11, 2017 · 4 comments

Comments

@capaj
Copy link

capaj commented Feb 11, 2017

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?

@petrbela
Copy link

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
}

@petrbela
Copy link

Also, this sort of question should go to stackoverflow.

@capaj
Copy link
Author

capaj commented Feb 11, 2017

@petrbela thanks, that's ... surprising

@MaxmaxmaximusGitHub
Copy link

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

no

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

No branches or pull requests

3 participants