Graphql-tag: Combine mutations

Created on 27 May 2017  路  4Comments  路  Source: apollographql/graphql-tag

Hi,

I'm struggling the best way to understand how to do this. There is not much documentation for this lib.

In short i have a dynamic amount of mutations I need to preform in a single operations/call. I was trying to figure out some how i can dynamically build these or concat two qgl mutations together?

Any ideas?

question

Most helpful comment

multiple mutations can be constructed within the same call to graphql-tag like

import gql from 'graphql-tag';

const mutation = gql`
  mutation {
    mutationOne
    mutationTwo
  }
`

if you wanted to construct it dynamically, its just a matter of interpolating those strings (what gql is parsing is just a string, after all).

import gql from 'graphql-tag';

const mutationNames = ['mutationOne', 'mutationTwo'];

const mutation = gql`
  mutation {
    ${mutationNames}
  }
`;

All 4 comments

multiple mutations can be constructed within the same call to graphql-tag like

import gql from 'graphql-tag';

const mutation = gql`
  mutation {
    mutationOne
    mutationTwo
  }
`

if you wanted to construct it dynamically, its just a matter of interpolating those strings (what gql is parsing is just a string, after all).

import gql from 'graphql-tag';

const mutationNames = ['mutationOne', 'mutationTwo'];

const mutation = gql`
  mutation {
    ${mutationNames}
  }
`;

@stevezau lmk if you still need help with this, i'm also in the Apollo slack if that is an easier way to answer this.

All good, forgot to reply. Thanks!

I cannot make it work, I am having the error : unexpected [

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hopewise picture hopewise  路  8Comments

pwo3 picture pwo3  路  5Comments

val-samonte picture val-samonte  路  9Comments

julmot picture julmot  路  5Comments

felixfbecker picture felixfbecker  路  6Comments