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

Ability to add directives on extended enum values

Open BoD opened this issue 3 years ago • 3 comments

This is currently disallowed by the specification:

enum Foo {
  bar
  baz
}

extend enum Foo {
  baz @myDirective
}

From https://spec.graphql.org/draft/#sec-Enum-Extensions.Type-Validation:

  1. All values of an Enum type extension must not already be a value of the original Enum.

Our immediate use-case is that we generate code on the client side and would like to allow renaming certain enum values (in case their name is a reserved keyword, or clashes with other fields in the generated code).

Has this ever come up and would it make sense to allow it?

BoD avatar May 30 '22 15:05 BoD

Interesting! You're not attempting to add the enum, but instead to add the directive to it, and there's no way to tell the system that's your intent. I recommend that you add a 10 minute topic to an upcoming GraphQL Working Group to discuss it, e.g.: https://github.com/graphql/graphql-wg/blob/main/agendas/2022/2022-07-07.md

Let me know if you need any guidance, or if you cannot attend WG and would like me to represent it on your behalf.

benjie avatar May 30 '22 16:05 benjie

This hits on a potentially deeper topic, which is that you sometimes want to merge schema definitions and schema extensions only give us a subset of that merging property (for instance, you can't add an argument to an existing field via schema extensions). The tricky bit is that sometimes you want to merge via a union operation and sometimes via an intersect. Extend implies union, and perhaps we want to just allow deep-unioning for all extensions.

mjmahone avatar Jul 07 '22 18:07 mjmahone

(From the working group we also noted that it's not possible to add directives to fields in this manner for similar reasons, and a solution to one of these should solve both.)

benjie avatar Jul 08 '22 07:07 benjie