byme8 / ZeroQL

C# GraphQL client with Linq-like syntax
MIT License
278 stars 13 forks source link

Escape Reserved Keywords in Generated C# Code #38

Closed lennykean closed 1 year ago

lennykean commented 1 year ago

This PR addresses an issue with the C# code generator. When a GraphQL schema contains reserved keywords as parameter names, the result is invalid C# code.

For instance, a GraphQL schema like the one below:

type Query {
  example(object: Data): String
}

would generate the following invalid C# code:

public string? Example(Data? object) // Syntax error

This is because object is a reserved keyword in C#.

To resolve this, the PR introduces a check in the generator to escape reserved keywords with the '@' character.

Using the same GraphQL schema as above, the generator now produces the following valid C# code:

public string? Example(Data? @object) // Valid
byme8 commented 1 year ago

Created release v3.6.2. Should be available in the Nuget soon.