Created
October 20, 2015 18:36
-
-
Save jhgg/f35195a3e0ed13659eb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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