Closed simonw closed 3 years ago
Here's a better query, using the label logic:
{
contributors {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
contributions
repo_id {
id
name
}
user_id {
id
name
}
}
}
}
await db.label_column_for_table(table)
is the documented method for finding the label column (if one exists): https://docs.datasette.io/en/stable/internals.html#database-introspection
Demo: https://datasette-graphql-demo.datasette.io/github/issue_comments now has a link in the cog table actions menu to this: https://datasette-graphql-demo.datasette.io/graphql/github?query=%7B%0A%20%20issue_comments%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20html_url%0A%20%20%20%20%20%20issue_url%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20node_id%0A%20%20%20%20%20%20created_at%0A%20%20%20%20%20%20updated_at%0A%20%20%20%20%20%20author_association%0A%20%20%20%20%20%20body%0A%20%20%20%20%20%20reactions%0A%20%20%20%20%20%20performed_via_github_app%0A%20%20%20%20%20%20user%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20issue%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20title%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D
{
issue_comments {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
html_url
issue_url
id
node_id
created_at
updated_at
author_association
body
reactions
performed_via_github_app
user {
id
name
}
issue {
id
title
}
}
}
}
The demo on https://datasette-graphql-demo.datasette.io/fixtures/repos shows how it correctly converts columns with invalid-to-GraphQL names like $key
into a safe GraphQL name _key
:
{
repos {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
id
full_name
name
tags
owner {
id
name
}
license {
_key
name
}
}
}
}
https://datasette-graphql-demo.datasette.io/github/contributors links to this example query: https://datasette-graphql-demo.datasette.io/graphql/github?query=%7B%0A%20%20contributors%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20contributions%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D
It omits the foreign keys which for a many-to-many table are the most interesting things about it!