Repository: polygraph-python/polygraph

Issue:
ObjectType type definition

Discussion:

Patch:
diff --git a/polygraph/types/basic_type.py b/polygraph/types/basic_type.py
index 6cbce15..7e889d1 100644
--- a/polygraph/types/basic_type.py
+++ b/polygraph/types/basic_type.py
@@ -4,6 +4,14 @@ from polygraph.types.definitions import TypeDefinition, TypeKind
 from polygraph.utils.trim_docstring import trim_docstring
 
 
+def get_field_list(namespace):
+    return [
+        value.__field__
+        for value in namespace.values()
+        if hasattr(value, "__field__")
+    ]
+
+
 class PolygraphTypeMeta(type):
     def __new__(cls, name, bases, namespace):
         default_description = trim_docstring(namespace.get("__doc__", ""))
@@ -22,7 +30,7 @@ class PolygraphTypeMeta(type):
                 kind=getattr(meta, "kind"),
                 name=getattr(meta, "name", name) or name,
                 description=getattr(meta, "description", default_description),
-                fields=None,  # FIXME
+                fields=get_field_list(namespace),
                 possible_types=getattr(meta, "possible_types", None),
                 interfaces=None,  # FIXME
                 enum_values=None,  # FIXME
diff --git a/polygraph/types/object_type.py b/polygraph/types/object_type.py
index 7c6a0f8..9567e1b 100644
--- a/polygraph/types/object_type.py
+++ b/polygraph/types/object_type.py
@@ -1,7 +1,5 @@
-import inspect
-from collections import OrderedDict
-
 from polygraph.types.basic_type import PolygraphOutputType, PolygraphType
+from polygraph.types.definitions import TypeKind
 
 
 class ObjectType(PolygraphOutputType, PolygraphType, dict):
@@ -10,12 +8,5 @@ class ObjectType(PolygraphOutputType, PolygraphType, dict):
     a value of a specific type.
     """
 
-    @classmethod
-    def get_field_map(cls):
-        field_map = OrderedDict()
-        for _, method in inspect.getmembers(cls, predicate=inspect.ismethod):
-            if hasattr(method, '__fieldname__') and hasattr(method, '__field__'):
-                fieldname = method.__fieldname__
-                field = method.__field__
-                field_map[fieldname] = field
-        return field_map
+    class Type:
+        kind = TypeKind.OBJECT


Test patch:
diff --git a/polygraph/types/tests/test_object_type.py b/polygraph/types/tests/test_object_type.py
index 9ffd4d4..5e380b3 100644
--- a/polygraph/types/tests/test_object_type.py
+++ b/polygraph/types/tests/test_object_type.py
@@ -1,6 +1,7 @@
 from unittest import TestCase
 
 from polygraph.exceptions import PolygraphValueError
+from polygraph.types.api import typedef
 from polygraph.types.decorators import field
 from polygraph.types.object_type import ObjectType
 from polygraph.types.scalar import Int, String
@@ -27,6 +28,15 @@ class HelloWorldObject(ObjectType):
 
 
 class SimpleObjectTypeTest(TestCase):
+    def test_object_type_definition(self):
+        type_info = typedef(HelloWorldObject)
+        self.assertEqual(type_info.name, "HelloWorldObject")
+        self.assertEqual(type_info.description, "This is a test object")
+        self.assertEqual(
+            set([f.name for f in type_info.fields]),
+            set(["greet_world", "greet_you", "bad_resolver"]),
+        )
+
     def test_bare_resolver(self):
         hello_world = HelloWorldObject()
         self.assertEqual(hello_world.greet_world(), String("Hello world!"))