0

I simply want to use an @client (local cache) variable as a query parameter to my apollo server. The docs reference the @export directive (https://www.apollographql.com/docs/react/data/local-state/#querying-local-state)

For some reason, I am unable to do something like

export const GET_COMPANY_DATA = gql`
  query GetCompanyData($id: ID!, $name: STRING!) {
    group @client @export(as: "name")
    getCompanyData(id: $id) {
      company {
        groups(name: $name) {
          data
        }
      }
    }
  }
;

Both queries work individually, for example:

{
  group @client
}

returns a string as it should from the local cache

export const GET_COMPANY_DATA = gql`
  query GetCompanyData($id: ID!, $name: STRING!) {
    getCompanyData(id: $id) {
      company {
        groups(name: $name) {
          data
        }
      }
    }
  }
;

returns the proper object type

In the docs, they show this example with no reference to the schema:

const query = gql`
  query currentAuthorPostCount($authorId: Int!) {
    currentAuthorId @client @export(as: "authorId")
    postCount(authorId: $authorId) @client
  }
`;

What am I doing wrong? I feel like I am missing some fundamental concept...

0

1 Answer 1

0

I figured it out; when setting up apollo client, you must add the resolvers property even if you don't have any:

const client = new ApolloClient({
  cache,
  link: authLink.concat(httpLink),
  **resolvers: {}**
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.