From 684136f5003cee8b1903f4715b2c65e6492a0c2d Mon Sep 17 00:00:00 2001 From: Florian Harr Date: Fri, 12 Jan 2024 10:44:26 -0500 Subject: [PATCH 1/3] Adding vars_create_factories option to graphql_builder --- packages/ferry_generator/lib/graphql_builder.dart | 3 ++- packages/ferry_generator/lib/src/utils/config.dart | 3 +++ packages/ferry_generator/pubspec.yaml | 2 +- packages/ferry_test_graphql2/build.yaml | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/ferry_generator/lib/graphql_builder.dart b/packages/ferry_generator/lib/graphql_builder.dart index 594299ab..08b582f4 100644 --- a/packages/ferry_generator/lib/graphql_builder.dart +++ b/packages/ferry_generator/lib/graphql_builder.dart @@ -115,7 +115,8 @@ class GraphqlBuilder implements Builder { p.basename(generatedFilePath(buildStep.inputId, varExtension)), config.typeOverrides, varAllocator, - triStateValueConfig), + triStateValueConfig, + config.shouldGenerateVarsCreateFactories), reqExtension: buildReqLibrary( doc, p.basename(generatedFilePath(buildStep.inputId, reqExtension)), diff --git a/packages/ferry_generator/lib/src/utils/config.dart b/packages/ferry_generator/lib/src/utils/config.dart index 8c09d99f..21f101d7 100644 --- a/packages/ferry_generator/lib/src/utils/config.dart +++ b/packages/ferry_generator/lib/src/utils/config.dart @@ -15,6 +15,7 @@ class BuilderConfig { final List? schemaIds; final bool shouldAddTypenames; final bool shouldGeneratePossibleTypes; + final bool shouldGenerateVarsCreateFactories; final Map typeOverrides; final Set customSerializers; final EnumFallbackConfig enumFallbackConfig; @@ -33,6 +34,8 @@ class BuilderConfig { ?.map((dynamic schema) => AssetId.parse(schema as String)) .toList(), shouldAddTypenames = config['add_typenames'] ?? true, + shouldGenerateVarsCreateFactories = + config['vars_create_factories'] ?? false, typeOverrides = _getTypeOverrides(config['type_overrides']), shouldGeneratePossibleTypes = config['generate_possible_types_map'] ?? true, diff --git a/packages/ferry_generator/pubspec.yaml b/packages/ferry_generator/pubspec.yaml index d5c9ae9d..e8a1b68f 100644 --- a/packages/ferry_generator/pubspec.yaml +++ b/packages/ferry_generator/pubspec.yaml @@ -12,7 +12,7 @@ topics: - codegen dependencies: gql: '>=0.14.0 <2.0.0' - gql_code_builder: ^0.9.1+1 + gql_code_builder: ^0.9.2 gql_tristate_value: ^1.0.0 built_collection: ^5.0.0 code_builder: ^4.3.0 diff --git a/packages/ferry_test_graphql2/build.yaml b/packages/ferry_test_graphql2/build.yaml index 3f757e9b..bc470526 100644 --- a/packages/ferry_test_graphql2/build.yaml +++ b/packages/ferry_test_graphql2/build.yaml @@ -6,6 +6,7 @@ targets: options: schema: ferry_test_graphql2|lib/schema/schema.graphql tristate_optionals: false + vars_create_factories: false data_class_config: reuse_fragments: true data_to_json: type_safe From e573084a9ca46828c86581539ebb3c9cbbe2de9a Mon Sep 17 00:00:00 2001 From: Florian Harr Date: Fri, 12 Jan 2024 10:54:34 -0500 Subject: [PATCH 2/3] feat(vars-builder-generator): Adding documentation for new codegen options --- docs/codegen.md | 4 ++++ packages/ferry_generator/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/codegen.md b/docs/codegen.md index 676d95be..fd5beff2 100644 --- a/docs/codegen.md +++ b/docs/codegen.md @@ -210,6 +210,10 @@ Supported keys are `when` and `maybeWhen`, and the values are booleans indicatin generation of the extension method not. By default, both are disabled. +`tristate_optionals`: \[bool\] Whether to use tristate optionals for nullable variables and input types. A Value class is used to represent the three possible states: absence of a value, presence of a value that is null, and presence of a non-null value. This class is used by the generated code for GraphQL variables and input types that are nullable in order to distinguish between the absence of a value and the presence of a null value, typically used for "update" Mutations. Defaults to false. + +`vars_create_factories`: \[bool\] Whether to generate an additional factory constructor for the variables class. In contrast to the `built_value` builders, this factory constructor respects nullability for it's parameters. Defaults to false. + Example: ```yaml diff --git a/packages/ferry_generator/pubspec.yaml b/packages/ferry_generator/pubspec.yaml index e8a1b68f..90b08b82 100644 --- a/packages/ferry_generator/pubspec.yaml +++ b/packages/ferry_generator/pubspec.yaml @@ -12,7 +12,7 @@ topics: - codegen dependencies: gql: '>=0.14.0 <2.0.0' - gql_code_builder: ^0.9.2 + gql_code_builder: ^0.10.0 gql_tristate_value: ^1.0.0 built_collection: ^5.0.0 code_builder: ^4.3.0 From fc92c792d4e9c9f2ddc29c1de04972dc63781b98 Mon Sep 17 00:00:00 2001 From: Florian Harr Date: Tue, 16 Jan 2024 13:39:14 -0500 Subject: [PATCH 3/3] feat(vars-builder-generator): Adding gql_code_builder vars builder dep --- packages/ferry_test_graphql2/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ferry_test_graphql2/pubspec.yaml b/packages/ferry_test_graphql2/pubspec.yaml index c6842899..2f0387c6 100644 --- a/packages/ferry_test_graphql2/pubspec.yaml +++ b/packages/ferry_test_graphql2/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: ferry_exec: ^0.5.0-dev.0+1 built_value: ^8.0.4 built_collection: ^5.0.0 - gql_code_builder: ^0.9.0 + gql_code_builder: ^0.10.0 dev_dependencies: test: ^1.16.8 build_runner: ^2.0.2