I'd like to mock an error response in graphql-tools/addMockFunctionsToSchema
mock resolver following this pattern:
const mocks = {
...,
Mutation: () => ({
getToken: (_, { password }) => {
if (password === 'password') {
return { value: casual.uuid }
} else {
throw new Error('Incorrect email or password')
}
}
})
}
const schema = makeExecutableSchema({`
type Token { value: ID! }
type Mutation {
getToken(email: String!, password: String!): Token
}
`});
addMockFunctionsToSchema({ schema, mocks});
This works OK and does return a GraphQL error but:
I was just looking into this issue today. It turns out that you should just return the error instead of throwing one.
Mutation: () => ({
getToken: (_, { password }) => {
if (password === 'password') {
return { value: casual.uuid }
} else {
return new Error('Incorrect email or password')
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With