4 ms·
I would personally caution against using an implicit rewriter like this. It is implicit in the sense once you change your schema, there's no documentation abou
by epidemian 7y ago
I would personally caution against using an implicit rewriter like this. It is implicit in the sense once you change your schema, there'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.
Instead of that, i'd personally recommend either sticking with your old schema if the change is as superfluous as the one mentioned on the project'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:
query {
user: userByIdV2(id: 123) {
...
}
}
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 :)
[1] Like Intellij IDEA's graphql plugin https://plugins.jetbrains.com/plugin/8097-js-graphql https://plugins.jetbrains.com/plugin/8097-js-graphql
[2] https://github.com/graphql/graphiql https://github.com/graphql/graphiql
- grrowl 7y agoI'd reckon the vast majority of real-world use of GraphQL is bog-standard web-api apps. With this, you could deploy a single schema changeset which updates the server, client, and middleware; then remove the middleware in a week once the web client has been guaranteed to have been refreshed or reloaded. Best of both worlds really.
- chanind 7y agoI wouldn't necessarily recommend using query rewriting for public graphql apis, but for internal apis or private apis to power mobile apps or web apps it should be fine. Just make sure you add tests for the old queries to ensure they keep working. Once you see the deprecated queries stop being used as users update their clients you can drop the rewriting entirely too.
- epidemian 7y agoThat seems like a good approach for those cases, yeah :) I guess the difference then boils down to whether you're OK with having a bunch of deprecates stuff in your schema (you can also remove those fields once they are not used anymore) and some "V2", "V3", etc in your field names, or your prefer having a more pristine schema but paying some price of discoverability and tooling support for those deprecated features.