1

I got a data from js side, it looks like this { "selectionSet": { "type": 1, "selections": [ { "name": { "kind": "Name", "value": "viewer" }, "selectionSet": { "type": 1, "selections": [ { "name": { "kind": "Name", "value": "avatarUrl" }, "selectionSet": null } ] } } ] } } I'm wondering how to defined types for selectionSet and selections.

It seems that when defining selections, I should have defined selectionSet because it has a field whose type is selectionSet. But when defined selectionSet, I should have defined selections

Can someone answer it in OCaml style? I want to convert this JSON style data into a record.

Shuumatsu
  • 592
  • 2
  • 5
  • 12
  • 2
    You are encouraged to post code as text, not as images. This helps people read and manipulate it. – coredump May 18 '18 at 11:44

1 Answers1

3

To define mutualy recursive types or functions for that matter you can use the key word and. In your case your records would look something like that:

type selectionSet = {
  t : t;
  selections : selections list;
}

and selections = {
  name : name;
  selectionSet : selectionSet option;
}
Daiwen
  • 727
  • 1
  • 4
  • 15