Ferry graphql dart types generator does not work with ENUM

686 views Asked by At

I am trying to generate dart types from my schema.graphql file described in ferry doc.

https://ferrygraphql.com/docs/codegen

I get this error while building the graphql code

 flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 543ms

[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 7.6s

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 890ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 4.5s elapsed, 4/5 actions completed.
[INFO] Generating SDK summary completed, took 3.5s

[WARNING] gql_build:serializer_builder on lib/$lib$:
Your current `analyzer` version may not fully support your current SDK version.

Analyzer language version: 2.14.0
SDK language version: 2.16.0

Please update to the latest `analyzer` version (3.3.1) by running
`flutter packages upgrade`.

If you are not getting the latest version by running the above command, you
can try adding a constraint like the following to your pubspec to start
diagnosing why you can't get the latest version:

dev_dependencies:
  analyzer: ^3.3.1

[INFO] 6.0s elapsed, 4/5 actions completed.
[INFO] 7.1s elapsed, 5/9 actions completed.
[INFO] 8.1s elapsed, 5/9 actions completed.
[INFO] 9.3s elapsed, 5/9 actions completed.
[INFO] 16.4s elapsed, 5/9 actions completed.
[INFO] 18.3s elapsed, 5/9 actions completed.
[SEVERE] built_value_generator:built_value on lib/schema.schema.gql.dart:
Error in BuiltValueGenerator for /ferry_codegen_test/lib/schema.schema.gql.dart.
Please make the following changes to use built_value serialization:

1. Declare GENUM_AQUATIC_ACTIVETYPE.serializer as: static Serializer<GENUM_AQUATIC_ACTIVETYPE> get serializer => _$gENUMAQUATICACTIVETYPESerializer; got static Serializer<GENUM_AQUATIC_ACTIVETYPE> get serializer => _$genumAquaticActivetypeSerializer;
2. Declare GENUM_AQUATIC_BREEDINGLEVEL.serializer as: static Serializer<GENUM_AQUATIC_BREEDINGLEVEL> get serializer => _$gENUMAQUATICBREEDINGLEVELSerializer; got static Serializer<GENUM_AQUATIC_BREEDINGLEVEL> get serializer => _$genumAquaticBreedinglevelSerializer;
3. Declare GENUM_AQUATIC_CARELEVEL.serializer as: static Serializer<GENUM_AQUATIC_CARELEVEL> get serializer => _$gENUMAQUATICCARELEVELSerializer; got static Serializer<GENUM_AQUATIC_CARELEVEL> get serializer => _$genumAquaticCarelevelSerializer;
4. Declare GENUM_AQUATIC_DIET.serializer as: static Serializer<GENUM_AQUATIC_DIET> get serializer => _$gENUMAQUATICDIETSerializer; got static Serializer<GENUM_AQUATIC_DIET> get serializer => _$genumAquaticDietSerializer;
5. Declare GENUM_AQUATIC_SCHOOLING.serializer as: static Serializer<GENUM_AQUATIC_SCHOOLING> get serializer => _$gENUMAQUATICSCHOOLINGSerializer; got static Serializer<GENUM_AQUATIC_SCHOOLING> get serializer => _$genumAquaticSchoolingSerializer;
6. Declare GENUM_AQUATIC_SWIMLEVEL.serializer as: static Serializer<GENUM_AQUATIC_SWIMLEVEL> get serializer => _$gENUMAQUATICSWIMLEVELSerializer; got static Serializer<GENUM_AQUATIC_SWIMLEVEL> get serializer => _$genumAquaticSwimlevelSerializer;
7. Declare GENUM_AQUATIC_TEMPERAMENT.serializer as: static Serializer<GENUM_AQUATIC_TEMPERAMENT> get serializer => _$gENUMAQUATICTEMPERAMENTSerializer; got static Serializer<GENUM_AQUATIC_TEMPERAMENT> get serializer => _$genumAquaticTemperamentSerializer;
8. Declare GENUM_AQUATIC_TEMPUNIT.serializer as: static Serializer<GENUM_AQUATIC_TEMPUNIT> get serializer => _$gENUMAQUATICTEMPUNITSerializer; got static Serializer<GENUM_AQUATIC_TEMPUNIT> get serializer => _$genumAquaticTempunitSerializer;
9. Declare GENUM_AQUATIC_TYPE.serializer as: static Serializer<GENUM_AQUATIC_TYPE> get serializer => _$gENUMAQUATICTYPESerializer; got static Serializer<GENUM_AQUATIC_TYPE> get serializer => _$genumAquaticTypeSerializer;
10. Declare GENUM_BIT_TYPE.serializer as: static Serializer<GENUM_BIT_TYPE> get serializer => _$gENUMBITTYPESerializer; got static Serializer<GENUM_BIT_TYPE> get serializer => _$genumBitTypeSerializer;
11. Declare GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE.serializer as: static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE> get serializer => _$gENUMCOMPONENTMEDIAMEDIAUPLOADMEDIATYPESerializer; got static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE> get serializer => _$genumComponentmediamediauploadMediatypeSerializer;
12. Declare GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS.serializer as: static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS> get serializer => _$gENUMCOMPONENTMEDIAMEDIAUPLOADSTATUSSerializer; got static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS> get serializer => _$genumComponentmediamediauploadStatusSerializer;
13. Declare GENUM_CONTRIBUTE_TYPE.serializer as: static Serializer<GENUM_CONTRIBUTE_TYPE> get serializer => _$gENUMCONTRIBUTETYPESerializer; got static Serializer<GENUM_CONTRIBUTE_TYPE> get serializer => _$genumContributeTypeSerializer;
14. Declare GENUM_FUNFACT_CATEGORY.serializer as: static Serializer<GENUM_FUNFACT_CATEGORY> get serializer => _$gENUMFUNFACTCATEGORYSerializer; got static Serializer<GENUM_FUNFACT_CATEGORY> get serializer => _$genumFunfactCategorySerializer;
15. Declare GENUM_FUNFACT_STATUS.serializer as: static Serializer<GENUM_FUNFACT_STATUS> get serializer => _$gENUMFUNFACTSTATUSSerializer; got static Serializer<GENUM_FUNFACT_STATUS> get serializer => _$genumFunfactStatusSerializer;
16. Declare GENUM_PRODUCT_CATEGORY.serializer as: static Serializer<GENUM_PRODUCT_CATEGORY> get serializer => _$gENUMPRODUCTCATEGORYSerializer; got static Serializer<GENUM_PRODUCT_CATEGORY> get serializer => _$genumProductCategorySerializer;
17. Declare GENUM_PRODUCT_STATUS.serializer as: static Serializer<GENUM_PRODUCT_STATUS> get serializer => _$gENUMPRODUCTSTATUSSerializer; got static Serializer<GENUM_PRODUCT_STATUS> get serializer => _$genumProductStatusSerializer;
[INFO] 21.9s elapsed, 5/9 actions completed.
[WARNING] No actions completed for 15.9s, waiting on:
  - built_value_generator:built_value on lib/main.dart
  - built_value_generator:built_value on test/widget_test.dart
  - built_value_generator:built_value on lib/schema.schema.gql.dart
  - built_value_generator:built_value on lib/serializers.gql.dart

[INFO] 22.9s elapsed, 9/10 actions completed.
[INFO] Running build completed, took 23.0s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 33ms

[SEVERE] Failed after 23.0s
pub finished with exit code 1

I think ferry generator having issues with graphql ENUM types

Can anyone help me to resolve the issue?

Thanks

reproduce repo https://github.com/aquadesk/ferry_codegen_test

pubspec.yaml

name: ferry_codegen_test
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev


version: 1.0.0+1

environment:
  sdk: ">=2.16.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  cupertino_icons: ^1.0.2
  ferry: ^0.10.4

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^1.0.0
  ferry_generator: ^0.4.4
  build_runner: ^2.1.7

flutter:

  uses-material-design: true

I think the schema.graphql file is too big to post here. so I will put a part of it that seems to be an issue.


enum ENUM_AQUATIC_TEMPUNIT {
  F
  C
}
enum ENUM_AQUATIC_TYPE {
  fish
  frog
}
enum ENUM_BIT_TYPE {
  youtube
  instagram
  blog
  site
  commerce
  facebook
}


1

There are 1 answers

0
helloworld331 On BEST ANSWER

I found the fix here

https://github.com/gql-dart/gql/pull/225

Pull down this repo gql in your local and checkout the commit 14e8d3602ebb93f14a2285247c80a9b70b1eb71b which is this change https://github.com/gql-dart/gql/commit/14e8d3602ebb93f14a2285247c80a9b70b1eb71b

and put this at the end of your pubspec.yaml


dependency_overrides:
  gql_code_builder:
    path: ../../../gql/codegen/gql_code_builder