Skip to content

Commit 97b4819

Browse files
committed
fix(doesQueryContain): improve error message if type not found
1 parent cce1944 commit 97b4819

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/doesQueryContain.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ export default function doesQueryContain(
2424
ids?: ?Set<any>,
2525
idField?: string = 'id'
2626
): boolean {
27-
const potentialAncestors = getPotentialAncestors(types[typename])
27+
const targetType = types[typename]
28+
if (!targetType) throw new Error(`type not found: ${typename}`)
29+
const potentialAncestors = getPotentialAncestors(targetType)
2830

2931
function doesNodeContain(
3032
node: Node,
3133
data: any,
3234
type: Type,
3335
): boolean {
34-
if (type.name === typename) {
36+
if (type === targetType) {
3537
if (!ids) return true
3638
return data && ids.has(data[idField])
3739
}

test/doesQueryContain.js

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import gql from 'graphql-tag'
88
import doesQueryContain from '../src/doesQueryContain'
99

1010
describe(`doesQueryContain`, function () {
11+
it(`throws if type is not found`, function () {
12+
const document = gql`{
13+
Device(id: 1) {
14+
id
15+
}
16+
}`
17+
let error
18+
try {
19+
doesQueryContain(document, types, 'Deviceg')
20+
} catch (err) {
21+
error = err
22+
}
23+
expect(error).to.exist
24+
})
1125
it(`basic test`, function () {
1226
const document = gql`{
1327
Device(id: 1) {

0 commit comments

Comments
 (0)