Zaid-Ajaj / Snowflaqe

A dotnet CLI to generate type-safe GraphQL clients for F# and Fable with automatic deserialization, static query verification and type checking
MIT License
154 stars 25 forks source link

Escape F# keywords in output #80

Closed etareduction closed 1 year ago

etareduction commented 1 year ago

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.

baronfel commented 1 year ago

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

Zaid-Ajaj commented 1 year ago

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.

etareduction commented 1 year ago

@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.

Zaid-Ajaj commented 1 year ago

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 😄

etareduction commented 1 year ago

@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 :(

etareduction commented 1 year ago

@Zaid-Ajaj

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

Here it is: #81