docs: document `table_by_pk` query
See original GitHub issueInstead of query { person(where: ... ) { id } }
returning an array of person
, it would be nice if it returned a single object.
This pattern of duplicating interactions for both plural (arrays) and singular (objects) results can be applied to mutations as well as queries.
Example:
// before
{
users(where: {
id: {
_eq: 123
}
}) {
id
}
} // returns an array of users even if I just want one... this makes destructuring and working with these values messy
// after
{
user (where: {
id: {
_eq: 123
}
}) {
id
}
} // returns a single user object
// OR
{
users (where: {
id: {
_eq: 123
}
}) {
id
}
} // returns an array of users that might match that query
// before
mutation AddUser ($objects: [users_insert_input!]!) { // I only want to insert a single user but I have to submit the mutation as an array.
insert_users(objects: $objects) {
returning {
id
}
}
}
// after
mutation AddUser ($object: user_insert_input!) { // only inserting a single user; returning a single object
insert_user(object: $object) {
returning {
id
}
}
}
// OR
mutation AddUsers ($objects: [users_insert_input!]!) { // Sometimes I will want to add multiple users, so keep the existing queries/mutations available.
insert_users(objects: $objects) {
returning {
id
}
}
}
GraphCMS does this and it’s a really nice user experience. In contrast, this is really one of the few things I find actually hinders my productivity and ability to read the code with Hasura.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:27 (7 by maintainers)
Top Results From Across the Web
QUERY function - Google Docs Editors Help
Runs a Google Visualization API Query Language query across data. Sample Usage QUERY(A2:E6,"select avg(A) pivot B") QUERY(A2:E6,F2,FALSE) Syntax QUERY(data, ...
Read more >Get data with Cloud Firestore - Firebase
There are three ways to retrieve data stored in Cloud Firestore. Any of these methods can be used with documents, collections of documents,...
Read more >Method: documents.get | Google Docs
Method: documents.get · On this page · HTTP request · Path parameters · Query parameters · Request body · Response body · Authorization...
Read more >Google Docs: Online Document Editor | Google Workspace
Use Google Docs to create, and collaborate on online documents. Edit together with secure sharing in real-time and from any device.
Read more >Query Drive data | BigQuery - Google Cloud
To retrieve the Drive URI, see Share a link to the file. URI format. https://docs.google.com/spreadsheets/d/ FILE_ID. or. https ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Singular and plural resolvers are already available for querying. I will update the docs on this soon 🙂
Also, renaming the singular resolvers like
user_by_pk
to something likeuser
will be possible via this PR: https://github.com/hasura/graphql-engine/pull/2509.@coco98 I know about searching by primary key, but what about searching through other columns for a single query?