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

Unable to mutate enum value through visitEnumValue #1390

Closed
danielrearden opened this issue Apr 23, 2020 · 3 comments · Fixed by #1391
Closed

Unable to mutate enum value through visitEnumValue #1390

danielrearden opened this issue Apr 23, 2020 · 3 comments · Fixed by #1391

Comments

@danielrearden
Copy link
Collaborator

I hit this issue while trying to implement a simple directive that would let you change the value of an enum value:

export class ValueDirective extends SchemaDirectiveVisitor {
  visitEnumValue(
    enumValue: GraphQLEnumValue,
  ): GraphQLEnumValue {
  return {
    ...enumValue,
    value: this.args.string,
  }  
}

The intent with the above directive is to have an SDL-only way to deal with "internal" values of enum values without having to utilize the resolver map.

Like all the other visitors, visitEnumValue lets you return a new GraphQLEnumValue that should replace the existing enum value. However, GraphQLEnumType utilizes several private properties that are derived from the initial set of values so just replacing the enum value won't cut it -- the whole enum type has to be created if any of the values are modified.

@ardatan ardatan reopened this Apr 23, 2020
@ardatan ardatan added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Apr 23, 2020
@yaacovCR
Copy link
Collaborator

Thanks for this PR, try out with npm install graphql-tools@alpha.

@danielrearden
Copy link
Collaborator Author

Works like a charm, thank you for the quick turnaround!

@yaacovCR
Copy link
Collaborator

Closed by #1419.

@yaacovCR yaacovCR removed the waiting-for-release Fixed/resolved, and waiting for the next stable release label May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants