Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow classes corresponding to SDL to be decoupled from implementation #1931

Open
danadajian opened this issue Feb 20, 2024 · 0 comments
Labels
type: enhancement New feature or request

Comments

@danadajian
Copy link

danadajian commented Feb 20, 2024

Is your feature request related to a problem? Please describe.

I want to leverage abstract classes to define interfaces corresponding to schema types, and have separate resolver classes inherit from those abstract classes. This provides a type contract that I can enforce separately from my resolvers.

For example, if my desired schema is:

type Query {
  myQuery(): MyType
}

type MyType {
  myField(myArg: String!): String!
}

Currently I need to couple my Kotlin schema classes with my implementation, like so:

class MyQuery : Query {
  fun myQuery(): MyType = MyType()
}

class MyType {
  fun myField(myArg: String): String = "resolve me"
}

But I instead want to leverage an abstract Kotlin class that corresponds to the schema:

class MyQuery : Query {
  fun myQuery(): MyType = MyTypeResolver()
}

abstract class MyType {
  abstract fun myField(myArg: String): String
}

class MyTypeResolver : MyType() {
  override fun myField(myArg: String) = "resolve me"
}

I would include the abstract class MyType in scope for SDL generation, and I would exclude MyTypeResolver from SDL generation, such that the abstract class explicitly defines the resulting SDL. As a result, my Kotlin that corresponds to SDL can be decoupled from my implementation.

However, when I attempt to do this, I get the following error at runtime from graphql-java when executing a query:
Abstract type "MyType" must resolve to an Object type at runtime for field "MyType.myfield". Could not determine the exact type of "MyType"

Describe the solution you'd like
I would like it to be possible to define schema-specific interfaces in Kotlin in a way that is decoupled from my implementation. If the blocker here exists within graphql-java, I wonder if there is a way that graphql-kotlin can help us work around it. Maybe we can add support for a particular directive? 🤷

@danadajian danadajian added the type: enhancement New feature or request label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Development

No branches or pull requests

1 participant