Created
March 5, 2018 18:40
-
-
Save jbaxleyiii/91d06f35624faabb45d606ad0555a356 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
const query = gql` | |
query FetchWhatMyAppNeeds { | |
# run 1 | |
tasks { | |
id | |
details { | |
date | |
title | |
# run 2 | |
header @client # virutal field (date + title) | |
} | |
} | |
# this is never applied because it isn't below | |
# a root field, so the resolver never runs for it | |
# run 2 | |
todos @client { | |
id | |
detail { | |
title | |
} | |
} | |
} | |
`; | |
const mutation = gql` | |
mutation addTodo($title: String) { | |
addTodo(title: $title) { | |
id | |
detail { | |
title | |
} | |
} | |
} | |
`; | |
const defaults = { | |
todos: [], | |
}; | |
const resolvers = { | |
Mutation: { | |
addTodo: (_, { title }, { cache }) => { | |
cache.writeData({ todo: { id: 1, detail: { title } } }); | |
}, | |
}, | |
Detail: { | |
header: ({ date, title }) => `${title} is due on ${date}`, | |
}, | |
}; | |
const link = withLinkState({ cache, defaults, resolvers }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment