graphql-kit icon indicating copy to clipboard operation
graphql-kit copied to clipboard

Add custom encoders support for router

Open maximkrouk opened this issue 3 years ago • 2 comments
trafficstars

I couldn't reproduce the behavior in tests, but responses may be encoded in the wrong order because JSONEncoder uses a Dictionary under the hood, but GraphQLJSONEncoder uses OrderedDictionary and always encodes GraphQLResult correctly.

Btw the implementation requires a bit higher version of GraphQL than was specified in Package.resolved

maximkrouk avatar Apr 15 '22 01:04 maximkrouk

To encode a response with a different encoder, you can register one the same way you would register one with Vapor. For incoming decoding, Graphiti 1.0.0 adds native support for custom decoders. As mentioned in #15 the underlying Graphiti packages has support for custom encoders. So, in my opinion, writing an additional wrapper around isn't useful enough. Do you think the same functionality could be achieved with the graphiti-1.0.0 branch instead?

alexsteinerde avatar Apr 20 '22 04:04 alexsteinerde

Seems like it cannot be achieved with Graphiti, at least my implementation encodes GraphQLResult to a specific Vapor type. The problem is that currently, you can only override the encoder for a specific mediatype globally, I couldn't find another way to override it only for GQL routes.

maximkrouk avatar Apr 22 '22 19:04 maximkrouk