简体   繁体   中英

“Unknown argument \”email\“ on field \”forgotPassword\“ of type \”Mutation\“.”

I would like to have an endpoint "forgotPassword" where an input is email, and there is no output (the result of the action is an email sent to the user). This looks like a mutation, rather than a query. I'm using graphqli on the front, and graphql-relay with node, express on the backend. I have this so far:

import {
  fromGlobalId,
  connectionDefinitions,
  forwardConnectionArgs,
  connectionFromArraySlice,
  cursorToOffset,
  mutationWithClientMutationId,
  graphql,
} from 'graphql-relay'
import { GraphQLObjectType,
  GraphQLInputObjectType,
  GraphQLString, GraphQLNonNull, GraphQLID, GraphQLInt, GraphQLBoolean, } from 'graphql'


const forgotPassword = mutationWithClientMutationId({
  name: 'forgotPassword',
  inputFields: {
    email: { type: GraphQLString },
  },
  outputFields: {
    email: { type: GraphQLString },
  },
  mutateAndGetPayload: (arg1, arg2) => {
    console.log('+++ forgotPassword mutate and get payload:', arg1, arg2)
    return "status: ok"
  }
})

And then I get: 在此处输入图片说明

What am I doing wrong, how do I fix this error? Also, what should I use to define a mutation, is it "mutationWithClientMutationId" or another method is preferable?

How can I make is so that there isn't a return value? (I'm currently returning the email)

My guess is that the argument email: $email should be wrapped in an input object like this:

input: {
  email: $email
}

I personally don't use relay's mutation helper function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM