Last active
February 16, 2019 21:17
-
-
Save hwillson/2b18e5b31bf5c61a16e691045aabf32f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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