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

.NET 6 SDK, Fantomas 5, GitHub Schema updates #75

Closed beauvankirk closed 1 year ago

beauvankirk commented 1 year ago

Hi Zaid - Long-time listener (fan), first-time caller (contributor).

Changes to the GitHub GraphQL schema resulted in a couple issue in Snowflaqe generated code, namely:

image

///The type of a project item.
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ProjectItemType =
    /// Issue
    | [<CompiledName "ISSUE">] Issue
    /// Pull Request
    | [<CompiledName "PULL_REQUEST">] PullRequest
    /// Draft Issue
    | [<CompiledName "DRAFT_ISSUE">] DraftIssue
    /// Redacted Item
    | [<CompiledName "REDACTED">] Redacted

///The type of a project next field.
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ProjectNextFieldType =

///Properties by which the return project can be ordered.
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ProjectNextOrderField =

///Properties by which project connections can be ordered.
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ProjectOrderField =
    /// Order projects by creation time
    | [<CompiledName "CREATED_AT">] CreatedAt
    /// Order projects by update time
    | [<CompiledName "UPDATED_AT">] UpdatedAt
    /// Order projects by name
    | [<CompiledName "NAME">] Name

Initially I merely set out to make the minimal updates to address these issues, but I wasn't able to get a working build/development setup with my current dotnet 6 (or 7) SDK setup.

I saw from the previous commit that the simple switch to from net5 to net6 broke CI, so I decided to have a go at getting everything updated for dotnet SDK 6 and Fantomas 5.X.X. A few things made this a bit tricky, in particular the shift in Fantomas to to drop the direct dependency on FCS, swapping it out with the new Fantomas.FCS custom branch. As mentioned in the Readme for that package, it is not binary-compatible which was leading to type mismatches when attempting to get things working with both Fantomas.FCS and FCS loaded concurrently.

Given that all uses of the FCS API in Snowflaqe are eventually passed to Fantomas for rendering, it seemed the easiest route was to drop the direct FCS dependency, instead picking up the FCS assemblies/types from Fantomas.FCS. The current Fantomas.FCS release includes an almost current commit of FCS, which included a large refactoring of the SyntaxTree API, adding ___Trivia types/fields to many Syn types. Those changes required corresponding updates to AstRct/AstCreate helpers from FsAst.

With those changes I was able to get the build/test working, and implement the update/fixes for the GitHub schema. I added some tests for those changes as well, and also adjusted the expected output of a few tests to match the new Fantomas formatting of records with comments on fields.

Appveyor builds (using VS 2022 and Ubuntu images for matrix build, each of which include dotnet 6 SDK) are passing on my branch.

I wasn't sure whether to open separate PRs for just the GitHub schema update/fixes. I have branches for those as well (see git graph) if it makes more sense to start with those, just let me know.

image

This was my first time really delving into the AST stuff, so some of the routes I with may very well need revising.

Zaid-Ajaj commented 1 year ago

Hello @beauvankirk I want to take a second and appreciate the work you have done here :heart: getting this work and updating to net6.0 must have been really annoying with all the changes in Fantomas. I only have a minor nit but for the rest, let's get merged in 💯

Zaid-Ajaj commented 1 year ago

Snowflaqe v1.40.0 has been published with these improvements 🚀 thanks again 🙏