Skip to content

Instantly share code, notes, and snippets.

@geelen
Created October 26, 2019 11:27
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 geelen/127e1e9dbeee080f00bbddba4b2f8182 to your computer and use it in GitHub Desktop.
Save geelen/127e1e9dbeee080f00bbddba4b2f8182 to your computer and use it in GitHub Desktop.
hax.js
type Query = {
book(id: ID!): Book!
author(id: ID!): Author!
}
type Book = {
id: ID!
name: String
author: Author
}
type Author = {
id: ID!
name: String
books: [Book!]
}
{
book(id: 123) {
id
name
author {
id
name
}
}
}
// next page: click author
{
author(id: 123) [
id
name
books {
id
name
}
}
}
// cache
{
schema: ...,
resolvers: {
book: (cache, { id }) => cache.resolve({ __typename: 'Book', id }),
author: (cache, { id }) => cache.resolve({ __typename: 'Author', id })
}
}
// resolve
{
author: {
id: 123,
name: '',
books: null
}
}
// now i can actually fetch
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment