Skip to content

Commit

Permalink
No errors on empty schema, closes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 21, 2020
1 parent 7e5b793 commit 69eaab1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions datasette_graphql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ async def schema_for_database(datasette, database=None):
)
)

if not to_add:
# Empty schema throws a 500 error, so add something here
to_add.append(("empty", graphene.String()))
to_add.append(("resolve_empty", lambda a, b: "schema"))

Query = type(
"Query",
(graphene.ObjectType,),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ async def test_permissions(db_path, db_path2, metadata, expected):
assert response.status_code == expected_status


@pytest.mark.asyncio
async def test_no_error_on_empty_schema():
# https://github.com/simonw/datasette-graphql/issues/64
ds = Datasette([], memory=True)
response = await ds.client.get("/graphql", headers={"Accept": "text/html"})
assert response.status_code == 200


@pytest.mark.asyncio
async def test_table_action(db_path):
ds = Datasette([db_path])
Expand Down

0 comments on commit 69eaab1

Please sign in to comment.