5 ms·
It works with circular references. For example, this works: { "user": [ { "id": 456, "name": "Sita K", "user_id": 123 }, { "id": 123,
by wawhal 8y ago
It works with circular references. For example, this works:
{
"user": [
{ "id": 456, "name": "Sita K", "user_id": 123 },
{ "id": 123, "name": "John Doe", "user_id": 123 }
]
}
Do you have anything else in mind?
PS: Co-author here
- chrisseaton 8y agoBut then to go from user 456 to user 123 via the field user_id do I have to do a linear search of all users to check their IDs?
- wawhal 8y agoNo. The tool also creates relationships based on foreign key references using Hasura. So to query all the users with the child users, you would make a GraphQL query like: query { user { id name childUser: userByUserId { id name } } } The response would be: { "data": { "user": [ { "id": 123, "name": "John Doe", "childUser": { "id": 123, "name": "John Doe" } }, { "id": 456, "name": "Sita K", "childUser": { "id": 123, "name": "John Doe" } } ] } } Did I answer your question?
- chrisseaton 8y agoThose child users don't then have their own child users (because it's cyclic) so do you have to choose one option of the two, both with a drawback? I was thinking you could replace or supplement the real user IDs with their indices in the array of returned users.
- general8bitso 8y agoSo, is a hypothetical scenario, an employee that is their own supervisor?
- chrisseaton 8y agoYes, but I'm not sure if you're implying that it's a nonsensical situation with that example. Lots of real-world graphs have genuine cycles.
- stevekemp 8y agoFor a good example of unexpected cycles you can see this classic question on genealogy software: https://stackoverflow.com/questions/6163683/cycles-in-family-tree-software https://stackoverflow.com/questions/6163683/cycles-in-family...
- wawhal 8y agoI am sorry, but if possible, could you elaborate @chrisseaton? (preferably with a bit more punctuation :D)
- chrisseaton 8y agoWith more punctuation? What's that supposed to mean? I've written two short sentences. It's not some wall of text.
- pmarreck 8y ago... wouldn't the second line have to be "user_id": 456, in order to really be circular?
- wawhal 8y agoCircular references basically mean that a table is referencing itself. Any row in the table could reference any row.