Skip to content

customTypeMapping, generateExtensionFieldsResolvers and Extension Fields produce invalid parameter names #964

@martinlau

Description

@martinlau

Issue Description

When using customTypeMapping and generateExtensionFieldsResolvers to reference objects defined outside of the GraphQL Schema, for example:

  "customTypesMapping": {
    "External": "com.github.martinlau.external.model.External"
  },
  "generateExtensionFieldsResolvers": true

Combined with extension fields on existing types:

type External {
    name: String!
}

extend type External {
    age: Int!
}

Resolver classes are generated with parameter names based on the mapped value, rather than the original (non-qualified) value:

    fun age(com.github.martinlau.external.model.External: com.github.martinlau.external.model.External): Int

(Kotlin above - same issue arises with Java)

Steps to Reproduce

Refer to https://github.com/martinlau/graphql-codegen

Expected Result

Resolvers should be generated with a name based on the original type, rather than the fully qualified mapped type

    fun age(external: com.github.martinlau.external.model.External): Int

Actual Result

Resolvers are generated with a name based on the fully qualified mapped type.

    fun age(com.github.martinlau.external.model.External: com.github.martinlau.external.model.External): Int

See https://github.com/martinlau/graphql-codegen/blob/main/target/generated-sources/graphql/com/github/martinlau/graphql/resolver/ExternalResolver.kt for the full example

Your Environment and Setup

  • graphql-java-codegen version: 5.4.0
  • Build tool: Maven
  • Mapping Config:
<configuration>
  <graphqlSchemas>
    <rootDir>${project.basedir}/src/main/resources/graphql</rootDir>
    <excludedFiles>
      <excludedFile>models.graphqls</excludedFile>
    </excludedFiles>
  </graphqlSchemas>
  <configurationFiles>
    <configurationFile>${project.basedir}/src/build/graphql-codegen.json</configurationFile>
  </configurationFiles>
  <outputDir>${project.build.directory}/generated-sources/graphql</outputDir>
</configuration>

And

{
  "apiPackageName": "com.github.martinlau.graphql.resolver",
  "apiRootInterfaceStrategy": "DO_NOT_GENERATE",
  "customTypesMapping": {
    "External": "com.github.martinlau.external.model.External"
  },
  "generateApisWithThrowsException": false,
  "generateBuilder": false,
  "generateDataFetchingEnvironmentArgumentInApis": false,
  "generateExtensionFieldsResolvers": true,
  "generateImmutableModels": true,
  "generateModelsForRootTypes": false,
  "generatedLanguage": "KOTLIN",
  "modelPackageName": "com.github.martinlau.graphql.model",
  "packageName": "com.github.martinlau.graphql"
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions