2

我正在学习有关 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
  }
}
4

1 回答 1

2
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",      
    } 
于 2017-12-17T11:34:25.723 回答