AnyCodable
values. For easier decoding and better type support you can, however, create custom GraphQLScalar
structures.
To create a custom scalar, you need to create a structure that conforms to the GraphQLScalar
protocol.
It doesn’t matter where you implement the conformance as long as it’s in the same project as the generated code.Because
GraphQLScalar
uses the Encodable
protocol to encode the value, you might need to customize how JSONEncoder
encodes the built-in value in case you are mapping a custom scalar to a built-in type. Depending on your target, you should either
JSONEncoder
as a paramater to the URLRequest.query
method,encoder
to FetchExchange
encoder
in GraphQLWebSocketConfiguration
.Don’t forget to add your scalar mapping to code generator options!