Skip to content

Commit

Permalink
Use datasette.client instead of calling TableView
Browse files Browse the repository at this point in the history
Closes #61
  • Loading branch information
simonw authored Jun 7, 2021
1 parent e705588 commit 289484d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
29 changes: 7 additions & 22 deletions datasette_graphql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,20 +483,6 @@ async def example_query():
return type(meta.graphql_name, (graphene.ObjectType,), table_dict)


class DatasetteSpecialConfig(wrapt.ObjectProxy):
_overrides = {"suggest_facets": False}

def config(self, key):
if key in self._overrides:
return self._overrides[key]
return self.__wrapped__.config(key)

def setting(self, key):
if key in self._overrides:
return self._overrides[key]
return self.__wrapped__.setting(key)


def make_table_resolver(
datasette,
database_name,
Expand All @@ -507,8 +493,6 @@ def make_table_resolver(
pk_args=None,
return_first_row=False,
):
from datasette.views.table import TableView

meta = table_metadata[table_name]

async def resolve_table(
Expand Down Expand Up @@ -597,12 +581,13 @@ async def resolve_table(
path_with_query_string,
)

request = Request.fake(path_with_query_string)

view = TableView(DatasetteSpecialConfig(datasette))
data, _, _ = await view.data(
request, database=database_name, hash=None, table=table_name, _next=after
)
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():
if isinstance(value, dict) and value.get("$base64"):
row[key] = b64decode(value["encoded"])
klass = table_classes[table_name]
data["rows"] = [klass.from_row(r) for r in data["rows"]]
if return_first_row:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_long_description():
version=VERSION,
packages=["datasette_graphql"],
entry_points={"datasette": ["graphql = datasette_graphql"]},
install_requires=["datasette>=0.51", "graphene>=2.0,<3.0", "sqlite-utils", "wrapt"],
install_requires=["datasette>=0.57", "graphene>=2.0,<3.0", "sqlite-utils", "wrapt"],
extras_require={"test": ["pytest", "pytest-asyncio", "httpx"]},
tests_require=["datasette-graphql[test]"],
package_data={"datasette_graphql": ["templates/*.html", "static/*"]},
Expand Down
6 changes: 4 additions & 2 deletions tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ async def test_graphql_error(ds):
async def test_graphql_auto_camelcase(db_path2, on, expected):
_schema_cache.clear()
ds = Datasette(
[db_path2], metadata={"plugins": {"datasette-graphql": {"auto_camelcase": on}}}
[str(db_path2)],
pdb=True,
metadata={"plugins": {"datasette-graphql": {"auto_camelcase": on}}},
)
query = """
{
Expand Down Expand Up @@ -275,7 +277,7 @@ async def test_graphql_pagination(ds, table):

@pytest.mark.asyncio
async def test_graphql_multiple_databases(db_path, db_path2):
ds = Datasette([db_path, db_path2])
ds = Datasette([str(db_path), str(db_path2)])
query = """
{
test_table {
Expand Down

0 comments on commit 289484d

Please sign in to comment.