You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/custom-scalars.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,22 +37,22 @@ gql_build|schema_builder:
37
37
type_overrides:
38
38
Date:
39
39
name: DateTime
40
-
import: 'package:my_date_library/date_time.dart'
40
+
import: "package:my_date_library/date_time.dart"
41
41
```
42
42
43
43
### Configure Custom Serializer
44
44
45
-
If our Dart type is not a Dart Data Type, we also need to [define a custom serializer](#create-a-custom-serializer) so that the generated classes can be correctly serialized & deserialized the data.
45
+
If our Dart type is not a Dart Data Type, we also need to [define a custom serializer](#create-a-custom-serializer) so that the generated classes can correctly serialize & deserialize the data.
46
46
47
-
Assuming we've created a [`DateSerializer`](#create-a-custom-serializer) for our custom `Date` scalar, we will need to include it in our `serializer_builder`.
47
+
Assuming we've created a [`DateSerializer`](#create-a-custom-serializer) for our custom `Date` scalar, we will need to include it in our `serializer_builder`:
48
48
49
49
```yaml
50
50
gql_build|serializer_builder:
51
51
enabled: true
52
52
options:
53
53
schema: my_project|lib/graphql/schema.graphql
54
54
custom_serializers:
55
-
- import: 'package:path/to/date_serializer.dart'
55
+
- import: "package:path/to/date_serializer.dart"
56
56
name: DateSerializer
57
57
```
58
58
@@ -92,7 +92,7 @@ targets:
92
92
options:
93
93
schema: my_project|lib/schema.graphql
94
94
custom_serializers:
95
-
- import: 'package:path/to/date_serializer.dart'
95
+
- import: "package:path/to/date_serializer.dart"
96
96
name: DateSerializer
97
97
98
98
ferry_generator|req_builder:
@@ -104,11 +104,11 @@ targets:
104
104
name: DateTime
105
105
```
106
106
107
-
## Create a Custom Serializer
107
+
## Creating a Custom Serializer
108
108
109
-
In order for us to instantiate our generated Dart Classes with data from our GraphQL server, we will need to create a custom `built_value` serializer for our custom `scalar` type.
109
+
For Ferry to create instances of our generated Dart classes, with data from a GraphQL server, we'll need to create a custom `built_value` serializer to handle the custom `scalar` type.
110
110
111
-
In this case, let's assume that our GraphQL server will return our `Date` scalar as an `int` timestamp.
111
+
Let's assume that our GraphQL server returns our `Date` scalar as an `int` timestamp. Then, a custom serializer can look like this:
112
112
113
113
```dart
114
114
import 'package:built_value/serializer.dart';
@@ -141,13 +141,13 @@ class DateSerializer implements PrimitiveSerializer<DateTime> {
141
141
}
142
142
```
143
143
144
-
And that's it! Now when we run our `pub run build_runner build` command, ferry's generators will automatically override our GraphQL `Date` scalar with the Dart `DateTime` type and use our `DateSerializer` to serialize & deserialize data.
144
+
And that's it! Now when we run our `pub run build_runner build` command, Ferry's generators will automatically override our GraphQL `Date` scalar with the Dart `DateTime` type and use our `DateSerializer` to serialize & deserialize data.
145
145
146
146
### Using `StructuredSerializer`s
147
147
148
148
We've implemented the above `DateSerializer` using the `PrimitiveSerializer` from `built_value`. However, if we were building a serializer for a non-primitive Dart type, we'd probably want to use the `StructuredSerializer` instead.
149
149
150
-
Since `built_value` doesn't use standard Json by default, rather than implementing `StructuredSerializer` directly, we may prefer to extend the `JsonSerializer` from `gql_code_builder`. For example, here's a serializer for the `Operation` type from `gql_exec` that ferry's generaters use internally.
150
+
Since `built_value` doesn't use standard Json by default, rather than implementing `StructuredSerializer` directly, we may prefer to extend the `JsonSerializer` from `gql_code_builder`. For example, here's a serializer for the `Operation` type from `gql_exec` that Ferry's generators use internally.
Copy file name to clipboardExpand all lines: docs/customization.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ class CacheTypedLink extends TypedLink {
41
41
42
42
Not all links need to resolve the request directly. Some links simply modify the request or response stream by calling the `forward()` callback on the `request()` method. This defers resolution of the request to the next link in the chain.
43
43
44
-
For example, ferry uses the following link to automatically add "___typename_" fields to each node of the GraphQL operation.
44
+
For example, ferry uses the following link to automatically add "_\_\_typename_" fields to each node of the GraphQL operation.
45
45
46
46
```dart
47
47
import 'dart:async';
@@ -81,7 +81,7 @@ class AddTypenameTypedLink extends TypedLink {
81
81
82
82
TypedLinks can be chained together using the `TypedLink.from()` method.
83
83
84
-
The following will create a link that adds "___typename_" fields to the request, then resolves the request from the Cache:
84
+
The following will create a link that adds "_\_\_typename_" fields to the request, then resolves the request from the Cache:
85
85
86
86
```dart
87
87
final myTypedLink = TypedLink.from([
@@ -96,8 +96,6 @@ You can then use this link to execute requests by listening to the Stream return
There are a few important guidelines that you should follow when chaining TypedLinks to ensure that your requests get executed correctly.
@@ -120,7 +118,7 @@ Instead, you can simply use the [underlying links that Client composes](https://
120
118
The ferry Client is created by composing these core TypedLinks.
121
119
122
120
-**Client**: The Ferry Client itself is a TypedLink, implemented by composing other core TypedLinks.
123
-
-**AddTypenameTypedLink**: Adds "___typename_" to each node of the operation.
121
+
-**AddTypenameTypedLink**: Adds "_\_\_typename_" to each node of the operation.
124
122
-**CacheTypedLink**: A terminating link that fetches the operation from the Cache.
125
123
-**FetchPolicyTypedLink**: A terminating link that resolves an operation from the Link or the Cache based on the request's `FetchPolicy`, possibly caching the response.
126
124
-**GqlTypedLink**: A terminating link which defers execution to the provided [gql_link](https://pub.dev/packages/gql_link). Any errors received by the [gql_link](https://pub.dev/packages/gql_link) are included in the `OperationResponse.linkException`.
0 commit comments