lionixevolve/GraphQLSuiteCRM

Mutation not working

Closed this issue · 1 comments

Hello,

I am trying to submit form to create records in suitecrm but mutations not working. Mutations working find with graphql tools but its not working with apollo-react.

Getting Below errors.

{"errors":[{"message":"Must provide an operation."}]}

Environment:
Suitecrm 7.11.2
PHP 7.0.22
NodeJs: 11.9.0
NextJs
React Apollo

Would you please suggest how to fix above issue.

Hi @rigalpatel001 , please take a look at this full example using "react-apollo": "^2.4.1" and this graphqlSuiteCRM library. This is taken from a fully working react app.

First define the mutation, in this example this is an UPDATE operation.

const oppMutationQuery = gql`
  mutation createOpportunity($id: String, $sales_stage: String) {
    createOpportunity(id: $id, sales_stage: $sales_stage) {
      id
    }
  }
`;

Here we name the operation to access the result in props.

const oppMutationOptions = { name: "oppMutation" };

This is how to use withApollo

export default 
  withApollo(
    compose(
      graphql(callMutationQuery, callMutationOptions),
      graphql(oppMutationQuery, oppMutationOptions)
    )(Opportunities)
);

This is how to call the operation

this.props
  .oppMutation({
    variables: {
      id: this.state.oppSelected.id,
      sales_stage: this.state.oppUpdate.sales_stage.value
    }
  })
  .then(result => {
        console.error("result: ", result);
  }).catch(error => {
    console.error("error creating opp: ", error);
  });