question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum value is not resolved to internal value for directive argumets and default values

See original GitHub issue

the original issue was submitted to the graphql-tools repo, but it seems that it never made it here.

the issue is that after following the official documentation the enum value is not resolved to the internal value when used as a default value or in directives.

the test attached to the original issue provided by @JakeDawkins https://gist.github.com/JakeDawkins/66f5b026cf21515f1004f057754a2cd4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
IvanGoncharovcommented, Dec 12, 2018

@raduflp With current graphql-js design defaultValue should be in internal representation. So to correct @JakeDawkins example you need to do:

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: () => ({
      avatar: {
        type: GraphQLBoolean,
        args: {
          anEnum: {
            type: allowedColor,
            defaultValue: '#f00',
            //            ^ Changed to value
          },
        },
        resolve: (root, args) => (args.anEnum === '#f00' ? false : true),
      },
    }),
  }),
});

Same goes for custom scalars, arrays or any other example of input coercion. For example ID coerce numbers to strings but this coercion is not applied on defaultValue:

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: () => ({
      avatar: {
        type: GraphQLBoolean,
        args: {
          id: {
            type: GraphQLID,
            // INVALID defaultValue: 0
            defaultValue: '0', //VALID
          },
        },
      },
    }),
  }),
});
1reaction
langpavelcommented, Jan 17, 2019

Current behavior is expected 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

What you need to know about GraphQL enums
Apollo Server will resolve enum values to their proper internal values ( resolvers.AuthType ) for both input and output data ( Mutation ...
Read more >
Directives - Apollo GraphQL Docs
Default directives ​​ Marks the schema definition of a field or enum value as deprecated with an optional reason. @skip(if: Boolean!) If true...
Read more >
How to use a typescript enum value in an Angular2 ngSwitch ...
This question is about ngSwitch based upon a particular value of an enum. Although the same approach of creating an class-internal reference to ......
Read more >
Enumeration declaration - cppreference.com
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >
Enums - C# language specification - Microsoft Learn
An enum type is a distinct value type (§8.3) that declares a set of named ... Shall resolve to an integral type other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found