如何在Apollo-Client中进行查询?
问题描述:
使用REST-API,我们可以提取查询而不是查询服务器。 我使用“Apollo-client”,但我想创建查询,而不将此查询连接到组件。我可以做吗? 可能我应该使用方法client.query(http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient.query)和client.mutate或类似的东西?如何在Apollo-Client中进行查询?
答
const apolloClient = new ApolloClient({
networkInterface: createNetworkInterface({uri: 'http://localhost:3003/graphql'})
});;
const loginQueruy = gql `Your query code here`,
,然后在代码
const apolloQuery = {
query: loginQuery,
};
apolloClient
.query(apolloQuery)
.then((res) => {
console.log("RES", res)
})