Skip to content

Commit f562006

Browse files
Parablessaihaj
andauthored
Flutter freezed v4.0.0 (#47)
* feat(config): ✨ added patterns for granular configuration TypeNamePattern are used to configure the class and its factories whiles the FieldNamePattern is used to configure the parameters. New plugin-config interface * feat(config): 💥 refactored plugin-config to use Patterns Using tuples instead of Records, we sacrifice IDE auto-complete and bloated config for positional(poor IDE support) but compact config New interface * test(config): ✅ added config-value with some tests config-value provides some methods that parses the config and returns ready-to-consume values in the various blocks * refactor(core): 🔥 utils contains shared functions used across multiple domains applying DDD concepts: moved every function into its appropirate domain dropped support for customDecorators, FreezedFactoryBlockRepository class renamed to NodeRepository class, FreezedConfigValue class renamed to Config classs * refactor(core): ♻️ functional+composition over OOP+mutations The previous version mutated properties of the class to generated the output. This made it very difficult to write tests without running the whole plugin and good luck tracking bugs and wrong generated output. This rewrite used functions everywhere for everything. Being static methods, you can test each independently without having to create a full instance of the class. Using value objects eliminates the use of primitive values plus ensures that we have a valid value everytime. * fix(core logic): 🎨 fixed broken indentation * refactor(plugin): 🔥 refactoring, code cleanup and integration testing * feat: 🚀 ready for v4.0.0 * fix: 🚑 fixed issue with CI * fix: 🚑 fixed ESM & CJS integrity issue * fix: 🚑 minor fix * added changeset documentation * added missing url * minor fix * minor fix * docs(config): 🔥 removed fromJsonToJson config option fromJsonToJson will be implented in the next release * style: prettier: Co-authored-by: Saihajpreet Singh <[email protected]>
1 parent 296ce64 commit f562006

23 files changed

+5487
-2738
lines changed

.changeset/chatty-teachers-repeat.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
'@graphql-codegen/flutter-freezed': major
3+
---
4+
5+
# Configuring the plugin using patterns
6+
7+
## What has changed
8+
9+
The following type definitions have been removed:
10+
11+
- CustomDecorator = Record<string, DecoratorToFreezed>;
12+
13+
- DecoratorToFreezed
14+
- arguments?: string[];
15+
- applyOn: ApplyDecoratorOn[];
16+
- mapsToFreezedAs: '@Default' | '@deprecated' | 'final' | 'directive' | 'custom';
17+
18+
- FieldConfig
19+
- final?: boolean;
20+
- deprecated?: boolean;
21+
- defaultValue?: any;
22+
- customDecorators?: CustomDecorator;
23+
24+
- FreezedConfig
25+
- alwaysUseJsonKeyName?: boolean;
26+
- copyWith?: boolean;
27+
- customDecorators?: CustomDecorator;
28+
- defaultUnionConstructor?: boolean;
29+
- equal?: boolean;
30+
- fromJsonToJson?: boolean;
31+
- immutable?: boolean;
32+
- makeCollectionsUnmodifiable?: boolean;
33+
- mergeInputs?: string[];
34+
- mutableInputs?: boolean;
35+
- privateEmptyConstructor?: boolean;
36+
- unionKey?: string;
37+
- unionValueCase?: 'FreezedUnionCase.camel' | 'FreezedUnionCase.pascal';
38+
39+
- TypeSpecificFreezedConfig
40+
- deprecated?: boolean;
41+
- config?: FreezedConfig;
42+
- fields?: Record<string, FieldConfig>;
43+
44+
- FlutterFreezedPluginConfig:
45+
- fileName?: string;
46+
- globalFreezedConfig?: FreezedConfig
47+
- typeSpecificFreezedConfig?: Record<string, TypeSpecificFreezedConfig>;
48+
49+
## Why those type definitions were removed
50+
51+
The previous version allow you to configure GraphQL Types and its fields globally using the `globalFreezedConfig` and override the global configuration with specific ones of each GraphQL Type using the `typeSpecificFreezedConfig`.
52+
53+
This resulted in a bloated configuration file with duplicated configuration for the same options but for different cases.
54+
55+
To emphasize on the problem, consider the before and after configurations below:
56+
57+
Before:
58+
59+
```ts
60+
{
61+
globalFreezedConfig: {
62+
immutable: true,
63+
},
64+
typeSpecificFreezedConfig: {
65+
Starship: {
66+
deprecated: true,
67+
},
68+
Droid: {
69+
config: {
70+
immutable: false,
71+
},
72+
fields: {
73+
id: {
74+
deprecated: true,
75+
},
76+
},
77+
},
78+
},
79+
};
80+
```
81+
82+
After:
83+
84+
```ts
85+
86+
{
87+
immutable: TypeNamePattern.forAllTypeNamesExcludeTypeNames([Droid]),
88+
deprecated: [
89+
[TypeNamePattern.forTypeNames([Starship]), ['default_factory']],
90+
[FieldNamePattern.forFieldNamesOfTypeName([[Droid, id]]), ['default_factory_parameter']],
91+
],
92+
}
93+
```
94+
95+
The 2 configurations above do the same thing, the later being more compact, flexible and readable than the former.
96+
97+
## How to update your existing configuration
98+
99+
First understand the [usage of the Patterns](https://the-guild.dev/graphql/codegen/docs/guides/flutter-freezed#configuring-the-plugin), then create a new config file(preferably a typescript file: previous version of the code generator used a YAML file).
100+
And implement the new configuration one by one inspecting the generated output.
101+
102+
> Please avoid migrating all your configuration at once. Doing that means you wont be able to inspect the generated output and ensure that the expected results are produced.

packages/plugins/dart/flutter-freezed/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"@graphql-codegen/schema-ast": "^2.5.0",
1818
"@graphql-codegen/visitor-plugin-common": "2.13.1",
1919
"auto-bind": "~4.0.0",
20-
"tslib": "~2.4.0",
21-
"change-case-all": "1.0.15"
20+
"change-case-all": "1.0.15",
21+
"tslib": "~2.4.0"
2222
},
2323
"peerDependencies": {
2424
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"

0 commit comments

Comments
 (0)