Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

74
Views
GraphQL result for another mutation

Is it meanwhile possible to use the result of a GraphQL mutation as a parameter for another mutation?

I would like to create a user and his address together in one call.

First I write the address and then take the address id for the creation of the user. Filling the necessary data via the inputs works perfectly

Is this possible without triggering a new mutation from the client?

const createUser = gql`
  mutation createUser(
    $user: createUserInput!
    $address: createAddressInput!
  ) {
    createAddress(input: $address) {
      address {
        id       
      }
    }
    createUser(input: $user ) {
      user {
        id
        username
      }
    }
  }
`
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

No, this is not possible. You either have to make two sequential requests from the client, or adapt your server implementation. I recommend the latter.

You should change your schema so that the CreateUserInput type to not only accepts an addressId: ID but alternatively can accept a newAddress: CreateAddressInput object, which it will then use to create a new address before creating a new user.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs