Skip to content
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

Fetched data is not converted into a record. #18

Open
hodatorabi opened this issue May 4, 2020 · 1 comment
Open

Fetched data is not converted into a record. #18

hodatorabi opened this issue May 4, 2020 · 1 comment

Comments

@hodatorabi
Copy link

hodatorabi commented May 4, 2020

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.

@hodatorabi
Copy link
Author

hodatorabi commented May 4, 2020

Update: I now know my log prints an array due to this: https://bucklescript.github.io/docs/en/better-data-structures-printing-debug-mode but still don't know why my data.hello is empty.

Update 2: Apparently that's not the case anymore: https://twitter.com/bobzhang1988/status/1196556310122135552
so this might actually be the reason why my example doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant