Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw a warning when we are using a deprecated field #374

Open
Kocal opened this issue Sep 5, 2018 · 9 comments
Open

Throw a warning when we are using a deprecated field #374

Kocal opened this issue Sep 5, 2018 · 9 comments

Comments

@Kocal
Copy link
Member

Kocal commented Sep 5, 2018

Hey,

I'm currently writing some docs on field deprecation (because I always forgot how to do it 🤣 ) 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?

@Kocal
Copy link
Member Author

Kocal commented Sep 5, 2018

Also, it's probably more related to GraphQL spec or to https://github.com/webonyx/graphql-php ... 😞

@mcg-web
Copy link
Member

mcg-web commented Sep 6, 2018

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.

@Kocal
Copy link
Member Author

Kocal commented Sep 6, 2018

Do you know where I can start?
I found how exceptions are handled and how to add a deprecationWarnings entry (I hope... 😅), but I can't find where I can check depreciation of query fields 🤔 Maybe in the Executor or Resolver folder?

@mcg-web
Copy link
Member

mcg-web commented Sep 7, 2018

This information should be present in the FieldDefinition. So using Schema extension with context and errorFormatter this could be done.

@Kocal
Copy link
Member Author

Kocal commented Sep 9, 2018

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?... 🤔

@mcg-web
Copy link
Member

mcg-web commented Sep 9, 2018

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.

@mcg-web
Copy link
Member

mcg-web commented Sep 12, 2018

#378 Should make this easier to implement

@Kocal
Copy link
Member Author

Kocal commented Sep 12, 2018

Mmmh maybe, I will take a look because I'm stuck at the moment 🤣

@Kocal
Copy link
Member Author

Kocal commented Dec 18, 2019

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants