simonw / datasette-graphql

Datasette plugin providing an automatic GraphQL API for your SQLite databases
https://datasette-graphql-demo.datasette.io/
Apache License 2.0
101 stars 6 forks source link

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

Closed simonw closed 4 years ago

simonw commented 4 years ago

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

simonw commented 4 years ago

Or table_one?

simonw commented 4 years ago

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 commented 4 years ago

But table_row is less characters than table_first.

simonw commented 4 years ago

Options (using repos as an example table):

simonw commented 4 years ago

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

aviflax commented 4 years ago

What about _record or _rec ?

aviflax commented 4 years ago

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

simonw commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

simonw commented 4 years ago

I'm going with _row.

simonw commented 4 years ago

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 commented 4 years ago

That query in the live demo: I'm happy with this change. Thanks, @aviflax!

https://datasette-graphql-demo.datasette.io/graphql/fixtures?query=%7B%0A%20%20table_with_rowid_row(rowid%3A%201)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%20%20table_with_pk_row(pk%3A%201)%20%7B%0A%20%20%20%20pk%0A%20%20%20%20name%0A%20%20%7D%0A%20%20table_with_compound_pk_row(pk1%3A1%2C%20pk2%3A3)%20%7B%0A%20%20%20%20name%0A%20%20%20%20pk1%0A%20%20%20%20pk2%0A%20%20%7D%0A%20%20users_row(id%3A%2012345)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D

aviflax commented 4 years ago

My pleasure, looks great!