simonw / datasette-graphql

Datasette plugin providing an automatic GraphQL API for your SQLite databases
https://datasette-graphql-demo.datasette.io/
Apache License 2.0
101 stars 6 forks source link

500 error on /graphql if no databases attached #64

Closed simonw closed 4 years ago

simonw commented 4 years ago

Very unimportant bug, but if you visit /graphql on an instance of Datasette started using datasette . without any attached databases you get this:

  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette/app.py", line 1033, in route_path
    response = await view(request, send)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette/app.py", line 1204, in async_view_fn
    response = await async_call_with_supported_arguments(
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette/utils/__init__.py", line 915, in async_call_with_supported_arguments
    return await fn(*call_with)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette_graphql/__init__.py", line 69, in view_graphql
    schema = await schema_for_database_via_cache(datasette, database=database)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette_graphql/utils.py", line 72, in schema_for_database_via_cache
    schema = await schema_for_database(datasette, database)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/datasette_graphql/utils.py", line 222, in schema_for_database
    return graphene.Schema(
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphene/types/schema.py", line 78, in __init__
    self.build_typemap()
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphene/types/schema.py", line 167, in build_typemap
    self._type_map = TypeMap(
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphene/types/typemap.py", line 80, in __init__
    super(TypeMap, self).__init__(types)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphql/type/typemap.py", line 31, in __init__
    self.update(reduce(self.reducer, types, OrderedDict()))  # type: ignore
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphene/types/typemap.py", line 88, in reducer
    return self.graphene_reducer(map, type)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphene/types/typemap.py", line 117, in graphene_reducer
    return GraphQLTypeMap.reducer(map, internal_type)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphql/type/typemap.py", line 109, in reducer
    field_map = type_.fields
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphql/pyutils/cached_property.py", line 22, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphql/type/definition.py", line 198, in fields
    return define_field_map(self, self._fields)
  File "/usr/local/Cellar/datasette/0.50.2/libexec/lib/python3.9/site-packages/graphql/type/definition.py", line 214, in define_field_map
    assert isinstance(field_map, Mapping) and len(field_map) > 0, (
AssertionError: Query fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping.