Skip to content

Instantly share code, notes, and snippets.

@tomitrescak
Last active July 25, 2018 20:46
Show Gist options
  • Select an option

  • Save tomitrescak/e31b20d2427ca8336c87a991cf6cab4c to your computer and use it in GitHub Desktop.

Select an option

Save tomitrescak/e31b20d2427ca8336c87a991cf6cab4c to your computer and use it in GitHub Desktop.
Medium - Resolvers
// the types below do all the heavy lifting of making everything type safe
import { Mutation, Notification, Query, Resolver } from './utils';
export const query: Query = {
// hit cmd+space and feel the magic
// params and ctx are type safe, parent and info are 'any'
notifications(_parent, params, ctx, info) {
}
};
export const mutation: Mutation = {
notify(_parent, args, ctx, info) {}
};
export const resolver: Resolver<Notification> = {
// we provide two version of the solution, where type names in resolver are NOT type safe,
// or with a bit of extra work we can make it type safe
Notification: {
// parent, ctx is type safe, args and info is any
text: async (parent, _args, ctx, info) => {}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment