Repository: edgedb/edgedb

Issue:
ISE on querying BaseObject with graphql
query:

```
{
  BaseObject {id}
}
```

error:

```
1. AttributeError: 'NoneType' object has no attribute 'dummy'

-------------------------------------------------------------- Traceback --------------------------------------------------------------

    /Users/yury/dev/edge/edgedb/edb/server/compiler_pool/worker.py, line 209, in compile_graphql
        > return graphql.compile_graphql(
    /Users/yury/dev/edge/edgedb/edb/graphql/compiler.py, line 83, in compile_graphql
        > op = graphql.translate_ast(
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 1752, in translate_ast
        > edge_forest_map = GraphQLTranslator(context=context).visit(document_ast)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 193, in visit
        > return self.node_visit(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 186, in node_visit
        > result = visitor(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 252, in visit_DocumentNode
        > for d in self.visit(node.definitions)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 191, in visit
        > return [self.node_visit(n) for n in node]
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 191, in <listcomp>
        > return [self.node_visit(n) for n in node]
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 186, in node_visit
        > result = visitor(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 318, in visit_OperationDefinitionNode
        > stmt = self._visit_query(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 363, in _visit_query
        > query.result.elements = self.visit(node.selection_set)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 193, in visit
        > return self.node_visit(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 186, in node_visit
        > result = visitor(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 451, in visit_SelectionSetNode
        > spec = self.visit(sel)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 193, in visit
        > return self.node_visit(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 186, in node_visit
        > result = visitor(node)
    /Users/yury/dev/edge/edgedb/edb/graphql/translator.py, line 542, in visit_FieldNode
        > if not prevt.dummy and target.dummy:

AttributeError: 'NoneType' object has no attribute 'dummy'
```


Discussion:

Resolving patch:
diff --git a/edb/graphql/types.py b/edb/graphql/types.py
--- a/edb/graphql/types.py
+++ b/edb/graphql/types.py
@@ -1720,9 +1720,17 @@ def __init__(
         self.modules = schema.modules
         super().__init__(schema, name=name, edb_base=edb_base, dummy=dummy)
         self._shadow_fields = ('__typename',)
+        # Record names of std built-in object types
+        self._std_obj_names = [
+            t.get_name(self.edb_schema).name for t in
+            self.edb_schema.get_objects(
+                included_modules=[s_name.UnqualName('std')],
+                type=s_objtypes.ObjectType,
+            )
+        ]
 
     def get_module_and_name(self, name: str) -> Tuple[str, ...]:
-        if name == 'Object':
+        if name in self._std_obj_names:
             return ('std', name)
         elif '__' in name:
             return tuple(name.split('__', 1))


Test patch:
diff --git a/tests/test_http_graphql_query.py b/tests/test_http_graphql_query.py
--- a/tests/test_http_graphql_query.py
+++ b/tests/test_http_graphql_query.py
@@ -557,6 +557,28 @@ def test_graphql_functional_query_18(self):
             }],
         })
 
+    def test_graphql_functional_query_19(self):
+        # Test built-in object types, by making sure we can query them
+        # and get some results.
+        res = self.graphql_query(r"""
+            {
+                Object {id}
+            }
+        """)
+        self.assertTrue(len(res) > 0,
+                        'querying "Object" returned no results')
+
+    def test_graphql_functional_query_20(self):
+        # Test built-in object types, by making sure we can query them
+        # and get some results.
+        res = self.graphql_query(r"""
+            {
+                BaseObject {id}
+            }
+        """)
+        self.assertTrue(len(res) > 0,
+                        'querying "BaseObject" returned no results')
+
     def test_graphql_functional_alias_01(self):
         self.assert_graphql_query_result(
             r"""