Closed simonw closed 4 years ago
Or table_one
?
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.
But table_row
is less characters than table_first
.
Options (using repos
as an example table):
repos_get
- it's a verb, nouns are betterrepos_one
- sure it returns just one result, but which one?repos_first
- clear that it returns the first result, but a little verboserepos_row
- it returns just one rowrepos_single
- verbose, first
is one less letterOf these options, repos_one
and repos_row
are both noun-based and only three letters.
What about _record
or _rec
?
FWIW, I still like row
best, but apart from that, I like rec
or record
more than one
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
}
}
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.
I'm coming round to _row
a bit more now.
I'm going with _row
.
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
}
}
That query in the live demo: I'm happy with this change. Thanks, @aviflax!
My pleasure, looks great!
GraphQL prefers nouns to verbs: https://twitter.com/flaximus/status/1291906337052524546