Add support for inline enum arguments
See original GitHub issueGiven that GraphQL serializes Enum values as strings, it would be great to have them supported as argument parameters. Currently they throw a Only scalar argument types currently supported.
error.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:14 (8 by maintainers)
Top Results From Across the Web
kotlin - can you help me explaining how this function work? ...
In Kotlin, inline functions get their bodies transformed in compile-time and, well, inlined at each of the call sites.
Read more >enum — Support for enumerations
enum — Support for enumerations¶ · is a set of symbolic names (members) bound to unique values · can be iterated over to...
Read more >TypeScript: Handbook - Enums
Numeric enums An enum can be defined using the enum keyword. Above, we have a numeric enum where Up is initialized with 1...
Read more >Enums
You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort parameter...
Read more >TypeScript string enums, and when and how to use them
enums are not natively supported in JavaScript, but there is a workaround ... declare them as types and pass them as arguments to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What if the Enum is inside a type? For example like below
mutation addSample($action: sampleInputType){ addSample(action: $action) { id } }
sampleInputType has a enum field.The above query do not work? How to handle nested enums with variables?
Prerequisites:
We must define < SomeEnumType > in our GraphQL schema (server side, no client configuration needed)
Let’s assume we have defined:
We also must configure our Apollo Client in appropriate way ans connect it with the GraphQL API.
Then on client side:
Only doing this, you can pass enum as a variable in your query or mutation. For example using useMutation hook we can now mutate as follows:
Since our type definition in gql tag equals with definition in Schema, GraphQL recognizes our variable as an enum type despite of that we give it as a string.
If we want pass enum to our variables using typescript enums we can do it as follows: