Skip to content

Support for rescript 11 and uncurried mode #290

Open
@JasoonS

Description

@JasoonS

I was unable to use this library in a new rescript 11 project.

I received the following error:

  This function is a curried function where an uncurried function is expected

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:

let result = %graphql(`
  query UserQuery {
  indexers {
    created_time
    indexer_id
  }
}
`)

Activity

DZakh

DZakh commented on Nov 30, 2023

@DZakh

I managed to make it work using @@uncurried.swap

// 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=...)
cwstra

cwstra commented on Dec 7, 2023

@cwstra

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.

LeoLeBras

LeoLeBras commented on Jan 19, 2024

@LeoLeBras

A rescript-forum note from the main maintainer 🙏

We at walnut are going to migrate to ReScript 11 as well, and are maintaining graphql-ppx bear with us while we ship an update. But it’s in progress :slight_smile:
https://forum.rescript-lang.org/t/anyone-using-graphql-ppx-and-rescript-apollo-client-with-11/4995/4?u=leolebras

studious

studious commented on Jan 30, 2025

@studious

Hello,
does TeamWalnut have a timeframe for publishing a new npm package with latest ppx binaries compatible with rescript 11?

My colleague is proceeding by grabbing the binary that was committed at one point and referencing this repo directly.

Something official would be great even if uses @next notation.

LeoLeBras

LeoLeBras commented on Feb 10, 2025

@LeoLeBras

Hello, does TeamWalnut have a timeframe for publishing a new npm package with latest ppx binaries compatible with rescript 11?

My colleague is proceeding by grabbing the binary that was committed at one point and referencing this repo directly.

Something official would be great even if uses @next notation.

👍 It would be great if a stable “latest” version could be released.
The latest version was published in #dev branch under the release name 1.2.4-79d140a5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @studious@LeoLeBras@JasoonS@cwstra@DZakh

      Issue actions

        Support for rescript 11 and uncurried mode · Issue #290 · teamwalnut/graphql-ppx