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

" Failed to generate type for <Union>" when an input has a union field #355

Closed
rrousselGit opened this issue Aug 16, 2024 · 2 comments
Closed

Comments

@rrousselGit
Copy link

Hello!

Consider:

type Foo {
  a: String!
}

type Bar {
  b: String!
}

union Union = Foo | Bar

input Input {
  input: Union!
}

extend type Mutation {
  example(input: Input!): String!
}

This fails with:

[SEVERE] graphql_codegen on lib/src/graphql/deployment.graphql:

Bad state: Failed to generate type for Union.
package:graphql_codegen/src/printer/base/property.dart 119:5  _printNamedTypeNode
package:graphql_codegen/src/printer/base/property.dart 52:12  _printTypeNode
package:graphql_codegen/src/printer/base/property.dart 39:10  printClassPropertyType
package:graphql_codegen/src/printer/base/input.dart 36:29     _printInputClasses.<fn>.<fn>
package:code_builder/src/specs/method.g.dart 649:33           _$ParameterBuilder.update
package:code_builder/src/specs/method.g.dart 398:32           new _$Parameter
package:graphql_codegen/src/printer/base/input.dart 34:21     _printInputClasses.<fn>
dart:core                                                     new List.from
package:built_collection/src/list/list_builder.dart 44:20     ListBuilder.replace
package:built_collection/src/list/list_builder.dart 20:45     new ListBuilder
package:graphql_codegen/src/printer/base/input.dart 32:29     _printInputClasses
package:graphql_codegen/src/printer/base/input.dart 15:5      printInputClasses
package:graphql_codegen/src/printer/printer.dart 23:20        printRootContext.<fn>
dart:core                                                     new List.of
package:graphql_codegen/src/printer/printer.dart 21:40        printRootContext
package:graphql_codegen/graphql_codegen.dart 27:10            _generateDocument
package:graphql_codegen/graphql_codegen.dart 118:10           generate
package:graphql_codegen/builder.dart 104:20                   GraphQLBuilder.build

It appears that _printNamedTypeNode does not handle Union types and throws because of it.

Copy link

👋 @rrousselGit
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@rrousselGit rrousselGit changed the title " Failed to generate type for <Union>" when an input as a union field " Failed to generate type for <Union>" when an input has a union field Aug 16, 2024
@rrousselGit
Copy link
Author

Looks like the schema was invalid. Closing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant