graphql-kotlin icon indicating copy to clipboard operation
graphql-kotlin copied to clipboard

[feature] support @oneOf directive

Open fediazgon opened this issue 1 year ago • 3 comments

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?

fediazgon avatar Nov 22 '23 23:11 fediazgon

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

dariuszkuc avatar Nov 23 '23 06:11 dariuszkuc

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?

fediazgon avatar Nov 23 '23 09:11 fediazgon

@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.

dariuszkuc avatar Nov 23 '23 14:11 dariuszkuc