Closed DZakh closed 10 months ago
Sure! Check this repo out: https://github.com/zth/relay/tree/rescript-relay. It's the Relay compiler fork RescriptRelay uses. It's in the compiler/
dir.
Place yourself in the compiler/test-project-res
dir and run cargo build && ../target/debug/relay
. That'll compile the compiler and run it on the test project. You'll see any changes you make reflected there.
Adding @as()
is hopefully fairly straight forward. There should be plenty of examples in the code base.
Currently my project using "rescript": "v11-rc.4" and "rescript-relay": "^2.0.0" with uncurried: true. I have input type in graphQL schema:
input ShippingFeePolicyMutationInput {
amount: Int!
freeShippingThreshold: Int
quantityStep: Int
type: ShippingFeePolicyType!
}
The js output has _type
instead of type
now with this ReScript code.
Mutation.make_shippingFeePolicyMutationInput(~amount=0, ~_type=#FREE, ())
{
amount: 0,
_type: "FREE"
}
The functions and type definition are extracted from the generated modules by rescript-relay.
It's the same issue I've described in the description. That's because of the PR: https://github.com/rescript-lang/rescript-compiler/pull/6354 Fix in the PR: https://github.com/zth/relay/pull/15
@DZakh Can you check the playground link I've added? I'm wondering why this output has type
.
See https://github.com/rescript-lang/rescript-compiler/pull/6354. There used to be the logic of mangling object keys up till 11-rc.3
I think the change should be highlighted more in ReScript V11 release notes. It's a breaking change people should know about.
Ah! I confused the setting of playground it was v11-beta.4 not rc.3 π
I opened an issue https://github.com/rescript-lang/rescript-compiler/issues/6440, if the js output is generated by the return type of the external function, then _type
issue here would be fixed, I guess.
Yes, but I think it'll be quite difficult to make it work. Also, if you noticed, in our case the type has a field called type_
, while external
has a field called _type
.
2.1.0
is out, and should fix this. Reopen if it does not.
I've tried migrating the project at Carla to rescript@11 several times. I've fixed all the issues besides the problem with rescript-relay:
For context, we want to use
uncurried: false
since the codebase is quite big, and we want to gradually migrate to uncurried mode. Because of this, therescript-relay
V3 is not an option for us.So we need to use
rescript-relay
V2 until we completely migrate to uncurried mode. But there's another problem. It uses_
prefixes for gql fields having restricted names. In rescript@10 the_
s were removed in runtime, but after my PR π I removed the fields mangling logic from rescript@11. This way,rescript-relay
V2 stopped handling private keywords in rescript@11 properly, the fields in compiled js are now prefixed with_
.Later, I've added the PR to allow using
@as
with@obj
so there's a migration path from fields mangling logic.So, now I'd like to update
rescript-relay
V2 to use@as
instead of_
for private keywords in the generated code. I've already taken a look in the source code and noticed a submodule written in Rust. If you tell me how to contribute to it, I'd like to give it a try. I really wish to start using rescript@11 in production.