【问题标题】:Corresponding graphql-tag for a schema with nested inputs?具有嵌套输入的模式的相应 graphql-tag?
【发布时间】:2018-05-30 16:11:19
【问题描述】:

我正在学习有关 graphql 的教程(此处:https://www.howtographql.com/graphql-js/5-authentication/),并遇到了带有嵌套输入的突变。 怎么写对应的graphql-tag?

gql``  

架构:

type Mutation {
  createUser(name: String!, authProvider: AuthProviderSignupData!): User
}
###########
## Inputs
###########

input AuthProviderEmail {
  email: String!
  password: String!
}

input AuthProviderSignupData {
  email: AuthProviderEmail
}

对应的graphiql输入:

mutation CreateUser {
  createUser(name: "tester2", authProvider: {email: {email: "test@test.com", password: "password"}}) {
    id
    name
  }
}

【问题讨论】:

    标签: apollo graphql-js react-apollo graphcool


    【解决方案1】:
    const mutation = gql`
       mutation createUser($authProvider: AuthProviderSignupData!, $name: String!) {
         createUser(authProvider: $authProvider, name: $name) {
           id
         }
       }
    `
    
    const variables = {
        "authProvider": {
          "email": {
             "email": "chakri@example.com",
              "password": "123456789"
             }
          },
         "name": "chakri",      
        } 
    

    【讨论】:

    • 我不知道如何选择你的答案作为正确的答案;但是,我确实想澄清一下,您的答案是我正在寻找的,但缺少完全正确的 $name 部分。谢谢!
    • 什么是 AuthProviderSignupData ?它只是一个简单的字符串还是在某个地方声明它
    猜你喜欢
    • 2020-01-31
    • 2021-03-16
    • 1970-01-01
    • 2021-04-21
    • 2018-07-23
    • 2015-11-24
    • 2019-02-07
    • 2019-08-12
    • 2019-12-21
    相关资源
    最近更新 更多