graphql-query-rewriter / core

Seamlessly turn breaking GraphQL changes into non-breaking changes
https://graphql-query-rewriter.github.io/core
MIT License
407 stars 15 forks source link

Resolve unknown fields #13

Closed runar-indico closed 4 years ago

runar-indico commented 4 years ago

We might have a strange setup with our servers, but after some googling, I found a few others who are in the same boat.

In short, we have multiple graphql-servers, and some of them are not updated very often since they are off-site. That means that the schemas might differ.

Clients however, are updated often. Currently, they need to check the server-version of the server that they are connected to and then only use queries that work with that version.

This turns into a few versioned queries, mostly just because we added some fields.

Updated clients cannot query for these new fields unless they know that the server is updated. Otherwise, they would get an error, like unknown field and the whole query drops.

I would really appreciate your help here, i could quite possibly contribute to the project.

Do you think it is possible to rewrite any query that is unknown to the current server? So that instead of the whole query returning an error, instead that single field would just return null.

I had a quick stab at your code, and it seems to be able to match on anything. However, would it be possible to only match on unknown fields? Is this a terrible idea?

chanind commented 4 years ago

So you'd want to be able to just silently drop any fields from the query that aren't in the graphql schema? I think it should be possible, but it would require a fair bit of work. Currently the rewriter doesn't know about the underlying graphQL schema at all, so you'd need to pass the current schema into the rewrite rule when you create it, and then have the rewrite rule check that every field it encounters exists in that schema. If you want to give that a try and open up a PR, definitely go for it!

runar-indico commented 4 years ago

Yes,I think this really is just a terrible idea. It would probably just lead to bad performance since it will in reality need to check every single field that it received to know if they are valid.

Anyway, thank you for your thoughts on the subject.