graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

Better support for deprecation (and other) directives

Open modruo opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

While exploring the mesh for composing a public facing gateway composed of multiple sources, one important aspect is the ability to deprecate operations in the mesh to facilitate seamless transitions in the public facing shape. Some sources like the JSON Schema have limited support to add deprecation(no way to specify the reason) on the mesh level, while others like the graphql source requires adding the deprecation on the source itself, which may not necessarily suit all situations. Perhaps a more generic way to add deprecation (and possibly other) directives on a field level would be a better way to solve this?

Describe the solution you'd like

A new transform that could allow adding any custom directive annotations on a field. Perhaps something like

transforms:
  - fieldDirective:
      - typeName: Foo
        fieldName: bar
        directive: @deprecated(reason: "lorem ipsum")

Describe alternatives you've considered

If a generic directive transform is undesirable for any reason, a simpler, deprecation-specific transform would also work.

transforms:
  - deprecateField:
      - typeName: Foo
        fieldName: bar
        reason: lorem ipsum

Additional context

The JSON Schema field deprecation also breaks if you use something like the hoistField transform to alter the original operation field.

modruo avatar Aug 06 '24 14:08 modruo

You can use "additionalTypeDefs" to add extra directives.

additionalTypeDefs:
      |
        extend type Foo {
             bar:Bar @deprecated
        }

ardatan avatar Aug 06 '24 15:08 ardatan

Thank you, @ardatan! One question, though - would this replace any previous directives already in place?

modruo avatar Aug 06 '24 16:08 modruo

Update: it doesn't seem to work - mesh complains about redefining a field that already exists.

🕸️  Mesh 💥 Error: Field "Foo.bar" already exists in the schema. It cannot also be defined in this type extension.  

modruo avatar Aug 06 '24 16:08 modruo

@modruo If you remove the extend it will work

paales avatar Nov 18 '24 12:11 paales