Query Parameter for List of Union
See original GitHub issueLibrary Version
GraphQL Kotlin Spring Server - 3.1.0
Describe the bug
A query parameter of type List of a Union type generates a “valid” schema (see SDL below). However the only valid GraphQL query is the following:
{
shapes(colors:[]) {
id
}
}
and attempting to put any object into colors: []
fails with “Validation error of type WrongType”.
To Reproduce
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
@Component
class ShapesQuery : Query {
suspend fun shapes(colors: List<Colors>): List<Shape> = listOf()
}
data class Shape(val id: String)
interface Colors
data class Red(val red: String): Colors
data class Blue(val blue: String): Colors
- Visit Playground and query for shapes.
Expected behavior
It should probably be invalidated at startup as it would appear Unions on input types are not supported in the GraphQL spec (currently?).
Generated SDL
schema {
query: Query
}
"Directs the executor to include this field or fragment only when the `if` argument is true"
directive @include(
"Included when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"Directs the executor to skip this field or fragment when the `if`'argument is true."
directive @skip(
"Skipped when true."
if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"Marks the field or enum value as deprecated"
directive @deprecated(
"The reason for the deprecation"
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE
"Exposes a URL that specifies the behaviour of this scalar."
directive @specifiedBy(
"The URL that specifies the behaviour of this scalar."
url: String!
) on SCALAR
union Colors = Blue | Red
type Blue {
blue: String!
}
type Query {
shapes(colors: [Colors!]!): [Shape!]!
}
type Red {
red: String!
}
type Shape {
id: String!
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
SLICK: A simple query using union and parameter lists
I'm new to SLICK (2.1) and am lost in creating my first query using union . Because the parameters are provided from external...
Read more >Use a union query to combine multiple queries into ...
Get a combined view of multiple select queries with a union query. ... to form one set of records - a list with...
Read more >Query Parameters and String Validations - FastAPI
The query parameter q is of type Union[str, None] (or str | None in Python 3.10), that means that it's of type str...
Read more >Adding A Parameter In Access Query: Using A Union Query
The union simply appends the records into one ultimate list using the keyword UNION in the SQL statement. Yep, we need to learn...
Read more >Unions and interfaces - Apollo GraphQL Docs
The SearchResult union enables Query.search to return a list that includes both Book s and Author s. Querying a union. GraphQL clients don't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe the problem is here -> https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/types/generateArgument.kt#L32
i.e. we check whether parameter is an interface AND is not a list (as list is an interface), proper check should unwrap the type and then validate it -> something along those lines
I’ll submit a patch tomorrow.
I agree schema generation should fail in this scenario.