Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cookies and auth headers #100

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +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-
cache: pip
cache-dependency-path: setup.py
- name: Install dependencies
run: |
pip install -e '.[test]'
Expand All @@ -33,18 +28,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
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
1 change: 1 addition & 0 deletions datasette_graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 12 additions & 3 deletions datasette_graphql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
)
Expand All @@ -592,8 +594,15 @@ async def resolve_table(
path_with_query_string,
)

data = (await datasette.client.get(path_with_query_string)).json()
data["rows"] = [dict(zip(data["columns"], row)) for row in data["rows"]]
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():
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup
import os

VERSION = "2.2"
VERSION = "3.0a0"


def get_long_description():
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down
Loading