2016-08-31 06:33:29 +00:00
|
|
|
import { nodeDefinitions, fromGlobalId } from 'graphql-relay'
|
2016-11-26 01:38:32 +00:00
|
|
|
import { toDashed } from './helpers'
|
2016-08-31 06:33:29 +00:00
|
|
|
|
|
|
|
|
const { nodeInterface, nodeField } = nodeDefinitions(
|
2016-11-26 01:38:32 +00:00
|
|
|
(globalID, { loaders }) => {
|
2016-08-31 06:33:29 +00:00
|
|
|
const { type, id } = fromGlobalId(globalID)
|
2016-11-26 01:38:32 +00:00
|
|
|
const entityType = toDashed(type)
|
|
|
|
|
return loaders.lookup.load([entityType, id])
|
2016-08-31 06:33:29 +00:00
|
|
|
},
|
|
|
|
|
(obj) => {
|
2016-11-26 01:38:32 +00:00
|
|
|
console.log(obj.entityType)
|
2016-08-31 06:33:29 +00:00
|
|
|
try {
|
2016-09-01 04:31:48 +00:00
|
|
|
return require(`./${obj.entityType}`).default
|
2016-08-31 06:33:29 +00:00
|
|
|
} catch (err) {
|
2016-09-01 04:31:48 +00:00
|
|
|
console.error(err)
|
2016-08-31 06:33:29 +00:00
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export default nodeInterface
|
|
|
|
|
export { nodeInterface, nodeField }
|