Skip to content

[Scala] [Kotlin] Parameterized field getters in type interface are missing parameters #939

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

Open
kobylynskyi opened this issue Jan 16, 2022 · 0 comments
Assignees
Labels
bug Something isn't working kotlin Pull requests that update Kotlin code scala Pull requests that update Scala code

Comments

@kobylynskyi
Copy link
Owner

Related to #859

Java implementation was done as part of #913
What's missing is the implementation for Scala and Kotlin

Original description from #859

Issue Description

I would like to generate a type as an interface that has parameterized fields, without using separate field resolvers for the parameterized fields. Since the type is being generated as an interface rather than a concrete class, I would expect the getter methods for the parameterized fields to be properly parameterized. However, there are no such parameters on the getters for the parameterized fields, and the generated interface is invalid/unusable.

Steps to Reproduce

Excerpt of relevant graphql schema:

"used with typesAsInterfaces config"
directive @asInterface on OBJECT

"used with fieldsWithResolvers config"
directive @noResolver on FIELD_DEFINITION

type Foo @asInterface {
  simpleField: String!
  parameterizedField(count: Int!): String! @noResolver
}

Expected Result

Expected generated interface:

public interface Foo {
    @javax.validation.constraints.NotNull
    String getSimpleField();

    @javax.validation.constraints.NotNull
    String getParameterizedField(int count);
}

Actual Result

Generated interface:

public interface Foo {
    @javax.validation.constraints.NotNull
    String getSimpleField();

    // missing parameter here
    @javax.validation.constraints.NotNull
    String getParameterizedField();
}

This interface is unusable/broken. In addition to being unable to implement the method in terms of its parameters, this is not even valid for graphql kickstart:

Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is graphql.kickstart.tools.resolver.FieldResolverError: No method found as defined in schema :216 with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:

com.workforcesoftware.timesheetservice.generated.graphql.model.Foo.parameterizedField(~count)
com.workforcesoftware.timesheetservice.generated.graphql.model.Foo.getParameterizedField(~count)

Your Environment and Setup

  • graphql-java-codegen version: 5.2.0
  • Build tool: Gradle
  • Config:
    Excerpt of graphqlCodegen from build.gradle
  generateApis = true
  apiInterfaceStrategy = "INTERFACE_PER_OPERATION"
  apiRootInterfaceStrategy = "DO_NOT_GENERATE"
  apiReturnType = "graphql.execution.DataFetcherResult"
  generateDataFetchingEnvironmentArgumentInApis = true
  generateImmutableModels = true
  generateParameterizedFieldsResolvers = true
  fieldsWithResolvers = ["@customResolver"]
  fieldsWithoutResolvers = ["@noResolver"]
  typesAsInterfaces = ["@asInterface"]
@kobylynskyi kobylynskyi added bug Something isn't working scala Pull requests that update Scala code kotlin Pull requests that update Kotlin code labels Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kotlin Pull requests that update Kotlin code scala Pull requests that update Scala code
Projects
None yet
Development

No branches or pull requests

2 participants