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
718 stars 22 forks source link

How to move gql query to useGraphQL operation query #47

Closed gauravverma029 closed 4 years ago

gauravverma029 commented 4 years ago

I want to move my gql query to useGraphQL query.I am getting errors.i do not want to use gql now.


`USER_QUERY = gql`
  query Plan($_id: String!) {
     user(_id: $_id) {
        language
        profile {
        emailAddress
      }
      travelPolicy {
        budgetPlan {
          plan {
            allowBooking
          }
        }
      }
    }
  }
`;`

  const { loading, cacheValue = {} } = useGraphQL({
     fetchOptionsOverride(options) {
      options.url = "http://localhost:3030/graphql";
    },
    operation: {
      query: `
     Plan($_id: String!) {
     user(_id: $_id) {
        language
        profile {
        emailAddress
      }
      travelPolicy {
        budgetPlan {
          plan {
            allowBooking
          }
        }
      }
    }
  }
      `,
    },
    loadOnMount: true,
    loadOnReload: true,
    loadOnReset: true,
  });
jaydenseric commented 4 years ago

You should not use gql from graphql-tag with graphql-react; just use plain template strings:

https://github.com/jaydenseric/graphql-react#writing-queries

You can use gql from fake-tag if you need to tag for dev tools that don't understand /* GraphQL */ comments (e.g. see https://github.com/apollographql/eslint-plugin-graphql/issues/224).

Your issue might be quite simple though: Your example query with useGraphQL has a syntax error at the start.