ExpediaGroup / graphql-kotlin

Libraries for running GraphQL in Kotlin
https://opensource.expediagroup.com/graphql-kotlin/
Apache License 2.0
1.74k stars 348 forks source link

[feature] support @oneOf directive #1891

Open fediazgon opened 11 months ago

fediazgon commented 11 months ago

graphql-java added support for the @oneOf directive in the 21.2 release. I understand that graphql-kotlin is still using the 21.1 release, but I was wondering if I will be able to use this directive out-of-the-box.

In the docs I can see that other directives like @skip are supported:

However, how do I annotate my schema and use graphql-kotlin-schema-generator to generate this annotations for me? What I want is to write Kotlin code like this:

@GraphqlOneOf
data class Some(
 val a: String?
 val b: Int?
)

and graphql-kotlin-schema-generator will generate code like:

type Some @oneOf { ... }

Do I have to use custom directives for this?

dariuszkuc commented 11 months ago

Hello 👋 Currently there is no built-in mechanism to support it as @oneOf is still not part of the GraphQL spec. While some implementations already added the support, RFC is still open (but it is getting close to be finalized). Once RFC is merged to the spec we'll work on adding the support.

Haven't tried it but 'm guessing you might be able to support it by writing some custom hooks + data fetcher that could handle some sort of wrapper.

Thanks, Derek

fediazgon commented 11 months ago

Thanks for the prompt response.

My second part of the question was: it seems there are multiple directives that are supported according to the docs (e.g., @skip, @include). However these do not have their corresponding annotation in com.expediagroup.graphql.generator.annotations as, for example, @deprecated has @GraphQLDeprecated. How do I annotate my Kotlin schema to make use of these annotations?

dariuszkuc commented 11 months ago

@skip/@include are executable directives so they are not part of your schema but instead are provided by clients writing their queries. Since there is nothing to represent in the schema, we don't provide annotations for them.

@specifiedBy directive is a schema directive that is applicable on custom scalars so technically we could provide corresponding annotation... but since you still need to provide manual configuration for your custom scalars (e.g. coercing logic) it's seemed like that would be the right place to do it.