zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[GraphQL] Query Local and Remote Data in Apollo Link State

in and Data Query State local Link Remote
2023-09-14 08:59:17 时间

In this lesson, you will learn how to query local and remote data in Apollo Link State in the same component.

We'll set the @client decorator on the local client State variable and set an empty Query object to get this done.

 

Query cache data:

TO query caches data, only need to add '@client':

const getCountQuery = gql`
  {
    count @client
    pokemon(name: "Pikachu") {
      image
    }
  }
`;

 

Set up default data for the client:

const client = new ApolloClient({
  uri: "https://graphql-pokemon.now.sh",
  clientState: {
    defaults: {
      count: 0
    },
    resolvers: {
      Query: {}
    }
  }
});

 

Read More: https://www.apollographql.com/docs/react/essentials/local-state.html