diff --git a/src/doesQueryContain.js b/src/doesQueryContain.js index 72844d9..d96e56d 100644 --- a/src/doesQueryContain.js +++ b/src/doesQueryContain.js @@ -24,14 +24,16 @@ export default function doesQueryContain( ids?: ?Set, idField?: string = 'id' ): boolean { - const potentialAncestors = getPotentialAncestors(types[typename]) + const targetType = types[typename] + if (!targetType) throw new Error(`type not found: ${typename}`) + const potentialAncestors = getPotentialAncestors(targetType) function doesNodeContain( node: Node, data: any, type: Type, ): boolean { - if (type.name === typename) { + if (type === targetType) { if (!ids) return true return data && ids.has(data[idField]) } diff --git a/test/doesQueryContain.js b/test/doesQueryContain.js index b429ca2..c8b6019 100644 --- a/test/doesQueryContain.js +++ b/test/doesQueryContain.js @@ -8,6 +8,20 @@ import gql from 'graphql-tag' import doesQueryContain from '../src/doesQueryContain' describe(`doesQueryContain`, function () { + it(`throws if type is not found`, function () { + const document = gql`{ + Device(id: 1) { + id + } + }` + let error + try { + doesQueryContain(document, types, 'Deviceg') + } catch (err) { + error = err + } + expect(error).to.exist + }) it(`basic test`, function () { const document = gql`{ Device(id: 1) {