question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs: document `table_by_pk` query

See original GitHub issue

Instead 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:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
marionschleifercommented, Jul 29, 2019

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 like user will be possible via this PR: https://github.com/hasura/graphql-engine/pull/2509.

4reactions
OLDINcommented, Jun 20, 2019

@coco98 I know about searching by primary key, but what about searching through other columns for a single query?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found