Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Created March 5, 2018 18:40
Show Gist options
  • Save jbaxleyiii/91d06f35624faabb45d606ad0555a356 to your computer and use it in GitHub Desktop.
Save jbaxleyiii/91d06f35624faabb45d606ad0555a356 to your computer and use it in GitHub Desktop.
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