-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Doesn't work with authenticated Datasette instances #97
Comments
I set that instance up with https://datasette.io/datasette-auth-tokens and this config: plugins:
datasette-auth-tokens:
tokens:
- token: secret-token
actor:
id: bot
allow:
id:
- bot
- root |
Fixing this is actually quite hard. The The main problem is that it's part of the schema which is created in here: datasette-graphql/datasette_graphql/utils.py Lines 92 to 94 in c0ab66b
Specifically this bit: datasette-graphql/datasette_graphql/utils.py Lines 180 to 187 in c0ab66b
And the whole point of |
Maybe the answer lies here: datasette-graphql/datasette_graphql/__init__.py Lines 110 to 124 in c0ab66b
I could inject the |
OK, this seems to fix things: 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 @@ def make_table_resolver(
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(): I need to do a bunch of testing around this though. Including checking that the schema isn't being linked to users who should not be able to view it. |
The GraphQL explorer at least doesn't - you get this error:
Interesting that the API introspection DOES work, but the actual query execution does not.
The text was updated successfully, but these errors were encountered: