UNPKG

graphql-compose-relay

Version:

Plugin for `graphql-compose` which wraps graphql types with Relay specific logic.

24 lines (23 loc) 717 B
import { InterfaceTypeComposer } from 'graphql-compose'; const NodeTC = InterfaceTypeComposer.createTemp({ name: 'Node', description: 'An object, that can be fetched by the globally unique ID among all types.', fields: { id: { type: 'ID!', description: 'The globally unique ID among all types.' } }, resolveType: payload => { // `payload.__nodeType` was added to payload via nodeFieldConfig.resolve return payload.__nodeType ? payload.__nodeType : null; } }); export const NodeInterface = NodeTC.getType(); export function getNodeInterface(sc) { if (sc.hasInstance('Node', InterfaceTypeComposer)) { return sc.get('Node'); } sc.set('Node', NodeTC); return NodeTC; }