Add proper JSON schema for Phylo graph data
Hopefully helps with #206 (closed).
@anoe I have now manually added a "schema" for the JSON by manually writing all the required instances, and wrote quite a bit of tests, including two golden tests. The second test, the one called testOpenSciencePhylo
is the most important one, because it tries to decode the JSON emitted by gargantext which currently cannot be decoded by the purescript frontend.
Initially, when writing this test, I've got a failure, because the nodes
field couldn't be found, and to mitigate that I have made the JSON parser a bit more lenient: whenever we encounter a Layer
node which has no nodes
field, we default to the empty list. @qlobbe I'm not really an expert on the phylo JSON format, but do you think this is a bug or we can genuinely emit an object
from our Phylo code that has no nodes?
Either way, I can speculate (mind, is a wild guess!) now why I think the Purescript frontend was failing: the PS frontend was trying to parse a RawObject
by trying to parse each and every object type (one between Layer
, PeriodToNode
etc). Conceivably Layer
was the first one tried, but the parsing failed because nodes
wasn't there. Therefore, the next available parser was attempted, i.e. the one for PeriodToNode
, but the input JSON didn't have the bId
field, and therefore the PS frontend failed with that message.
Long story short, I would expect that after we merge this patch, something should change; either we would get parsing errors when producing the GraphData
from the backend, or we should see a slightly different error in the frontend.