2021-04-16 04:34:29 +00:00
|
|
|
import GraphQLRelay from 'graphql-relay';
|
|
|
|
|
import { toDashed } from '../util.js';
|
|
|
|
|
import { resolveType } from './helpers.js';
|
2016-08-31 06:33:29 +00:00
|
|
|
|
2021-04-16 04:34:29 +00:00
|
|
|
const { nodeDefinitions, fromGlobalId } = GraphQLRelay;
|
2016-12-14 05:18:33 +00:00
|
|
|
|
2016-08-31 06:33:29 +00:00
|
|
|
const { nodeInterface, nodeField } = nodeDefinitions(
|
2016-11-26 01:38:32 +00:00
|
|
|
(globalID, { loaders }) => {
|
2021-04-16 04:34:29 +00:00
|
|
|
const { type, id } = fromGlobalId(globalID);
|
|
|
|
|
const entityType = toDashed(type);
|
|
|
|
|
return loaders.lookup.load([entityType, id]);
|
2016-08-31 06:33:29 +00:00
|
|
|
},
|
2021-04-16 04:34:29 +00:00
|
|
|
resolveType
|
|
|
|
|
);
|
2016-08-31 06:33:29 +00:00
|
|
|
|
2021-04-16 04:34:29 +00:00
|
|
|
export const Node = nodeInterface;
|
|
|
|
|
export { nodeInterface, nodeField };
|