码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-08 23:28:11      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:add   object   state   tor   read   oca   idt   only   embed   

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

 

 

 

 

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

标签:add   object   state   tor   read   oca   idt   only   embed   

原文地址:https://www.cnblogs.com/Answer1215/p/9610930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!