Skip to content

Instantly share code, notes, and snippets.

@nataliemarleny
Created July 7, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliemarleny/19ce507479779bf0d4f9aa184bf00f80 to your computer and use it in GitHub Desktop.
Save nataliemarleny/19ce507479779bf0d4f9aa184bf00f80 to your computer and use it in GitHub Desktop.
ES6 object syntax (implicit object properties)
// Reduced
const obj1 = {
fun1() {}
}
const obj1 = {
fun1: () => {}
}
// this
// source: https://www.apollographql.com/docs/graphql-tools/resolvers/#unions-and-interfaces
const resolverMap = {
Vehicle: {
__resolveType(obj, context, info) {
if (obj.wingspan) {
return 'Airplane';
}
if (obj.licensePlate) {
return 'Car';
}
return null;
}
}
};
// is the same as (source: brain + time)
const resolverMap = {
Vehicle: {
__resolveType: (obj, context, info) => {
if (obj.wingspan) {
return 'Airplane';
}
if (obj.licensePlate) {
return 'Car';
}
return null;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment