Hotchocolate: Automatically include @deprecated directive where ObsoleteAttribute is used

Created on 16 May 2019  路  11Comments  路  Source: ChilliCream/hotchocolate

Is your feature request related to a problem? Please describe.
When creating a code-first GraphQL schema, placing an ObsoleteAttribute on fields for a model/type/query require an explicit call to the IFieldDescriptor.DeprecationReason(). This can lead to a disconnect between the code I've written and the GraphQL model since I need to denote the deprecation in multiple locations.

Describe the solution you'd like
As part of schema generation, it would be great to look for attributes on fields (implicit or explicit) that use the ObsoleteAttribute and have a valid Message property value that conforms to the GraphQL spec. This would prevent the need to use both an ObsoleteAttribute and the DeprecationReason() method to denote a deprecated field.

Describe alternatives you've considered
I have not considered additional alternatives at this time.

Additional context
This is a feature that is supported by some ASP.NET Core Swagger implementations, and would be nice to include this as part of HotChocolate to provide additional support for code-first schema generation.

馃帀 enhancement

All 11 comments

I like your ideas :) we should do that. We should integrate that in the conventions.

Let us implement this for 9.1

The way we should do this is by having some kind of functionality in the conventions where the descriptors can ask the conventions for a depreciation reason. This way people can override out default convention and introduce their own attributes if they wish to.

Do you want to have a go at it?

So,

we should add this one to the naming conventions INamingConventions.

It does not really fit perfectly there but it sounds ok :)

Basically we would need to add a new method GetDepricationReason there that gets a MemberInfo and returns a String.

Would be more than happy to take a go at this! I would agree that, for now, INamingConventions will probably be the best spot to place this and then use the new method in the object creation similar to #715

So, have a go at this one... I will try finishing of the #715 this week. Thanks for your work on both of them!

This is closed as of merge #826. One addition I could see being made is a new GraphQLDeprecatedAttribute(string) that could be added, similar to the GraphQLDescriptionAttribute. Would be nice to have both "implicit" support from core attributes, as well as a HotChocolate specific method like descriptions have.

@willwolfram18 I agree with you. We should add this one. If you find the time create a pr and add this one.

Reopening issue and will get a PR together for a GraphQLDeprecated attribute 馃槃

Closed as of #843

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nigel-sampson picture nigel-sampson  路  5Comments

PascalSenn picture PascalSenn  路  5Comments

benmccallum picture benmccallum  路  5Comments

RohrerF picture RohrerF  路  3Comments

acelot picture acelot  路  4Comments