-1

what changes need to perform the code:

const data = client.mutate({
    mutation: (Query)
});

let Query = gql`
  mutation{
    create(input:{
         department:"Tester", 
         code:"Tester"
    }
    )
      {
        code,
        details,
        description,   
    }
  }`
console.log(data, "data")

how to pass input dynamically? I have my input as:

var department = {
   department:"Tester", 
   code:"Tester"
}

1 Answers1

1

I haven't tested it, but it will work.
in react apollo-client

import { gql, useMutation } from '@apollo/client';

const Query = gql`
  mutation Create($department: String!, $code: String!) {
    create(department: $department, code: $code) {
        code
        details
        description
    }
  }
`;
const [create] = useMutation(Query);
create({ variables: { department: department_value, code: code_value } });

other way

const departmentValue = "Tester"
const codeValue = "Tester"
client.mutate({
  variables: { department: departmentValue, code:codeValue },
  mutation: gql`
    mutation Create($department: String!, $code: String!){
      create(department: $department, code: $code){
        code
        details
        description
      }
    }
  `,
})
.then(result => { console.log(result) })
.catch(error => { console.log(error) });
myeongkil kim
  • 2,465
  • 4
  • 16
  • 22