Skip to content

Commit

Permalink
Allow __typename in union type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeggy committed Jun 24, 2019
1 parent 067359f commit 9cf5d3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ fun Field.validateArguments(selectionArgs: Arguments?, parentTypeName : String?)


/**
* validate that only typed fragments are present
* validate that only typed fragments or __typename are present
*/
fun validateUnionRequest(field: Field.Union<*>, selectionNode: SelectionNode) {
val illegalChildren = selectionNode.children?.filterNot {
it is Fragment.Inline || it is Fragment.External
it is Fragment.Inline || it is Fragment.External || it.key == "__typename"
}

if (illegalChildren?.any() ?: false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ class UnionsSpecificationTest : BaseSchemaTest() {
}
}

@Test
fun `A Union type should allow requesting __typename`() {
val result = execute("""{
actors {
name
favourite {
... on Actor { name }
... on Director { name, age }
... on Scenario { content(uppercase: false) }
__typename
}
}
}""".trimIndent())
println(result)
}

@Test
fun `The member types of a Union type must all be Object base types`(){
expect<SchemaException>("The member types of a Union type must all be Object base types"){
Expand Down

0 comments on commit 9cf5d3c

Please sign in to comment.