Skip to content

Instantly share code, notes, and snippets.

@jhgg
Created October 20, 2015 18:36
Show Gist options
  • 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