mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Add Node.resolveType tests
This commit is contained in:
parent
9247d34f8c
commit
8b8338b332
2 changed files with 14 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import { nodeDefinitions, fromGlobalId } from 'graphql-relay'
|
||||
import { toDashed } from './helpers'
|
||||
|
||||
const debug = require('debug')('graphbrainz:types/node')
|
||||
|
||||
const { nodeInterface, nodeField } = nodeDefinitions(
|
||||
(globalID, { loaders }) => {
|
||||
const { type, id } = fromGlobalId(globalID)
|
||||
|
|
@ -11,7 +13,7 @@ const { nodeInterface, nodeField } = nodeDefinitions(
|
|||
try {
|
||||
return require(`./${obj._type}`).default
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
debug(`Failed to load type: ${obj._type}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
test/types/node.js
Normal file
11
test/types/node.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import test from 'ava'
|
||||
import Node from '../../src/types/node'
|
||||
import ReleaseGroup from '../../src/types/release-group'
|
||||
|
||||
test('loads types from their module', t => {
|
||||
t.is(Node.resolveType({ _type: 'release-group' }), ReleaseGroup)
|
||||
})
|
||||
|
||||
test('returns null for unknown types', t => {
|
||||
t.is(Node.resolveType({ _type: 'foo' }), null)
|
||||
})
|
||||
Loading…
Reference in a new issue