ifiokjr / edgedb_codegen

Generate fully typed rust code from your edgedb schema.
The Unlicense
8 stars 0 forks source link

Support for custom scalars #8

Open CodesInChaos opened 2 weeks ago

CodesInChaos commented 2 weeks ago

I'm interested in proper support for custom scalar types. This has some overlap with the enum support mentioned in the readme, in particular this applies to them as well:

However end users probably don't want multiple enums for each generated query module as this would break sharing. To get around this, there should be a macro for generating the shared types used by all other.

There is one additional challenge however: Custom scalars usually have constraints, so the new function needs to contain validation and return a custom Result type. Auto generating that isn't trivial for standard constraints, and practically impossible for expression constraints. So there needs to be a design that allows mixing auto-generated code with custom written code.

ifiokjr commented 2 weeks ago

I think I'll leave the custom scalar types until the edgedb-protocol library is upgraded to protocol version 2.0. This provides names for the scalar types which can be added to the shared types.

Regarding constraints, I was thinking there might be a way to provide the https://github.com/Keats/validator as an option. But I can't think of a good API for this.

It's not a high priority for my current project, but if you can think of a compelling way to integrate this, I'm happy to accept contributions.