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

Handling of double-quoted Descriptions in SDL #67

Closed Yakimych closed 2 years ago

Yakimych commented 2 years ago

Hi! Maybe I am missing something, but I am getting errors when trying to run snowflaqe --generate off of a more-or-less standard HotChocolate schema.graphql file. There are a number of directives and scalars at the end of the schema file, preceded with comments:

"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`."
directive @defer("If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to." label: String "Deferred when true." if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT

"The `@specifiedBy` directive is used within the type system definition language to provide a URL for specifying the behavior of custom scalar definitions."
directive @specifiedBy("The specifiedBy URL points to a human-readable specification. This field will only read a result for scalar types." url: String!) on SCALAR

"The `@stream` directive may be provided for a field of `List` type so that the backend can leverage technology such as asynchronous iterators to provide a partial list in the initial response, and additional list items in subsequent responses. `@include` and `@skip` take precedence over `@stream`."
directive @stream("If this argument label has a value other than null, it will be passed on to the result of this stream directive. This label is intended to give client applications a way to identify to which fragment a streamed result belongs to." label: String "The initial elements that shall be send down to the consumer." initialCount: Int! "Streamed when true." if: Boolean!) on FIELD

"The `DateTime` scalar represents an ISO-8601 compliant date time type."
scalar DateTime @specifiedBy(url: "https:\/\/www.graphql-scalars.com\/date-time")

"The `Long` scalar type represents non-fractional signed whole 64-bit numeric values. Long can represent values between -(2^63) and 2^63 - 1."
scalar Long

The first error I get is

Syntax Error GraphQL (628:1) Unexpected String "The `@defer` directive..."

As far as I understand, those are just Descriptions according to the spec. If I remove them, however, I get the following error:

Expected Name, found String "If this argument label has a value other than null, it will be passed ...

From what I can see in this thread: https://github.com/ChilliCream/hotchocolate/issues/4147#issuecomment-908129090, this SDL is as expected.

Zaid-Ajaj commented 2 years ago

Hi @Yakimych it could be that the GraphQL parser that Snowflaqe uses is parsing an older spec of GraphQL. What you could do is download the schema, not as SDL but as JSON. From the README docs about the <schema>:

A relative path to another JSON file containing the output of the standard Introspection query which you can execute against the backend yourself (this allows for offline verification and type-checking)

Can you give this a try?

Yakimych commented 2 years ago

Hi @Zaid-Ajaj ,

Thanks for the quick reply! Yep, I've tried it with JSON and it seemed to work fine, it's the SDL that is the problem though.

Yakimych commented 2 years ago

Hi again @Zaid-Ajaj,

After some quick digging, it looks like you are right - it's only Descriptions that are not parsed correctly. The quoted syntax was introduced in the June 2018 version of the spec: http://spec.graphql.org/June2018/#sec-Descriptions. The older syntax with # Description works with snowflaqe.

I will update the name of the issue and remove mentions of "Scalars" and "Directives".

Zaid-Ajaj commented 2 years ago

Thanks @Yakimych for looking into this. I will look for a fix when time permits 😄

Yakimych commented 2 years ago

Great, thanks!

Yakimych commented 2 years ago

@Zaid-Ajaj We've bumped the GraphQL-dotnet package and it seems to have fixed the problem. A PR coming up tonight: https://github.com/danielstarck/Snowflaqe/tree/update-package