Skip to content

Instantly share code, notes, and snippets.

@cgrice
Created March 20, 2018 09:27
Show Gist options
  • Save cgrice/f4b17dc591921e2df8115898902330a1 to your computer and use it in GitHub Desktop.
Save cgrice/f4b17dc591921e2df8115898902330a1 to your computer and use it in GitHub Desktop.
const resolvers = {
// Resolvers can fetch data for fields on the query root. As long as they return
// data that matches the schema, this can come from anywhere. Here we've hardcoded
// some data.
Query: {
products: () => [
{
name: 'Eggs',
price: 199
}
]
},
// They can also retrieve data for individual types.
Product: {
// In this case, we need to access the parent node to fetch related products
related: (product) => getRelatedProducts(product.id),
// And here we need to access the arguments passed through to the field as well
inStockAt: (product, args) => isInStockAtStore(product.id, args.storeId),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment