graphql-kit / graphql-lodash

🛠 Data manipulation for GraphQL queries with lodash syntax
https://apis.guru/graphql-lodash/
MIT License
1.23k stars 48 forks source link

Server side usage - seems to be working well :-) #14

Closed anodynos closed 6 years ago

anodynos commented 6 years ago

Thanks for this library, it's really cool!

You mention this will break the contract and, most likely, will break all the GraphQL tooling you use but I don't really understand why - could you elaborate?

I've experimented a bit in a pet project and I have had no problems with it so far :-)

Regards

IvanGoncharov commented 6 years ago

You mention this will break the contract and, most likely, will break all the GraphQL tooling you use but I don't really understand why - could you elaborate?

If you apply @_ directive on a server-side it will break all the tooling that depend on a shape of response. For example, caching clients like Apollo or Relay. Also, it will break client-side code generation e.g. https://github.com/apollographql/apollo-cli#apollo-codegengenerate-output

anodynos commented 6 years ago

I'm no so experienced with graphql & apollo especially, so I'm not sure if I get it right.

What I did is to have two middlewares, applied first and last on the request on my express (NestJS actually). It goes like this:

I know this is not terribly performant, but for my pet project I don't care at all.

If all other middlewares execute in the middle, I guess they can still operate, cause lodash works at the start and end of the queue, almost as if it was running on the client. Isnt that right?

IvanGoncharov commented 6 years ago

@anodynos For server-side middleware yes. But if you try to do something complex on client-side it would fail.

anodynos commented 6 years ago

I don't understand - why will it fail on the client side?

IvanGoncharov commented 6 years ago

@anodynos If you using fetch or any simple client it will work as expected. But if you are doing complex transformations on client-side that depend on the shape of the response it will fail.