Skip to content
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

Rename table_get to table_row (nouns are better than verbs in GraphQL land) #36

Closed
simonw opened this issue Aug 8, 2020 · 14 comments
Closed
Labels
enhancement New feature or request
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Aug 8, 2020

GraphQL prefers nouns to verbs: https://twitter.com/flaximus/status/1291906337052524546

@simonw simonw added the enhancement New feature or request label Aug 8, 2020
@simonw simonw added this to the 1.0 milestone Aug 8, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

Or table_one?

@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

Or table_row? I'm not so keen on that as "row" is more of an implementation detail. Plus it doesn't necessarily make sense for views.

@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

But table_row is less characters than table_first.

@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

Options (using repos as an example table):

  • repos_get - it's a verb, nouns are better
  • repos_one - sure it returns just one result, but which one?
  • repos_first - clear that it returns the first result, but a little verbose
  • repos_row - it returns just one row
  • repos_single - verbose, first is one less letter

@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

Of these options, repos_one and repos_row are both noun-based and only three letters.

@simonw simonw changed the title Rename table_get to table_first Rename table_get to table_NOUN (nouns are better than verbs in GraphQL land) Aug 8, 2020
@aviflax
Copy link

aviflax commented Aug 8, 2020

What about _record or _rec ?

@aviflax
Copy link

aviflax commented Aug 9, 2020

FWIW, I still like row best, but apart from that, I like rec or record more than one

@simonw
Copy link
Owner Author

simonw commented Aug 9, 2020

Another option: _by

Tools like https://www.graphile.org/postgraphile/examples/ set up fields called forumBySlug - the current table_get method is essentially tableByPk but with more options:

{
  users_by(id: 12345) {
    name
  }
}

It would still support filter: and where: and search: - e.g.:

{
  by_search: users_by(search: "simonw") {
    name
  }
  by_filter: users_by(filter: {name: {eq: "simonw"}}) {
    name
  }  
}

@simonw
Copy link
Owner Author

simonw commented Aug 9, 2020

The problem with _by for single lookups is that it would also work as a name for the users field (which lets you filter users by criteria, but returns more than one result). So I don't like that option.

@simonw
Copy link
Owner Author

simonw commented Aug 9, 2020

I'm coming round to _row a bit more now.

@simonw
Copy link
Owner Author

simonw commented Aug 9, 2020

I'm going with _row.

@simonw simonw changed the title Rename table_get to table_NOUN (nouns are better than verbs in GraphQL land) Rename table_get to table_row (nouns are better than verbs in GraphQL land) Aug 9, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 9, 2020

A bunch of demo queries in https://github.com/simonw/datasette-graphql/blob/006238a7527ee3d7bc0e465d613ef36f6e062dd3/examples/table_row.md

{
  table_with_rowid_row(rowid: 1) {
    name
  }
  table_with_pk_row(pk: 1) {
    pk
    name
  }
  table_with_compound_pk_row(pk1:1, pk2:3) {
    name
    pk1
    pk2
  }
  users_row(id: 12345) {
    name
  }
}

simonw added a commit that referenced this issue Aug 9, 2020
@simonw simonw closed this as completed Aug 9, 2020
@aviflax
Copy link

aviflax commented Aug 9, 2020

My pleasure, looks great!

@simonw simonw modified the milestones: 1.0, Datasette 0.12 Aug 13, 2020
simonw added a commit that referenced this issue Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants