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.
@kabytaa thanks for reporting this issue! Any chance you can share your full template / failing test? it will make it easier to solve :)
Hello, is there any update on sharing full template code or reproduction?
@kabytaa ?
Sorry for the deley. Here is the git project:
git clone https://github.com/kabytaa/ifDirectiveEnumIssue.git
npm install
npm start
then the result will be in "_gqlEnums.ts" file.
@kabytaa you are right :) fixed it in: https://github.com/dotansimha/graphql-code-generator/pull/626
I tried your fix(0.12.5) my project still not working.
Just do:
git pull
npm start
@kabytaa , this fix it not published yet... can you please try 0.13.0-alpha.106f2555?
Great, it works now.
Thanks
@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 :)