Skip to content

Instantly share code, notes, and snippets.

@hwillson
Last active February 16, 2019 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwillson/2b18e5b31bf5c61a16e691045aabf32f to your computer and use it in GitHub Desktop.
Save hwillson/2b18e5b31bf5c61a16e691045aabf32f to your computer and use it in GitHub Desktop.
Apollo Client - 2.5.0 Announcement Post - @client @export
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import gql from 'graphql-tag';
const query = gql`
query currentAuthorPosts($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
posts(authorId: $authorId) {
title
timestamp
}
}
`;
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: 'http://localhost:4000/graphql',
}),
resolvers: {
Query: {
currentAuthorId() {
// Load the current author ID from somewhere, like
// the cache
return 12345;
},
},
},
});
client.query({ query }).then((result) => {
// `result` holds post data for the current
// author
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment