jaydenseric / graphql-react

A GraphQL client for React using modern context and hooks APIs that is lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.
https://npm.im/graphql-react
MIT License
717 stars 22 forks source link

Multiple operations on the same query #39

Closed fev4 closed 5 years ago

fev4 commented 5 years ago

This is somewhat what I want to achieve

operation: {
      variables: { sanitizedemail },
      query: /* GraphQL */ `
        mutation SubscribeToMarketing($sanitizedemail: String!) {
          mailchimpAddContact(params: { email: $sanitizedemail }) {
            email
          }
        }
        mutation CreateUserOnDb($sanitizedemail: String!) {
          dbCreateUser(params: { email: $sanitizedemail }) {
            email
          }
        }
      `,
    },

What am I missing to make it work with graphql-react?

I'm a little lost on this, any help is appreciated

Cheers

fev4 commented 5 years ago

Hmm my bad, this had nothing to do with the graphql-react, just didn't know how to properly write the query.

Here's I guess the correct syntax:

mutation SubscribeToMarketing($sanitizedemail: String!) {
          mailchimpAddContact(params: { email: $sanitizedemail }) {
            email
          }
          dbCreateUser(params: { email: $sanitizedemail }) {
            email
          }
        }

The resulting data response will contain two objects with the names given, in this case, mailchimpAddContact and dbCreateUser respectively.

Hope this helps someone else.