Skip to content

Commit e393321

Browse files
docs: Adds readme section about coders
1 parent 54b7287 commit e393321

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,25 @@ let app = Application(
127127
```
128128

129129
The example above follows Hummingbird best practices when it uses a separate router for HTTP and WebSocket requests. For more details, see the [Hummingbird WebSocket documentation](https://docs.hummingbird.codes/2.0/documentation/hummingbird/websocketserverupgrade#Overview).
130+
131+
### Custom Encoding/Decoding
132+
133+
You can set custom encoders and decoders using the `Config.coders` argument:
134+
135+
```swift
136+
// Configure custom JSON encoder
137+
let graphQLJSONEncoder = GraphQLJSONEncoder()
138+
graphQLJSONEncoder.dateEncodingStrategy = .millisecondsSince1970
139+
140+
// Inject it using the `config.coders` argument
141+
router.graphql(
142+
schema: schema,
143+
config: .init(
144+
coders: .init(graphQLJSONEncoder: graphQLJSONEncoder)
145+
)
146+
) { _, _ in
147+
GraphQLContext()
148+
}
149+
```
150+
151+
Like [Hummingbird](https://docs.hummingbird.codes/2.0/documentation/hummingbird/responseencoding#Date-encoding), all default GraphQL encoders and decoders use the standard settings with ISO8601 date formatting.

0 commit comments

Comments
 (0)