From 3bdcba825149b00ab86be6697ef9062026864ccd Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 7 Sep 2023 09:43:28 -0700 Subject: [PATCH 1/5] Fixes for Datasette 1.0 API changes, refs #96 --- datasette_graphql/utils.py | 5 +++-- setup.py | 2 +- tests/test_graphql.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/datasette_graphql/utils.py b/datasette_graphql/utils.py index d38087a..9eeb358 100644 --- a/datasette_graphql/utils.py +++ b/datasette_graphql/utils.py @@ -270,7 +270,7 @@ class _TableCollection(graphene.ObjectType): edges = graphene.List(_Edge) def resolve_totalCount(parent, info): - return parent["filtered_table_rows_count"] + return parent["count"] def resolve_nodes(parent, info): return parent["rows"] @@ -570,6 +570,8 @@ async def resolve_table( elif sort_desc: qs["_sort_desc"] = column_name_rev[sort_desc.value] + qs["_extra"] = "count" + path_with_query_string = "/{}/{}.json?{}".format( database_name, table_name, urllib.parse.urlencode(qs) ) @@ -593,7 +595,6 @@ async def resolve_table( ) data = (await datasette.client.get(path_with_query_string)).json() - data["rows"] = [dict(zip(data["columns"], row)) for row in data["rows"]] # If any cells are $base64, decode them into bytes objects for row in data["rows"]: for key, value in row.items(): diff --git a/setup.py b/setup.py index 46d68c2..34c38a7 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def get_long_description(): packages=["datasette_graphql"], entry_points={"datasette": ["graphql = datasette_graphql"]}, install_requires=[ - "datasette>=0.58.1", + "datasette>=1.0a5", "graphene>=3.1.0,<4.0", "graphql-core>=3.2.1", "sqlite-utils", diff --git a/tests/test_graphql.py b/tests/test_graphql.py index 5402ba8..cf33b56 100644 --- a/tests/test_graphql.py +++ b/tests/test_graphql.py @@ -537,7 +537,7 @@ async def test_time_limit_ms(db_path): assert len(response_json["errors"]) == 1 assert response_json["errors"][0]["message"].startswith("Time limit exceeded: ") assert response_json["errors"][0]["message"].endswith( - " > 0.1ms - /test/repos.json?_nofacet=1&_size=10&_search=dogspotter" + " > 0.1ms - /test/repos.json?_nofacet=1&_size=10&_search=dogspotter&_extra=count" ) From e7617a846702cd4d710fc453603b4e341f9b7ec2 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 7 Sep 2023 09:47:17 -0700 Subject: [PATCH 2/5] Upgrade GitHub Actions, drop 3.7 - refs #96 --- .github/workflows/publish.yml | 31 +++++++++---------------------- .github/workflows/test.yml | 15 +++++---------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 12d1e00..4c28a89 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,23 +9,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - uses: actions/cache@v2 - name: Configure pip caching - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Install dependencies - run: | - pip install -e '.[test]' + cache: pip + cache-dependency-path: setup.py - name: Run tests run: | pytest @@ -33,18 +25,13 @@ jobs: runs-on: ubuntu-latest needs: [test] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.11' - - uses: actions/cache@v2 - name: Configure pip caching - with: - path: ~/.cache/pip - key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/setup.py') }} - restore-keys: | - ${{ runner.os }}-publish-pip- + cache: pip + cache-dependency-path: setup.py - name: Install dependencies run: | pip install setuptools wheel twine build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c42f0d0..a923917 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,20 +7,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - uses: actions/cache@v2 - name: Configure pip caching - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} - restore-keys: | - ${{ runner.os }}-pip- + cache: pip + cache-dependency-path: setup.py - name: Install dependencies run: | pip install -e '.[test]' From 3f5237608b103d7a477738032954c03554f93c18 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 7 Sep 2023 09:47:54 -0700 Subject: [PATCH 3/5] 3.0a0 alpha release, refs #96 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 34c38a7..5cd2ca0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup import os -VERSION = "2.2" +VERSION = "3.0a0" def get_long_description(): From c0ab66bc34a2cc65df2585cf9894d6f4c6db6186 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 7 Sep 2023 09:50:57 -0700 Subject: [PATCH 4/5] Install test dependencies on publish, refs #96 --- .github/workflows/publish.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c28a89..3b81eca 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,6 +18,9 @@ jobs: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: setup.py + - name: Install dependencies + run: | + pip install -e '.[test]' - name: Run tests run: | pytest From 0b9fac69399f1a5495712cef19f8d4bb547de4b8 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 7 Feb 2024 13:10:11 -0800 Subject: [PATCH 5/5] WIP forward auth headers --- datasette_graphql/__init__.py | 1 + datasette_graphql/utils.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/datasette_graphql/__init__.py b/datasette_graphql/__init__.py index d02262f..ac18ce6 100644 --- a/datasette_graphql/__init__.py +++ b/datasette_graphql/__init__.py @@ -113,6 +113,7 @@ async def view_graphql(request, datasette): "num_queries_executed": 0, "num_queries_limit": config.get("num_queries_limit") or DEFAULT_NUM_QUERIES_LIMIT, + "request": request, # For authentication headers } result = await schema.execute_async( diff --git a/datasette_graphql/utils.py b/datasette_graphql/utils.py index 9eeb358..c346ded 100644 --- a/datasette_graphql/utils.py +++ b/datasette_graphql/utils.py @@ -594,7 +594,15 @@ async def resolve_table( path_with_query_string, ) - data = (await datasette.client.get(path_with_query_string)).json() + headers = context["request"].headers + cookies = context["request"].cookies + + response = await datasette.client.get( + path_with_query_string, headers=headers, cookies=cookies + ) + if response.status_code != 200: + raise Exception(str(response.status_code) + response.text) + data = response.json() # If any cells are $base64, decode them into bytes objects for row in data["rows"]: for key, value in row.items():