Skip to content

Instantly share code, notes, and snippets.

@jgcmarins
Created November 3, 2017 15:05
Show Gist options
  • Save jgcmarins/e58757d5bfcae77158256effec7ea1a0 to your computer and use it in GitHub Desktop.
Save jgcmarins/e58757d5bfcae77158256effec7ea1a0 to your computer and use it in GitHub Desktop.
// @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