Created
November 3, 2017 15:05
-
-
Save jgcmarins/e58757d5bfcae77158256effec7ea1a0 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
// @flow | |
import { nodeDefinitions, fromGlobalId } from 'graphql-relay'; | |
import UserType from '../type/UserType'; | |
const { nodeInterface, nodeField, nodesField } = nodeDefinitions( | |
// A method that maps from a global id to an object | |
async (globalId, context, options) => { | |
const { id, type } = fromGlobalId(globalId); | |
// console.log('node: ', id, type); | |
if (type === 'User') { | |
return UserLoader.load(id); | |
} | |
// it should not get here | |
return null; | |
}, | |
// A method that maps from an object to a type | |
obj => { | |
if (obj instanceof UserLoader) { | |
return UserType; | |
} | |
// it should not get here | |
return null; | |
}, | |
); | |
export const NodeInterface = nodeInterface; | |
export const NodeField = nodeField; | |
export const NodesField = nodesField; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment