Skip to content

Instantly share code, notes, and snippets.

@jhgg
Created October 20, 2015 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhgg/f35195a3e0ed13659eb3 to your computer and use it in GitHub Desktop.
Save jhgg/f35195a3e0ed13659eb3 to your computer and use it in GitHub Desktop.
const registeredTypes = {};
export default function register(type) {
invariant(!registeredTypes.hasOwnProperty(type.name), `Cannot register duplicate type of name ${type.name}`);
registeredTypes[type.name] = type;
}
export default function type(typeName) {
invariant(registeredTypes.hasOwnProperty(type.name), `Unknown Type ${type.name}`);
return registeredTypes[typeName];
}
export default function types(typeNames) {
return function () {
return typeNames.map(type);
}
}
// Now you can define your schema.
register(GraphQLObjectType({
name: "Dog",
fields: {
name: 'Barks'
},
interfaces: types(['Pet'])
}));
register(GraphQLInterfaceType({
name: "Pet",
fields: {
name: 'Barks'
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment