带有 react-apollo 的自定义 InputTypes [英] Custom InputTypes with react-apollo

查看:28
本文介绍了带有 react-apollo 的自定义 InputTypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在客户端执行需要自定义输入类型的突变查询.目前它看起来像这样:

I'm trying to execute a mutation query that requires a custom input type on the client. Currently it looks something like this:

import { graphql } from 'react-apollo';
...
const graphQuery = graphql(gql`
  input UserSignUpInput {
    firstName: String!,
    lastName: String!,
    email: String!,
    password: String!
  }
  mutation userSignUp($input: UserSignUpInput!) {
    createUserByEmail(input: $input) {
      authToken
    }
  }`, {
  props: ({ mutate }) => ({
    signup: (firstName, lastName, email, password) =>
      mutate({ variables: { input: { firstName, lastName, email, password } } }),
  }),
});
...

但是我收到错误,我不允许在查询中定义输入类型.我的问题是:如何定义这些复杂的输入类型?我似乎无法为 ApolloClient 提供 Schema ..

However I'm getting the error that I'm not allowed to define input types in the query. My question is: How do I define these complex input types? It doesn't seem like I'm able to provide a Schema to ApolloClient..

推荐答案

客户端 端的正确语法是:

gql`
  mutation userSignUp($input: UserSignUpInput!) {
    createUserByEmail(input: $input) {
      authToken
    }
  }
`

当您的输入 UserSignUpInput 在服务器上定义时,一切正常.

As your input UserSignUpInput is defined on the server, everything is going fine.

服务器

input UserSignUpInput {
  firstName: String!,
  lastName: String!,
  email: String!,
  password: String!
}

这篇关于带有 react-apollo 的自定义 InputTypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆