Skip to content

Schema with multiple enum generates unusable data class #1114

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
choweiyuan opened this issue Apr 8, 2021 · 0 comments · Fixed by #1115
Closed

Schema with multiple enum generates unusable data class #1114

choweiyuan opened this issue Apr 8, 2021 · 0 comments · Fixed by #1115
Labels
type: bug Something isn't working

Comments

@choweiyuan
Copy link

Library Version
What version are you using?
4.0.0-rc1

Describe the bug
When I have a schema that contains multiple enums, then the client generates a class that does not work (due to ambiguity). If I comment out one of the enum imports it compiles fine.
Screenshot 2021-04-08 at 11 18 58

To Reproduce
Steps to reproduce the behavior. Please provide:

Kotlin code to generate schema:
Similar to this as I'm referencing local schema.graphql and query.graphql #1104

Schema

schema {
  query: Query
  mutation: Mutation
}

type BudgetDataView {
  provider: Provider!
  status: Status!
}

enum Provider {
  PROVIDER_A
  PROVIDER_B
  UNKNOWN
}

enum Status {
  FOUND
  INTERNAL_ERROR
  NOT_FOUND
}

type Query {
  fetchBudgetData: [BudgetDataView!]!
}

Query

query FetchBudgetDataQuery {
  fetchBudgetData {
    provider
    status
  }
}

Expected behavior
A working data class, for example:

package com.company.project.graphql.provider.fetchbudgetdataquery

import com.company.project.graphql.provider.BigDecimal
import com.company.project.graphql.provider.Instant
import com.company.project.graphql.provider.enums.Provider
// Don't need this? since enums.Provider is imported
//import com.company.project.graphql.provider.enums.Provider.__UNKNOWN_VALUE
import com.company.project.graphql.provider.enums.Status
// Don't need this either?  since enums.Status is imported.
//import com.company.project.graphql.provider.enums.Status.__UNKNOWN_VALUE
import kotlin.String

public data class BudgetDataView(
  public val provider: Provider = Provider.__UNKNOWN_VALUE,
  public val status: Status = Status.__UNKNOWN_VALUE,
)
@choweiyuan choweiyuan added the type: bug Something isn't working label Apr 8, 2021
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this issue Apr 8, 2021
We are providing default `__UNKNOWN_VALUE` value for enums. When generating references to this default value using kotlinpoet `MemberName` it was adding redundant explicit import of that enum value. If there were multiple fields asking for different enums then compilation would fail with multiple imports of `__UNKNOWN_VALUE`. Updated logic to use the explicit `TypeName` of the enum and `Name` of the constant.

Resolves: ExpediaGroup#1114
smyrick pushed a commit that referenced this issue Apr 14, 2021
We are providing default `__UNKNOWN_VALUE` value for enums. When generating references to this default value using kotlinpoet `MemberName` it was adding redundant explicit import of that enum value. If there were multiple fields asking for different enums then compilation would fail with multiple imports of `__UNKNOWN_VALUE`. Updated logic to use the explicit `TypeName` of the enum and `Name` of the constant.

Resolves: #1114
huehnerlady pushed a commit to huehnerlady/graphql-kotlin that referenced this issue Apr 27, 2021
We are providing default `__UNKNOWN_VALUE` value for enums. When generating references to this default value using kotlinpoet `MemberName` it was adding redundant explicit import of that enum value. If there were multiple fields asking for different enums then compilation would fail with multiple imports of `__UNKNOWN_VALUE`. Updated logic to use the explicit `TypeName` of the enum and `Name` of the constant.

Resolves: ExpediaGroup#1114
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Aug 5, 2022
We are providing default `__UNKNOWN_VALUE` value for enums. When generating references to this default value using kotlinpoet `MemberName` it was adding redundant explicit import of that enum value. If there were multiple fields asking for different enums then compilation would fail with multiple imports of `__UNKNOWN_VALUE`. Updated logic to use the explicit `TypeName` of the enum and `Name` of the constant.

Resolves: ExpediaGroup#1114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant