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.

ifDirective on enum value not working

See original GitHub issue

I have the following scenario:

gql file:

directive @lookup on ENUM
directive @lookupItem(id:Int! ,name: String!) on ENUM_VALUE
enum Color @lookup{
    RED @lookupItem(id:1 ,name: "Red")
    GREEN @lookupItem(id:2 ,name: "Green")
}

handlebars file:

{{#each enums}}
{{#ifDirective this "lookup"}}
export const {{../name}}Lookup = {
  {{#each ../values }}
   {{value}}: { {{#ifDirective this "lookupItem"}}id:{{id}},name:'{{name}}'{{/ifDirective}} } ,
  {{/each}}
}
{{/ifDirective}}
{{/each}}

gql-gen.json:

{
  "flattenTypes": true,
  "primitives": {
    "String": "string",
    "Int": "number",
    "Float": "number",
    "Boolean": "boolean",
    "ID": "string"
  }
}

output file:

export const ColorLookup = {
	RED: {},
	GREEN: {}
};

expected output:

export const ColorLookup = {
	RED: {id:1,name:'Red'},
	GREEN: {id:2,name:'Green'}
};

What I did wrong? Please help.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dotansimhacommented, Sep 18, 2018

@kabytaa great 😃 we’ll release a stable version with this fix soon (and then i’ll close the issue). Until then you can use the alpha 😃

1reaction
kabytaacommented, Sep 18, 2018

Great, it works now. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

If statement not working as expected on combined enum value
Seems the [Flags] attribute wasn't set on the enum as I originally thought. Adding this attribute now makes the enum work in either...
Read more >
Enumerations — The Swift Programming Language (Swift 5.7)
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe...
Read more >
ENUM - MariaDB Knowledge Base
If a DEFAULT clause is missing, the default value will be: NULL if the column is nullable;; otherwise, the first value in the...
Read more >
Enum Statement - Visual Basic - Microsoft Learn
Declares an enumeration and defines the values of its members. ... The following example shows how to use the Enum statement.
Read more >
11.3.5 The ENUM Type
The numbers are translated back to the corresponding strings in query results. and these potential issues to consider: If you make enumeration values...
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