GraphQL Query JSON?
See original GitHub issueIt’d be really cool if we could declare a field as JSON/B and query it per usual. My reasons for thinking this is that sifting through 50 columns in a table for misc stuff—or having 10 tables all revolving around the same concept—seems messy and hard to navigate.
In contrast, dumping things that are related to a concept, but not big enough to warrant their own table, might clean a db up. For instance, a User might have a profile with some addresses, names, and such in it… A User might also have a bunch of stuff related to auth (e.g. tokens, providers, roles, etc.). If you break those out into their own columns on the User table, you end up with 50 columns. If you break them out to their own tables, you end up stitching together all those tables with relationships.
Open to discussion/suggestions/critique, but the generic query syntax might look like this:
(https://www.db-fiddle.com/f/UsVwfCin7LFLZbAuW691G/2)
{
user {
profile {
name
}
}
}
And where
syntax might look like this:
{
user {
profile(where: {
addresses: {
_contains: {
type: "billing"
}
}
}) {
name
}
}
}
So I suppose arrays could do _contains
where the param is part of an object?
Feel free to poke holes in this. No rush. I’m slightly concerned what performance would be, and if perf is fine, then nailing the syntax might be tricky if there isn’t some GraphQL spec for it already.
Resources:
- https://blog.hasura.io/postgres-json-and-jsonb-type-support-on-graphql-41f586e47536/ (can
where
; can’t generic query) - https://github.com/taion/graphql-type-json (not sure what this is exactly, but it has 200k+ weekly downloads so might be relevant 😅)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:11 (5 by maintainers)
Is there a way to use the postgres
->>
and#>>
operators in query filters, e.g.@aboutaaron You can find documentation and sample here https://docs.hasura.io/1.0/graphql/manual/api-reference/graphql-api/query.html#simple-object