|
| 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. |
0 commit comments