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

feat(vars-builder-generator): Adding vars_create_factories to ferry_generator|graphql_builder #565

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/ferry_generator/lib/graphql_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
3 changes: 3 additions & 0 deletions packages/ferry_generator/lib/src/utils/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BuilderConfig {
final List<AssetId>? schemaIds;
final bool shouldAddTypenames;
final bool shouldGeneratePossibleTypes;
final bool shouldGenerateVarsCreateFactories;
final Map<String, Reference> typeOverrides;
final Set<Reference> customSerializers;
final EnumFallbackConfig enumFallbackConfig;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ferry_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.10.0
gql_tristate_value: ^1.0.0
built_collection: ^5.0.0
code_builder: ^4.3.0
Expand Down
1 change: 1 addition & 0 deletions packages/ferry_test_graphql2/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ferry_test_graphql2/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down