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

Current enum value isn't present on GraphQLEnumType_values_value scope #2035

Closed
benjie opened this issue Apr 29, 2024 · 4 comments · Fixed by #2143
Closed

Current enum value isn't present on GraphQLEnumType_values_value scope #2035

benjie opened this issue Apr 29, 2024 · 4 comments · Fixed by #2143

Comments

@benjie
Copy link
Member

benjie commented Apr 29, 2024

const makeDeprecateEnumsPlugin = (enumTypeName: string, enumValues: string[], deprecationReason: string): GraphileConfig.Plugin => ({
  name: `DeprecateEnumsPlugin_${enumTypeName}_${enumValues.join("_")}`,
  value: "0.0.0",

  schema: {
    hooks: {
      GraphQLEnumType_values_value(value, build, context) {
        if (context.Self.name !== enumTypeName) return value;
        if (!enumValues.includes(context.scope.OH_NO_THIS_DOESNT_EXIST_YET)) return value;
        return {
          ...value,
          deprecationReason,
        }
      }
    }
  }
});

Should be equivalent to the fieldName on the GraphQLObjectType_fields_field scope. enumValueName?

Hipri: sylv

@benjie
Copy link
Member Author

benjie commented Apr 30, 2024

Related: graphql/graphql-js#4018

@benjie
Copy link
Member Author

benjie commented Apr 30, 2024

Turns out Self also doesn't exist; and both are for the reason outlined in the graphql-js issue above.

@benjie
Copy link
Member Author

benjie commented Aug 6, 2024

On hold due to #2142

@benjie
Copy link
Member Author

benjie commented Aug 6, 2024

Something like this should work:

const makeDeprecateEnumsPlugin = (enumTypeName: string, enumValues: string[], deprecationReason: string): GraphileConfig.Plugin => ({
  name: `DeprecateEnumsPlugin_${enumTypeName}_${enumValues.join("_")}`,
  value: "0.0.0",

  schema: {
    hooks: {
      GraphQLEnumType_values_value(value, build, context) {
        if (context.Self.name !== enumTypeName) return value;
        if (!enumValues.includes(context.scope.valueName)) return value;
        return {
          ...value,
          deprecationReason,
        }
      }
    }
  }
});

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

Successfully merging a pull request may close this issue.

1 participant