Skip to content

Commit

Permalink
fix(doesQueryContain): improve error message if type not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Jul 19, 2018
1 parent cce1944 commit 97b4819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/doesQueryContain.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ export default function doesQueryContain(
ids?: ?Set<any>,
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])
}
Expand Down
14 changes: 14 additions & 0 deletions test/doesQueryContain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 97b4819

Please sign in to comment.