Hi, I've been using this library for a while and it's pretty good, but today I'd like to discuss an improvement about schema generation of @oneOf.
According to https://github.com/graphql/graphql-spec/pull/825/files, the @oneOf is merged to main line of graphql-spec.
So I think now is a good time to talk about schema generation of @oneOf.
Currently, according to the doc, the type def below
case class Name(firstName: String, lastName: String)
@GQLOneOfInput
sealed trait AuthorInput
object AuthorInput {
case class ById(id: String)
case class ByName(name: Name)
}
will generate schema below
input NameInput {
firstName: String!
lastName: String!
}
input AuthorInput @oneOf {
id: String
name: NameInput
}
,
which brings limitation that, every kind of AuthorInput should contains exactly one field that is different from others.
Of course we can just wrap fields into new case classes, but that's a bit not ergonomically friendly.
But if we provide an alternative, which generate schema below
input ById {
id: String!
}
input ByName {
firstName: String!
lastName: String!
}
input AuthorInput @oneOf {
ById: ById
ByName: ByName
}
for type def below
@GQLOneOfInput
sealed trait AuthorInput
object AuthorInput {
case class ById(id: String)
case class ByName(firstName: String, lastName: String)
}
We can enjoy a more ergonomic model derivation.
This is just a preliminary idea, but if it's feasible, I'd love to help implement this feature.
What do you think?
Hi, I've been using this library for a while and it's pretty good, but today I'd like to discuss an improvement about schema generation of
@oneOf.According to https://github.com/graphql/graphql-spec/pull/825/files, the
@oneOfis merged to main line of graphql-spec.So I think now is a good time to talk about schema generation of
@oneOf.Currently, according to the doc, the type def below
will generate schema below
,
which brings limitation that, every kind of
AuthorInputshould contains exactly one field that is different from others.Of course we can just wrap fields into new case classes, but that's a bit not ergonomically friendly.
But if we provide an alternative, which generate schema below
for type def below
We can enjoy a more ergonomic model derivation.
This is just a preliminary idea, but if it's feasible, I'd love to help implement this feature.
What do you think?