@@ -49,6 +49,10 @@ public static function addImplementationToInterfaces(ObjectType $impl)
4949 }
5050 }
5151
52+ /**
53+ * InterfaceType constructor.
54+ * @param array $config
55+ */
5256 public function __construct (array $ config )
5357 {
5458 Config::validate ($ config , [
@@ -63,7 +67,6 @@ public function __construct(array $config)
6367
6468 $ this ->name = $ config ['name ' ];
6569 $ this ->description = isset ($ config ['description ' ]) ? $ config ['description ' ] : null ;
66- $ this ->_fields = !empty ($ config ['fields ' ]) ? FieldDefinition::createMap ($ config ['fields ' ]) : [];
6770 $ this ->_resolveTypeFn = isset ($ config ['resolveType ' ]) ? $ config ['resolveType ' ] : null ;
6871 $ this ->config = $ config ;
6972 }
@@ -73,11 +76,25 @@ public function __construct(array $config)
7376 */
7477 public function getFields ()
7578 {
79+ if (null === $ this ->_fields ) {
80+ $ this ->_fields = [];
81+ $ fields = isset ($ this ->config ['fields ' ]) ? $ this ->config ['fields ' ] : [];
82+ $ fields = is_callable ($ fields ) ? call_user_func ($ fields ) : $ fields ;
83+ $ this ->_fields = FieldDefinition::createMap ($ fields );
84+ }
7685 return $ this ->_fields ;
7786 }
7887
88+ /**
89+ * @param $name
90+ * @return FieldDefinition
91+ * @throws \Exception
92+ */
7993 public function getField ($ name )
8094 {
95+ if (null === $ this ->_fields ) {
96+ $ this ->getFields ();
97+ }
8198 Utils::invariant (isset ($ this ->_fields [$ name ]), 'Field "%s" is not defined for type "%s" ' , $ name , $ this ->name );
8299 return $ this ->_fields [$ name ];
83100 }
@@ -90,6 +107,10 @@ public function getPossibleTypes()
90107 return $ this ->_implementations ;
91108 }
92109
110+ /**
111+ * @param Type $type
112+ * @return bool
113+ */
93114 public function isPossibleType (Type $ type )
94115 {
95116 $ possibleTypeNames = $ this ->_possibleTypeNames ;
0 commit comments