Skip to content

Commit

Permalink
fix: check for empty fields in InputFilter inference (#9057)
Browse files Browse the repository at this point in the history
* Check for empty fields in InputFilter inference

* Add test

* We already have test for unknown types, so let's add one case there
  • Loading branch information
stefanprobst authored and pieh committed Oct 17, 2018
1 parent a2aced4 commit 4a0563e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Expand Up @@ -267,6 +267,14 @@ describe(`GraphQL Input args from fields, test-only`, () => {
},
})
),
baz: typeField(
new GraphQLObjectType({
name: `Jbo2`,
fields: {
aa: typeField(OddType),
},
})
),
},
}),
},
Expand All @@ -293,6 +301,10 @@ describe(`GraphQL Input args from fields, test-only`, () => {
isStringInput(innerObjFields.foo.type)
expect(innerObjFields.ba).toBeUndefined()
isIntInput(innerObjFields.bar.type)

// innerObj.baz is object containing only unsupported types
// so it should not be defined
expect(innerObj.baz).toBeUndefined()
})

it(`includes the filters of list elements`, async () => {
Expand Down
Expand Up @@ -138,15 +138,19 @@ function convertToInputFilter(
fields: fields,
})
} else if (type instanceof GraphQLInputObjectType) {
const fields = _.transform(type.getFields(), (out, fieldConfig, key) => {
const type = convertToInputFilter(
`${prefix}${_.upperFirst(key)}`,
fieldConfig.type
)
if (type) out[key] = { type }
})
if (Object.keys(fields).length === 0) {
return null
}
return new GraphQLInputObjectType({
name: createTypeName(`${prefix}{type.name}`),
fields: _.transform(type.getFields(), (out, fieldConfig, key) => {
const type = convertToInputFilter(
`${prefix}${_.upperFirst(key)}`,
fieldConfig.type
)
if (type) out[key] = { type }
}),
fields: fields,
})
} else if (type instanceof GraphQLList) {
const innerType = type.ofType
Expand Down

0 comments on commit 4a0563e

Please sign in to comment.