graphql-query-rewriter / core

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

Query Name Rewriter #15

Open irfanalef2060 opened 4 years ago

irfanalef2060 commented 4 years ago

First of all this is not an issue, I need a little bit of help.

I didn't find a rewriter for the query name.

Example: Let say we have query like this which is being used in many clients query query getUserById($id: String!) { userById(id: $id) { ... } }

I want to change my query to this query getCurrentUserByID($id: String!) { userById(id: $id) { ... } }

So I want that whenever client query getUserById, it should map to getCurrentUserByID. I think currently there is no option for query name. So is there any problem with writing a rewriter for query name? Have you tried this? Because I am thinking to write a query rewriter for this.

chanind commented 4 years ago

This was also requested in https://github.com/ef-eng/graphql-query-rewriter/pull/14. Currently there's no rewriter for this since you can deprecate the old field and make a new field with the new name using normal graphQL deprecationReason, but I think it's fine to add if it's something people want to use. As discussed in the existing PR, it will require changing some internals to make this rewriter possible.

irfanalef2060 commented 4 years ago

@chanind Thanks for the reply. I checked out the PR. I went through code as well of rewrite a response. I found out that its more related to work with rewriteScalarFieldToObjectField and NestFieldOutputsRewriter. To make it work FieldNameRewrite won't be straight away. I am trying to make it work with it. Any suggestions would be appreciated.

gregbty commented 4 years ago

@chanind did you already have something in mind for updating the rewriter? I could submit a pull request for it. I've created a version of the field name rewriter but the only thing missing is the ability to rewrite the response.

gregbty commented 4 years ago

See #20.

chanind commented 4 years ago

Thanks @gregbty! Sorry for the delay getting back on this! Just a minor naming nit on the PR and should be good to merge.