Zaid-Ajaj/Snowflaqe

Escape F# keywords in output

etareduction opened this issue · 6 comments

Currently if you try to generate from a schema that has fields named like of in it's type declarations, generated types won't compile with following error

Unexpected keyword 'of' in field declaration. Expected identifier or other token

I suggest escaping such cases like that:

type A = { ``of``: int }

Also @baronfel#1673 in F# discord suggested that there is some compiler-provided function to detect stuff like that.

I am thinking of FSharp.Compiler.Syntax.PrettyNaming.NormalizeIdentifierBackticks, which should add double-backticks if required to any identifier.

Hi @etareduction i thought we were escaping keywords, guess of slipped through. I will have a look when I can, for the time being, you can alias the GraphQL field to something else that is not a F# keyword.

@Zaid-Ajaj

for the time being, you can alias the GraphQL field to something else that is not a F# keyword.

I don't think it's that easy. Snowflaqe seems to generate types for the whole schema, not only types that i depend on in queries. So it doesn't compile as a whole for me while this problem is unsolved.

Snowflaqe seems to generate types for the whole schema

I believe only input types and enums are generated globally, the rest is dependant on the query

So it doesn't compile as a whole for me while this problem is unsolved

Happy to accept a PR if you are willing to look into it 😄

@Zaid-Ajaj

I believe only input types and enums are generated globally, the rest is dependant on the query

Yeah, i see. I have of's in my input types unfortunately :(

@Zaid-Ajaj

Happy to accept a PR if you are willing to look into it 😄

Here it is: #81