Skip to content

Fetched data is not converted into a record. #18

@hodatorabi

Description

@hodatorabi

I'm running a simple hello world example similar to the one that is used as an example in this repo. Here is the code for it:

let query =
  ReasonQL.gql({|
  query AppQuery {
    hello {
      message
    }
  }
|});

module Request =
  ReasonQL.MakeRequest(
    AppQuery,
    {
      let url = "http://localhost:4000";
      let headers = Js.Obj.empty();
    },
  );

let onClick = () => {
    Js.log("Loading data...");
    Request.send(Js.Dict.empty())
    ->Request.finished((data: AppQuery.queryResult) => {
        Js.log2("fetched", data.hello);
      });
  };


Problem is when I print the data, data is an array with the value of my hello field and data.hello returns undefined. I've also run the hello world example that is included in the project, printing data results in the same output but actually accessing data.hello seems to work as expected. I also checked the generated AppQuery.re and the decoding of the response is like below:

[%%raw {|
var decodeHello = function (res) {
  return [
    res.message,
  ]
}

var decodeQueryResult = function (res) {
  return [
    decodeHello(res.hello),
  ]
}
|}]

Seeing as this is returning an array, it seems reasonable that the data after the request finished is also an array. I just don't get how the record is being correctly made in the hello world example in this project and how to get the expected behavior which is getting my result as records. Since these examples and package haven't been updated in a while maybe there has been some breaking change which I can't seem to figure out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions