datasette-graphql 2.2__tar.gz → 3.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/PKG-INFO +23 -19
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/README.md +14 -14
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/__init__.py +8 -21
- datasette_graphql-3.0a1/datasette_graphql/static/LICENSES.md +7 -0
- datasette_graphql-3.0a1/datasette_graphql/static/fetch_latest.py +25 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/utils.py +15 -8
- datasette_graphql-3.0a1/pyproject.toml +36 -0
- datasette-graphql-2.2/datasette_graphql.egg-info/PKG-INFO +0 -505
- datasette-graphql-2.2/datasette_graphql.egg-info/SOURCES.txt +0 -23
- datasette-graphql-2.2/datasette_graphql.egg-info/dependency_links.txt +0 -1
- datasette-graphql-2.2/datasette_graphql.egg-info/entry_points.txt +0 -2
- datasette-graphql-2.2/datasette_graphql.egg-info/requires.txt +0 -8
- datasette-graphql-2.2/datasette_graphql.egg-info/top_level.txt +0 -1
- datasette-graphql-2.2/setup.cfg +0 -4
- datasette-graphql-2.2/setup.py +0 -41
- datasette-graphql-2.2/tests/test_docs.py +0 -78
- datasette-graphql-2.2/tests/test_graphql.py +0 -874
- datasette-graphql-2.2/tests/test_plugin_hook.py +0 -71
- datasette-graphql-2.2/tests/test_schema_caching.py +0 -64
- datasette-graphql-2.2/tests/test_schema_for_database.py +0 -31
- datasette-graphql-2.2/tests/test_template_tag.py +0 -56
- datasette-graphql-2.2/tests/test_utils.py +0 -17
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/hookspecs.py +0 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/static/graphiql.1.5.1.min.css +0 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/static/graphiql.1.5.1.min.js +0 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/static/react-dom.production.17.0.2.min.js +0 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/static/react.production.17.0.2.min.js +0 -0
- {datasette-graphql-2.2 → datasette_graphql-3.0a1}/datasette_graphql/templates/graphiql.html +0 -0
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: datasette-graphql
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0a1
|
|
4
4
|
Summary: Datasette plugin providing an automatic GraphQL API for your SQLite databases
|
|
5
|
-
Home-page: https://github.com/simonw/datasette-graphql
|
|
6
5
|
Author: Simon Willison
|
|
7
|
-
License: Apache
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Dist: datasette>=1.0a20
|
|
8
|
+
Requires-Dist: graphene>=3.1.0,<4.0
|
|
9
|
+
Requires-Dist: graphql-core>=3.2.1
|
|
10
|
+
Requires-Dist: sqlite-utils
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Project-URL: Homepage, https://github.com/simonw/datasette-graphql
|
|
8
13
|
Project-URL: Issues, https://github.com/simonw/datasette-graphql/issues
|
|
9
14
|
Project-URL: CI, https://github.com/simonw/datasette-graphql/actions
|
|
10
15
|
Project-URL: Changelog, https://github.com/simonw/datasette-graphql/releases
|
|
11
16
|
Description-Content-Type: text/markdown
|
|
12
|
-
Provides-Extra: test
|
|
13
17
|
|
|
14
18
|
# datasette-graphql
|
|
15
19
|
|
|
@@ -22,7 +26,7 @@ Provides-Extra: test
|
|
|
22
26
|
|
|
23
27
|
Read more about this project: [GraphQL in Datasette with the new datasette-graphql plugin](https://simonwillison.net/2020/Aug/7/datasette-graphql/)
|
|
24
28
|
|
|
25
|
-
Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://datasette-graphql-demo.datasette.io/graphql?query=%7B%0A%20%20repos(first%3A10%2C%20search%3A%20%22sql%22%2C%20sort_desc%3A%20created_at)%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%09stargazers_count%0A%20%20%20%20%20%20created_at%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20html_url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
29
|
+
<!-- Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://datasette-graphql-demo.datasette.io/graphql?query=%7B%0A%20%20repos(first%3A10%2C%20search%3A%20%22sql%22%2C%20sort_desc%3A%20created_at)%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%09stargazers_count%0A%20%20%20%20%20%20created_at%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20html_url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
26
30
|
|
|
27
31
|
<!-- toc -->
|
|
28
32
|
|
|
@@ -47,7 +51,7 @@ Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://dat
|
|
|
47
51
|
|
|
48
52
|
<!-- tocstop -->
|
|
49
53
|
|
|
50
|
-

|
|
51
55
|
|
|
52
56
|
## Installation
|
|
53
57
|
|
|
@@ -75,7 +79,7 @@ This plugin sets up `/graphql` as a GraphQL endpoint for the first attached data
|
|
|
75
79
|
|
|
76
80
|
If you have multiple attached databases each will get its own endpoint at `/graphql/name_of_database`.
|
|
77
81
|
|
|
78
|
-
The automatically generated GraphQL schema is available at `/graphql/name_of_database.graphql
|
|
82
|
+
The automatically generated GraphQL schema is available at `/graphql/name_of_database.graphql`<!-- - here's [an example](https://datasette-graphql-demo.datasette.io/graphql/github.graphql) -->.
|
|
79
83
|
|
|
80
84
|
### Querying for tables and columns
|
|
81
85
|
|
|
@@ -92,7 +96,7 @@ Individual tables (and SQL views) can be queried like this:
|
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
```
|
|
95
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
99
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
96
100
|
|
|
97
101
|
In this example query the underlying database table is called `repos` and its columns include `id`, `full_name` and `description`. Since `description` is a reserved word the query needs to ask for `description_` instead.
|
|
98
102
|
|
|
@@ -109,7 +113,7 @@ If you only want to fetch a single record - for example if you want to fetch a r
|
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
```
|
|
112
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos_row%28id%3A%20107914493%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20full_name%0A%20%20%20%20description_%0A%20%20%7D%0A%7D%0A)
|
|
116
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos_row%28id%3A%20107914493%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20full_name%0A%20%20%20%20description_%0A%20%20%7D%0A%7D%0A) -->
|
|
113
117
|
|
|
114
118
|
The `tablename_row` field accepts the primary key column (or columns) as arguments. It also supports the same `filter:`, `search:`, `sort:` and `sort_desc:` arguments as the `tablename` field, described below.
|
|
115
119
|
|
|
@@ -131,7 +135,7 @@ If a column is a foreign key to another table, you can request columns from the
|
|
|
131
135
|
}
|
|
132
136
|
}
|
|
133
137
|
```
|
|
134
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20login%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
138
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20login%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
135
139
|
|
|
136
140
|
### Accessing related objects
|
|
137
141
|
|
|
@@ -154,7 +158,7 @@ Consider a `users` table which is related to `repos` - a repo has a foreign key
|
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
```
|
|
157
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users%28first%3A%201%2C%20search%3A%20%22simonw%22%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20repos_by_owner_list%28first%3A%205%29%20%7B%0A%20%20%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
161
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users%28first%3A%201%2C%20search%3A%20%22simonw%22%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20repos_by_owner_list%28first%3A%205%29%20%7B%0A%20%20%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
158
162
|
|
|
159
163
|
|
|
160
164
|
### Filtering tables
|
|
@@ -174,7 +178,7 @@ You can filter the rows returned for a specific table using the `filter:` argume
|
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
```
|
|
177
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28filter%3A%20%7Blicense%3A%20%7Beq%3A%20%22apache-2.0%22%7D%2C%20stargazers_count%3A%20%7Bgt%3A%2010%7D%7D%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
181
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28filter%3A%20%7Blicense%3A%20%7Beq%3A%20%22apache-2.0%22%7D%2C%20stargazers_count%3A%20%7Bgt%3A%2010%7D%7D%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
178
182
|
|
|
179
183
|
See [table filters examples](https://github.com/simonw/datasette-graphql/blob/main/examples/filters.md) for more operations, and [column filter arguments](https://docs.datasette.io/en/stable/json_api.html#column-filter-arguments) in the Datasette documentation for details of how those operations work.
|
|
180
184
|
|
|
@@ -193,7 +197,7 @@ These same filters can be used on nested relationships, like so:
|
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
```
|
|
196
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users_row%28id%3A%209599%29%20%7B%0A%20%20%20%20name%0A%20%20%20%20repos_by_owner_list%28filter%3A%20%7Bname%3A%20%7Bstartswith%3A%20%22datasette-%22%7D%7D%29%20%7B%0A%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
200
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users_row%28id%3A%209599%29%20%7B%0A%20%20%20%20name%0A%20%20%20%20repos_by_owner_list%28filter%3A%20%7Bname%3A%20%7Bstartswith%3A%20%22datasette-%22%7D%7D%29%20%7B%0A%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
197
201
|
|
|
198
202
|
|
|
199
203
|
The `where:` argument can be used as an alternative to `filter:` when the thing you are expressing is too complex to be modeled using a filter expression. It accepts a string fragment of SQL that will be included in the `WHERE` clause of the SQL query.
|
|
@@ -208,7 +212,7 @@ The `where:` argument can be used as an alternative to `filter:` when the thing
|
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
```
|
|
211
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28where%3A%20%22name%3D%27sqlite-utils%27%20or%20name%20like%20%27datasette-%25%27%22%29%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
215
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28where%3A%20%22name%3D%27sqlite-utils%27%20or%20name%20like%20%27datasette-%25%27%22%29%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
212
216
|
|
|
213
217
|
### Sorting
|
|
214
218
|
|
|
@@ -224,7 +228,7 @@ You can set a sort order for results from a table using the `sort:` or `sort_des
|
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
230
|
```
|
|
227
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28sort_desc%3A%20stargazers_count%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
231
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28sort_desc%3A%20stargazers_count%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
228
232
|
|
|
229
233
|
### Pagination
|
|
230
234
|
|
|
@@ -248,7 +252,7 @@ By default the first 10 rows will be returned. You can control this using the `f
|
|
|
248
252
|
}
|
|
249
253
|
}
|
|
250
254
|
```
|
|
251
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
255
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
252
256
|
|
|
253
257
|
The `totalCount` field returns the total number of records that match the query.
|
|
254
258
|
|
|
@@ -272,7 +276,7 @@ Requesting the `pageInfo.endCursor` field provides you with the value you need t
|
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
```
|
|
275
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%2C%20after%3A%20%22134874019%22%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
279
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%2C%20after%3A%20%22134874019%22%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
276
280
|
|
|
277
281
|
The `hasNextPage` field tells you if there are any more records.
|
|
278
282
|
|
|
@@ -295,7 +299,7 @@ If a table has been configured to use SQLite full-text search you can execute se
|
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
301
|
```
|
|
298
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28search%3A%20%22datasette%22%29%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%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
302
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28search%3A%20%22datasette%22%29%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%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
299
303
|
|
|
300
304
|
The [sqlite-utils](https://sqlite-utils.datasette.io/) Python library and CLI tool can be used to add full-text search to an existing database table.
|
|
301
305
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Read more about this project: [GraphQL in Datasette with the new datasette-graphql plugin](https://simonwillison.net/2020/Aug/7/datasette-graphql/)
|
|
11
11
|
|
|
12
|
-
Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://datasette-graphql-demo.datasette.io/graphql?query=%7B%0A%20%20repos(first%3A10%2C%20search%3A%20%22sql%22%2C%20sort_desc%3A%20created_at)%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%09stargazers_count%0A%20%20%20%20%20%20created_at%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20html_url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
12
|
+
<!-- Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://datasette-graphql-demo.datasette.io/graphql?query=%7B%0A%20%20repos(first%3A10%2C%20search%3A%20%22sql%22%2C%20sort_desc%3A%20created_at)%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20pageInfo%20%7B%0A%20%20%20%20%20%20endCursor%0A%20%20%20%20%20%20hasNextPage%0A%20%20%20%20%7D%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%09stargazers_count%0A%20%20%20%20%20%20created_at%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20html_url%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
13
13
|
|
|
14
14
|
<!-- toc -->
|
|
15
15
|
|
|
@@ -34,7 +34,7 @@ Try out a live demo at [datasette-graphql-demo.datasette.io/graphql](https://dat
|
|
|
34
34
|
|
|
35
35
|
<!-- tocstop -->
|
|
36
36
|
|
|
37
|
-

|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
@@ -62,7 +62,7 @@ This plugin sets up `/graphql` as a GraphQL endpoint for the first attached data
|
|
|
62
62
|
|
|
63
63
|
If you have multiple attached databases each will get its own endpoint at `/graphql/name_of_database`.
|
|
64
64
|
|
|
65
|
-
The automatically generated GraphQL schema is available at `/graphql/name_of_database.graphql
|
|
65
|
+
The automatically generated GraphQL schema is available at `/graphql/name_of_database.graphql`<!-- - here's [an example](https://datasette-graphql-demo.datasette.io/graphql/github.graphql) -->.
|
|
66
66
|
|
|
67
67
|
### Querying for tables and columns
|
|
68
68
|
|
|
@@ -79,7 +79,7 @@ Individual tables (and SQL views) can be queried like this:
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
```
|
|
82
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
82
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
83
83
|
|
|
84
84
|
In this example query the underlying database table is called `repos` and its columns include `id`, `full_name` and `description`. Since `description` is a reserved word the query needs to ask for `description_` instead.
|
|
85
85
|
|
|
@@ -96,7 +96,7 @@ If you only want to fetch a single record - for example if you want to fetch a r
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
```
|
|
99
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos_row%28id%3A%20107914493%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20full_name%0A%20%20%20%20description_%0A%20%20%7D%0A%7D%0A)
|
|
99
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos_row%28id%3A%20107914493%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20full_name%0A%20%20%20%20description_%0A%20%20%7D%0A%7D%0A) -->
|
|
100
100
|
|
|
101
101
|
The `tablename_row` field accepts the primary key column (or columns) as arguments. It also supports the same `filter:`, `search:`, `sort:` and `sort_desc:` arguments as the `tablename` field, described below.
|
|
102
102
|
|
|
@@ -118,7 +118,7 @@ If a column is a foreign key to another table, you can request columns from the
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20login%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
121
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20owner%20%7B%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20login%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
122
122
|
|
|
123
123
|
### Accessing related objects
|
|
124
124
|
|
|
@@ -141,7 +141,7 @@ Consider a `users` table which is related to `repos` - a repo has a foreign key
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users%28first%3A%201%2C%20search%3A%20%22simonw%22%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20repos_by_owner_list%28first%3A%205%29%20%7B%0A%20%20%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
144
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users%28first%3A%201%2C%20search%3A%20%22simonw%22%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20repos_by_owner_list%28first%3A%205%29%20%7B%0A%20%20%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
### Filtering tables
|
|
@@ -161,7 +161,7 @@ You can filter the rows returned for a specific table using the `filter:` argume
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
```
|
|
164
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28filter%3A%20%7Blicense%3A%20%7Beq%3A%20%22apache-2.0%22%7D%2C%20stargazers_count%3A%20%7Bgt%3A%2010%7D%7D%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
164
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28filter%3A%20%7Blicense%3A%20%7Beq%3A%20%22apache-2.0%22%7D%2C%20stargazers_count%3A%20%7Bgt%3A%2010%7D%7D%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
165
165
|
|
|
166
166
|
See [table filters examples](https://github.com/simonw/datasette-graphql/blob/main/examples/filters.md) for more operations, and [column filter arguments](https://docs.datasette.io/en/stable/json_api.html#column-filter-arguments) in the Datasette documentation for details of how those operations work.
|
|
167
167
|
|
|
@@ -180,7 +180,7 @@ These same filters can be used on nested relationships, like so:
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
```
|
|
183
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users_row%28id%3A%209599%29%20%7B%0A%20%20%20%20name%0A%20%20%20%20repos_by_owner_list%28filter%3A%20%7Bname%3A%20%7Bstartswith%3A%20%22datasette-%22%7D%7D%29%20%7B%0A%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
183
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20users_row%28id%3A%209599%29%20%7B%0A%20%20%20%20name%0A%20%20%20%20repos_by_owner_list%28filter%3A%20%7Bname%3A%20%7Bstartswith%3A%20%22datasette-%22%7D%7D%29%20%7B%0A%20%20%20%20%20%20totalCount%0A%20%20%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
184
184
|
|
|
185
185
|
|
|
186
186
|
The `where:` argument can be used as an alternative to `filter:` when the thing you are expressing is too complex to be modeled using a filter expression. It accepts a string fragment of SQL that will be included in the `WHERE` clause of the SQL query.
|
|
@@ -195,7 +195,7 @@ The `where:` argument can be used as an alternative to `filter:` when the thing
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
```
|
|
198
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28where%3A%20%22name%3D%27sqlite-utils%27%20or%20name%20like%20%27datasette-%25%27%22%29%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
198
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28where%3A%20%22name%3D%27sqlite-utils%27%20or%20name%20like%20%27datasette-%25%27%22%29%20%7B%0A%20%20%20%20totalCount%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
199
199
|
|
|
200
200
|
### Sorting
|
|
201
201
|
|
|
@@ -211,7 +211,7 @@ You can set a sort order for results from a table using the `sort:` or `sort_des
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
```
|
|
214
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28sort_desc%3A%20stargazers_count%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
214
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28sort_desc%3A%20stargazers_count%29%20%7B%0A%20%20%20%20nodes%20%7B%0A%20%20%20%20%20%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
215
215
|
|
|
216
216
|
### Pagination
|
|
217
217
|
|
|
@@ -235,7 +235,7 @@ By default the first 10 rows will be returned. You can control this using the `f
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
```
|
|
238
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
238
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
239
239
|
|
|
240
240
|
The `totalCount` field returns the total number of records that match the query.
|
|
241
241
|
|
|
@@ -259,7 +259,7 @@ Requesting the `pageInfo.endCursor` field provides you with the value you need t
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
```
|
|
262
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%2C%20after%3A%20%22134874019%22%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
262
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28first%3A%2020%2C%20after%3A%20%22134874019%22%29%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%20full_name%0A%20%20%20%20%20%20stargazers_count%0A%20%20%20%20%20%20license%20%7B%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
263
263
|
|
|
264
264
|
The `hasNextPage` field tells you if there are any more records.
|
|
265
265
|
|
|
@@ -282,7 +282,7 @@ If a table has been configured to use SQLite full-text search you can execute se
|
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
```
|
|
285
|
-
[Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28search%3A%20%22datasette%22%29%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%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
|
|
285
|
+
<!-- [Try this query](https://datasette-graphql-demo.datasette.io/graphql?query=%0A%7B%0A%20%20repos%28search%3A%20%22datasette%22%29%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%20full_name%0A%20%20%20%20%20%20description_%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A) -->
|
|
286
286
|
|
|
287
287
|
The [sqlite-utils](https://sqlite-utils.datasette.io/) Python library and CLI tool can be used to add full-text search to an existing database table.
|
|
288
288
|
|
|
@@ -2,6 +2,7 @@ from click import ClickException
|
|
|
2
2
|
from datasette import hookimpl
|
|
3
3
|
from datasette.utils.asgi import Response, NotFound, Forbidden
|
|
4
4
|
from datasette.plugins import pm
|
|
5
|
+
from datasette.resources import DatabaseResource
|
|
5
6
|
from graphql import graphql, print_schema
|
|
6
7
|
import json
|
|
7
8
|
from .utils import schema_for_database_via_cache
|
|
@@ -133,27 +134,13 @@ async def view_graphql(request, datasette):
|
|
|
133
134
|
|
|
134
135
|
|
|
135
136
|
async def check_permissions(request, datasette, database):
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
request.actor,
|
|
139
|
-
"view-database",
|
|
140
|
-
resource=database,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if ok is not None:
|
|
144
|
-
if ok:
|
|
145
|
-
return
|
|
146
|
-
else:
|
|
147
|
-
raise Forbidden("view-database")
|
|
148
|
-
|
|
149
|
-
# Fall back to checking instance permission
|
|
150
|
-
ok2 = await datasette.permission_allowed(
|
|
151
|
-
request.actor,
|
|
152
|
-
"view-instance",
|
|
153
|
-
default=None,
|
|
154
|
-
)
|
|
155
|
-
if ok2 is False:
|
|
156
|
-
raise Forbidden("view-instance")
|
|
137
|
+
# Check database permission - this already incorporates instance-level permissions
|
|
138
|
+
if not await datasette.allowed(
|
|
139
|
+
actor=request.actor,
|
|
140
|
+
action="view-database",
|
|
141
|
+
resource=DatabaseResource(database),
|
|
142
|
+
):
|
|
143
|
+
raise Forbidden("view-database")
|
|
157
144
|
|
|
158
145
|
|
|
159
146
|
@hookimpl
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Licenses
|
|
2
|
+
|
|
3
|
+
The files bundled in this directory are covered by the following licenses:
|
|
4
|
+
|
|
5
|
+
- `fetch.min.js` is covered by this MIT license: https://github.com/github/fetch/blob/master/LICENSE
|
|
6
|
+
- `graphiql.css` and `graphiql.min.js` are covered by this MIT license: https://github.com/graphql/graphiql/blob/main/LICENSE
|
|
7
|
+
- `react-dom.production.min.js` and `react.production.min.js` are covered by this MIT license: https://github.com/facebook/react/blob/master/LICENSE
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
urls = (
|
|
4
|
+
"https://unpkg.com/react/umd/react.production.min.js",
|
|
5
|
+
"https://unpkg.com/react-dom/umd/react-dom.production.min.js",
|
|
6
|
+
"https://unpkg.com/graphiql/graphiql.min.css",
|
|
7
|
+
"https://unpkg.com/graphiql/graphiql.min.js",
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def fetch(url):
|
|
12
|
+
final_url = httpx.get(url).next_request.url
|
|
13
|
+
content = httpx.get(final_url).text
|
|
14
|
+
version = str(final_url).split("@")[1].split("/")[0]
|
|
15
|
+
filename = str(final_url).split("/")[-1]
|
|
16
|
+
# Insert version into filename
|
|
17
|
+
bits = filename.split(".min.")
|
|
18
|
+
version_filename = f".{version}.min.".join(bits)
|
|
19
|
+
open(version_filename, "w").write(content)
|
|
20
|
+
print(version_filename)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
for url in urls:
|
|
25
|
+
fetch(url)
|
|
@@ -93,9 +93,18 @@ async def schema_for_database(datasette, database=None):
|
|
|
93
93
|
db = datasette.get_database(database)
|
|
94
94
|
hidden_tables = await db.hidden_table_names()
|
|
95
95
|
|
|
96
|
+
# First get all table configs (async)
|
|
97
|
+
table_names = await db.table_names()
|
|
98
|
+
view_names = await db.view_names()
|
|
99
|
+
table_configs = {}
|
|
100
|
+
for table in table_names + view_names:
|
|
101
|
+
table_configs[table] = await datasette.table_config(
|
|
102
|
+
table=table, database=db.name
|
|
103
|
+
)
|
|
104
|
+
|
|
96
105
|
# Perform all introspection in a single call to the execute_fn thread
|
|
97
106
|
table_metadata = await db.execute_fn(
|
|
98
|
-
lambda conn: introspect_tables(conn, datasette, db.name)
|
|
107
|
+
lambda conn: introspect_tables(conn, datasette, db.name, table_configs)
|
|
99
108
|
)
|
|
100
109
|
|
|
101
110
|
# Construct the tableFilter classes
|
|
@@ -270,7 +279,7 @@ def make_table_collection_class(table, table_class, meta):
|
|
|
270
279
|
edges = graphene.List(_Edge)
|
|
271
280
|
|
|
272
281
|
def resolve_totalCount(parent, info):
|
|
273
|
-
return parent["
|
|
282
|
+
return parent["count"]
|
|
274
283
|
|
|
275
284
|
def resolve_nodes(parent, info):
|
|
276
285
|
return parent["rows"]
|
|
@@ -545,6 +554,7 @@ def make_table_resolver(
|
|
|
545
554
|
|
|
546
555
|
qs = {
|
|
547
556
|
"_nofacet": 1,
|
|
557
|
+
"_extra": "columns,count",
|
|
548
558
|
}
|
|
549
559
|
qs.update(pairs)
|
|
550
560
|
if after:
|
|
@@ -593,7 +603,6 @@ def make_table_resolver(
|
|
|
593
603
|
)
|
|
594
604
|
|
|
595
605
|
data = (await datasette.client.get(path_with_query_string)).json()
|
|
596
|
-
data["rows"] = [dict(zip(data["columns"], row)) for row in data["rows"]]
|
|
597
606
|
# If any cells are $base64, decode them into bytes objects
|
|
598
607
|
for row in data["rows"]:
|
|
599
608
|
for key, value in row.items():
|
|
@@ -659,7 +668,7 @@ def path_from_row_pks(row, pks, use_rowid, quote=True):
|
|
|
659
668
|
return ",".join(bits)
|
|
660
669
|
|
|
661
670
|
|
|
662
|
-
def introspect_tables(conn, datasette, db_name):
|
|
671
|
+
def introspect_tables(conn, datasette, db_name, table_configs):
|
|
663
672
|
db = sqlite_utils.Database(conn)
|
|
664
673
|
|
|
665
674
|
table_names = db.table_names()
|
|
@@ -669,13 +678,11 @@ def introspect_tables(conn, datasette, db_name):
|
|
|
669
678
|
table_namer = Namer("t")
|
|
670
679
|
|
|
671
680
|
for table in table_names + view_names:
|
|
672
|
-
|
|
673
|
-
table=table, database=db_name
|
|
674
|
-
)
|
|
681
|
+
datasette_table_config = table_configs.get(table, {})
|
|
675
682
|
columns = db[table].columns_dict
|
|
676
683
|
foreign_keys = []
|
|
677
684
|
pks = []
|
|
678
|
-
supports_fts = bool(
|
|
685
|
+
supports_fts = bool(datasette_table_config.get("fts_table"))
|
|
679
686
|
fks_back = []
|
|
680
687
|
if hasattr(db[table], "foreign_keys"):
|
|
681
688
|
# Views don't have .foreign_keys
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "datasette-graphql"
|
|
3
|
+
version = "3.0a1"
|
|
4
|
+
description = "Datasette plugin providing an automatic GraphQL API for your SQLite databases"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{name = "Simon Willison"}]
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"datasette>=1.0a20",
|
|
11
|
+
"graphene>=3.1.0,<4.0",
|
|
12
|
+
"graphql-core>=3.2.1",
|
|
13
|
+
"sqlite-utils",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://github.com/simonw/datasette-graphql"
|
|
18
|
+
Issues = "https://github.com/simonw/datasette-graphql/issues"
|
|
19
|
+
CI = "https://github.com/simonw/datasette-graphql/actions"
|
|
20
|
+
Changelog = "https://github.com/simonw/datasette-graphql/releases"
|
|
21
|
+
|
|
22
|
+
[project.entry-points.datasette]
|
|
23
|
+
graphql = "datasette_graphql"
|
|
24
|
+
|
|
25
|
+
[dependency-groups]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest",
|
|
28
|
+
"pytest-asyncio",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.9.18,<1"]
|
|
33
|
+
build-backend = "uv_build"
|
|
34
|
+
|
|
35
|
+
[tool.uv.build-backend]
|
|
36
|
+
module-root = ""
|