Skip to content

Recursive Type Reuses Name for API and Model #1475

@MEnnabah

Description

@MEnnabah

Issue Description

When a type defines a field that requires schema mapping, graphql-java-codegen generates an API and a model of the same name, which breaks model interfaces return type.

Steps to Reproduce

The following is a sample type:

type FolderOutput {
    id: Int!
    name: String!
    path: String!
    children(depth: Int = 1): [Folder!]!
}

query {
    folderGet(id: Int!): FolderOutput!
}

Expected Result

The output is expected be a model (FolderOutput), and a concrete type is expected to implement the children API interface to resolve the children field.

package com.org.generated.api;

public interface FolderGetQuery {
    @QueryMapping
    com.org.generated.model.FolderOutput folderGet(@Argument int id);
}

Actual Result

The output is a an API, rather than a model.

package com.org.generated.api;

public interface FolderGetQuery {
    @QueryMapping
    com.org.generated.api.FolderOutput folderGet(@Argument int id);
}
package com.org.generated.api;

public interface FolderOutput {
    @SchemaMapping(typeName="FolderOutput")
    java.util.List<com.org.generated.api.FolderOutput> children(FolderOutput folderOutput, @Argument Integer depth);
}

Your Environment and Setup

  • graphql-java-codegen version: 5.9.0
  • Build tool: Gradle
  • Mapping Config: E.g.:
graphqlCodegen {
    outputDir = new File("$buildDir/generated/graphql")
    apiPackageName = "com.org.generated.api"
    modelPackageName = "com.org.generated.model"
    customTypesMapping = [
            DateTime: "java.time.OffsetDateTime",
            UUID    : "java.util.UUID",
            JSON    : "java.util.Map"
    ]
    apiNameSuffix = ""
    modelNameSuffix = ""
    typeResolverSuffix = ""
    generateApis = true
    generateApisWithThrowsException = false
    supportUnknownFields = false
    generateDataFetchingEnvironmentArgumentInApis = true
    generateAllMethodInProjection = false
    unknownFieldsPropertyName = "additionalFields"
    resolverArgumentAnnotations = ['org.springframework.graphql.data.method.annotation.Argument']
    parametrizedResolverAnnotations = ["org.springframework.graphql.data.method.annotation.SchemaMapping(typeName=\"{{TYPE_NAME}}\")"]
    customAnnotationsMapping = [
            '^Query\\.\\w+$'       : ['org.springframework.graphql.data.method.annotation.QueryMapping'],
            '^Mutation\\.\\w+$'    : ['org.springframework.graphql.data.method.annotation.MutationMapping'],
            '^Subscription\\.\\w+$': ['org.springframework.graphql.data.method.annotation.SubscriptionMapping'],
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions