GraphQLBundle
GraphQLBundle copied to clipboard
Throw a warning when we are using a deprecated field
Hey,
I'm currently writing some docs on field deprecation (because I always forgot how to do it :rofl: ) and I just encountered a weird behavior.
When we mark a field a field as deprecated and we still use it in queries, it would be nice to see a warning, no?
Human:
type: object
config:
description:
fields:
faith:
deprecationReason: "We've lost faith in Humanity"
Query:
type: object
config:
fields:
humans: { type: "[Human]!" }
running query { humans { faith } } should returns something like that:
{
"data": {
"humans": [...]
},
"extension": {
"deprecationWarnings": [
{
"message": "The field is marked as deprecated",
"field": "humans.faith",
"reason": "We've lost faith in Humanity"
}
]
}
}
What do you think?
Also, it's probably more related to GraphQL spec or to https://github.com/webonyx/graphql-php ... :disappointed:
Hi @Kocal, It seems that GraphQL specs doesn't say nothing about this on query runtime. The only way to know if a field is deprecated is to use introspection query. Adding a custom deprecationWarnings entry in extensions can always be done since the specs leave the possibility to add whatever we want.
Do you know where I can start?
I found how exceptions are handled and how to add a deprecationWarnings entry (I hope... :sweat_smile:), but I can't find where I can check depreciation of query fields :thinking: Maybe in the Executor or Resolver folder?
This information should be present in the FieldDefinition. So using Schema extension with context and errorFormatter this could be done.
I'm probably missing something, but how can I have access to the parsed incoming GraphQL query in my schema extension?
In fact, I'm not sure I should use a schema extension, maybe an event would be more appropriate, no?... :thinking:
In your schema extension you should wrap all objects graphql resolver and use ResolveInfo to get the field query and if query fields are deprecated add them in a variable (an array on Dreprecated Schema Extension itself or using context?). I'm not sure if this is the best way but this can be done like that. A combination of different Events can maybe do the same thing in a cleaner way.
#378 Should make this easier to implement
Mmmh maybe, I will take a look because I'm stuck at the moment :rofl:
Hey @mcg-web, I really want to continue my work on #377 because I really think it's a must have to show a warning when querying a deprecated field.
I need to know if your advices are still up-to-date with the new versions or not? Thanks :)