-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Recursive object as a graphql field #3531
Comments
You can have a Postgres table which is recursive. E.g. - CREATE TABLE messages (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content text NOT NULL,
parent_message UUID REFERENCES messages(id)
); Then in the Hasura console, if you go to the relationships tab of the messages table, you can see that both object and array relationships are suggested on the same table. You can add them both, name the object relationship as Now you can make the following query: query {
messages {
id
content
children {
id
content
}
}
} This fetches all messages and all their children. PS: beware that this query can be quite expensive on large data set. You would add limits etc. when using the query in production. |
Thank you so much. A simple foreign key is indeed doing the job perfectly. |
Is there a way to add a recursive object type as a field as explained here: graphql/graphql-spec#91 (comment) ?
The idea is to have replies on comments in a forum (like reddit, you can reply to a comment, which can be replied to etc.)
So that I could do the following query:
In the link I posted above, managing your own graphql server, they achieve it by using a function as a field that returns some other fields:
I wonder how I could achieve something similar with hasura.
The text was updated successfully, but these errors were encountered: