Skip to content
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

Recursive Type Reuses Name for API and Model #1475

Open
MEnnabah opened this issue Mar 12, 2024 · 0 comments
Open

Recursive Type Reuses Name for API and Model #1475

MEnnabah opened this issue Mar 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MEnnabah
Copy link

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'],
    ]
}
@MEnnabah MEnnabah added the bug Something isn't working label Mar 12, 2024
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

1 participant