Query new field in GraphQL in backward compatible manner

Query new field in GraphQL in backward compatible manner


0

So there is this new field added to the server API that the client wants to use. But the client also still needs to work with the older installs of the server that don’t define that field yet.

Unfortunately when I just include the field, I get error that the field does not exist and only the error and no data.

I also tried introspecting whether the field exist, setting hasNewField variable and than doing newField @include(if: $hasNewField), but that still gives me error that newField does not exist, even if the hasNewField variable is false.

Is there any way to conditionally exclude the field or otherwise get the response with the field if it exists and without it if it doesn’t without needing two versions of the query?

The server is using Chilli Cream, but I would prefer a generic solution.

1 Answer
1


0

Field additions are non-breaking to a schema. Old clients don’t ask for them and new clients are free to request them. You don’t need to condition the presence of the field in your schema, just add it.

Field deletions (or renames) are potentially breaking and must be handled with much more care.



Leave a Reply

Your email address will not be published. Required fields are marked *