-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for rescript 11 and uncurried mode #290
Comments
I managed to make it work using // Api.res
type gqlResponse = {
data: option<Json.t>,
errors: option<Json.t>,
}
%%private(
@module("./api/fetchBackoffice.ts")
external fetch: (~query: string, ~variables: 'variables) => Promise.t<gqlResponse> = "default"
)
@@uncurried.swap
module MakeRequest = (
Query: {
module Raw: {
type t
}
type t
type t_variables
let query: string
let unsafe_fromJson: (. Json.t) => Raw.t
},
) => {
let toTask = (. ~variables: Query.t_variables): Task.t<Query.Raw.t, string> => {
Task.make((~resolve, ~reject) => {
fetch(~query=Query.query, ~variables)
->Promise.thenResolve(response => {
switch response {
| {errors: Some(errors)} => reject(errors->Json.stringifyAny->Option.getExn)
| {errors: None, data: None} => reject("Response data is empty.")
| {errors: None, data: Some(data)} => resolve(data->Query.unsafe_fromJson)
}
})
->Promise.catch(exn => {
exn->Exn.asJsExn->Option.flatMap(Exn.message)->Option.getExn->reject
Promise.resolve()
})
->ignore
None
})
}
} // Foo.res
%graphql(`
query Query($registrationNumber: String!){
carInfo(registrationNumber: $registrationNumber) {
engineType
modelYear
vehicleMake
model
}
}
`)
module Request = Api.MakeRequest(Query)
Request.toTask(~variables=...) |
I think the ppx still fails with a "This function is a curried function where an uncurried function is expected" error whenever a fragment shows up, which is harder to fix with a wrapper. |
A rescript-forum note from the main maintainer 🙏
|
I was unable to use this library in a new rescript 11 project.
I received the following error:
I didn't get the chance to dig deeper into the issue so I can't say what the root cause is, but it happened on this query:
The text was updated successfully, but these errors were encountered: