Created
October 26, 2019 11:27
-
-
Save geelen/127e1e9dbeee080f00bbddba4b2f8182 to your computer and use it in GitHub Desktop.
hax.js
This file contains hidden or 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
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