Corresponding graphql-tag for a schema with nested inputs?

799 Views Asked by At

I'm following a tutorial (here:https://www.howtographql.com/graphql-js/5-authentication/) on graphql and came across a mutation with nested inputs. How would I write the corresponding graphql-tag?

gql``  

Schema:

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

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

input AuthProviderSignupData {
  email: AuthProviderEmail
}

Corresponding graphiql input:

mutation CreateUser {
  createUser(name: "tester2", authProvider: {email: {email: "[email protected]", password: "password"}}) {
    id
    name
  }
}
1

There are 1 best solutions below

2
On BEST ANSWER
const mutation = gql`
   mutation createUser($authProvider: AuthProviderSignupData!, $name: String!) {
     createUser(authProvider: $authProvider, name: $name) {
       id
     }
   }
`

const variables = {
    "authProvider": {
      "email": {
         "email": "[email protected]",
          "password": "123456789"
         }
      },
     "name": "chakri",      
    }