Skip to content

Parameterized field getters in type interface are missing parameters #859

@UselessPickles

Description

@UselessPickles

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"]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions