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

Mapping of custom scalars #8

Closed MargaretKrutikova closed 4 years ago

MargaretKrutikova commented 4 years ago

I am using hasura graphql api and for dates it generates custom scalars like date and timestamptz, which get mapped to the same types in F#, but there are no such types in F# 🙂

Is there any way to provide custom mapping for those scalar types to F# types? I would happy even with strings there, but for now nothing compiles 🙂

Thanks!

Zaid-Ajaj commented 4 years ago

Hi @MargaretKrutikova, I believe custom scalars compile to strings if they are not recognized. Can you please elaborate more on your issue? Are the types not being generated at all or the is the generated code not compiling at all?

MargaretKrutikova commented 4 years ago

Yes, I should have been more specific. Types of query and mutation parameters don't get compiled to string. If custom scalar types are used in the response, they are indeed compiled to strings.

Zaid-Ajaj commented 4 years ago

I see, so parameter types are not mapped to strings. Do you happen to have a sample schema and sample query/mutation that I can debug against? If the types are date and timestamptz and they are transferred as ISO-8601 dates then we should be able to map those to DateTime for date and DateTimeOffset for timestamptz

MargaretKrutikova commented 4 years ago

Yes, here is the schema, and a query you can test against:

query GetCurrentOrderQuery($userId: Int!, $deliveryDate: timestamptz!) {
  userOrders(
    where: { userId: { _eq: $userId }, deliveryDate: { _gte: $deliveryDate } }
  ) {
    status
    id
    deliveryDate
    userOrderDetails {
      amount
      id
      price
      status
    }
  }
}

schema.txt

Zaid-Ajaj commented 4 years ago

Awesome, thanks a lot! This is enough information for me start debugging the issue. I will work on it soon and will keep you posted :smile:

Closed the issue by accident, nvm that

MargaretKrutikova commented 4 years ago

Great, thanks a lot! 🙂

Zaid-Ajaj commented 4 years ago

Hi @MargaretKrutikova, I just published a new version of Snowflaqe and your issue should now be resolved as of v1.5 :rocket:

I was able to reproduce the problem where a custom scalar type like timestamptz was being as is in the generated code for the input variables which of course breaks the whole project because such type is not recognized in F#. I fixes this problem by:

You should be able to update the tool by first uninstalling it and then re-installing:

dotnet tool uninstall snowflaqe -g
dotnet tool install snowflaqe -g 

Please let me know if this actually solves the problem at hand 🙏 reopen the issue if the problem persists (or if you encounter any more of these types of issues)

MargaretKrutikova commented 4 years ago

Just verified that everything works properly with the new version. Thanks a lot for your hard work! 🙂

xperiandri commented 3 years ago

Are these types specific to PostgreSQL? I tried to search them and only GraphQL with PostgreSQL articles appear.

Zaid-Ajaj commented 3 years ago

@xperiandri these types are specific to hasura, snowflaqe knows about them and translates them accordingly

Numpsy commented 3 years ago

Hi,

On a related note to this:

I had a go at generating a client for a GraphQl service written using Hot Chocolate and I notice that properties defined on the server as C# long are represented in the generated schema as a custom scalar type Long (there is some documentation about that at https://chillicream.com/docs/hotchocolate/v10/schema/custom-scalar-types).

Those are currently represented as string in the F# client generated by Snowflaqe.

I was just wondering if there are any thoughts or objections to the idea of recognizing those in the generator, and exposing the properties as int64 instead of string?

xperiandri commented 3 years ago

Must be a simple fix

Zaid-Ajaj commented 3 years ago

@Numpsy I've fixed this issue in latest Snowflaqe v1.27 it should now handle Long as int64 please give it a try and confirm whether it works for you or not.