alexsteinerde / graphql-kit

Easy setup of a GraphQL server with Vapor. It uses the GraphQL implementation of Graphiti.
MIT License
99 stars 18 forks source link

Add custom encoders support for router #16

Open maximkrouk opened 2 years ago

maximkrouk commented 2 years ago

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

alexsteinerde commented 2 years ago

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?

maximkrouk commented 2 years ago

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.