TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

GraphQL Query Rewriter

65 pointsby chanindalmost 6 years ago

3 comments

epidemianalmost 6 years ago
I would personally caution against using an implicit rewriter like this. It is implicit in the sense once you change your schema, there&#x27;s no documentation about the deprecated queries that are still supported. Yes, old queries will still work, but people who stumble up on them will be very confused as to why they are working, since the schema will say otherwise. Tools like IDE auto-completion for queries[1] or the graphical interface GraphiQL[2] will also ignore these rewrite capabilities and so will not help with writing, editing or running the old-but-still-supported rewritten queries.<p>Instead of that, i&#x27;d personally recommend either sticking with your old schema if the change is as superfluous as the one mentioned on the project&#x27;s README (changing the type of the `userById(id)` field parameter from `String!` to `ID!`), or shamelessly embracing versioning your fields. In the case example case mentioned on the README, that could mean adding a @deprecated directive on the `userById(id: String!)` field, and then adding a new `userByIdV2(id: ID!)`. Users of the new field can alias it on to a friendlier versionless name, like:<p><pre><code> query { user: userByIdV2(id: 123) { ... } } </code></pre> This way, the changes on the schema are much more explicit: users can still use tools like GraphiQL or schema-aware text editor plugins to write their queries, while receiving feedback about their use of deprecated fields, and what they can do about them :)<p>[1] Like Intellij IDEA&#x27;s graphql plugin <a href="https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;8097-js-graphql" rel="nofollow">https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;8097-js-graphql</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;graphql&#x2F;graphiql" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;graphql&#x2F;graphiql</a>
评论 #20020673 未加载
评论 #20020594 未加载
revskillalmost 6 years ago
What i don&#x27;t like about Graphql is that it enable stringly type query. Why not enforcing JSON instead ?<p>Stringly type is too hard to be manipulated.
评论 #20020365 未加载
评论 #20020719 未加载
评论 #20020060 未加载
miguelolleralmost 6 years ago
I was originally skeptical as GraphQL already comes with the `deprecated` directive for this use case and it’s recommended for API evolution. Was actually delighted to see that this can let you make changes to your schema transparently without breaking clients!
评论 #20018091 未加载