Skip to content

Parameterized field getters in type interface are missing parameters #859

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

Closed
UselessPickles opened this issue Oct 21, 2021 · 4 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@UselessPickles
Copy link

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"]
@UselessPickles UselessPickles added the bug Something isn't working label Oct 21, 2021
@kobylynskyi kobylynskyi added the help-wanted Extra attention is needed label Dec 2, 2021
@kobylynskyi kobylynskyi self-assigned this Dec 3, 2021
@kobylynskyi kobylynskyi added this to the 5.4.0 milestone Dec 3, 2021
@kobylynskyi
Copy link
Owner

@UselessPickles thanks for a detailed explanation of the issue.
I've addressed it in #913. Could you please have a look and let me know that's what you were looking for?
Thank you for your patience as well. Last month was quite busy for me.

@kobylynskyi
Copy link
Owner

Java implementation is done in #913
Created a new ticket to address this issue in Scala and Kotlin: #939

@UselessPickles
Copy link
Author

@kobylynskyi Sorry for not responding earlier. I somehow missed the notification from Dec 2. I looked at the changes you committed, and based on the example generated interfaces for your tests, it looks like exactly what I was looking for. Thanks!

@kobylynskyi
Copy link
Owner

This feature will be released as part of 5.4.0 very soon. Stay tuned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants