【问题标题】:"Unknown argument \"email\" on field \"forgotPassword\" of type \"Mutation\".""未知参数 \"email\" 在类型 \"Mutation\" 的字段 \"forgotPassword\" 上。"
【发布时间】:2019-01-15 03:45:49
【问题描述】:

我想要一个端点“forgotPassword”,其中输入是电子邮件,没有输出(操作的结果是发送给用户的电子邮件)。这看起来像一个突变,而不是一个查询。我在前端使用graphqli,在后端使用带有节点的graphql-relay,表示。到目前为止我有这个:

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"
  }
})

然后我得到:

我做错了什么,我该如何解决这个错误?另外,我应该用什么来定义突变,是“mutationWithClientMutationId”还是其他方法更可取?

我怎样才能使没有返回值? (我目前正在回邮件)

【问题讨论】:

    标签: javascript express graphql graphql-relay


    【解决方案1】:

    我的猜测是参数email: $email 应该像这样包装在输入对象中:

    input: {
      email: $email
    }
    

    我个人不使用relay的mutation helper函数。

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 2020-11-27
      • 2020-05-18
      • 2020-01-10
      • 2019-09-12
      • 2020-05-31
      • 2019-03-28
      • 2017-02-03
      • 1970-01-01
      相关资源
      最近更新 更多