@@ -334,25 +334,38 @@ def __call__(self, shortcut: Any) -> "DSLDirective": ... # pragma: no cover
334334 def __call__ (
335335 self , shortcut : str , name : Optional [str ] = None
336336 ) -> Union ["DSLMetaField" , "DSLInlineFragment" , "DSLFragment" , "DSLDirective" ]:
337- """Factory method for creating DSL objects.
337+ """Factory method for creating DSL objects from a shortcut string .
338338
339- Currently, supports creating DSLDirective instances when name starts with '@'.
340- Future support planned for meta-fields (__typename), inline fragments (...),
341- and fragment definitions (fragment).
339+ The shortcut determines which DSL object is created:
342340
343- :param shortcut: the name of the object to create
341+ * "__typename", "__schema", "__type" -> :class:`DSLMetaField`
342+ * "..." -> :class:`DSLInlineFragment`
343+ * "fragment" -> :class:`DSLFragment` (requires ``name`` to be a string)
344+ * "@<name>" -> :class:`DSLDirective`
345+
346+ :param shortcut: The shortcut string identifying the DSL object.
344347 :type shortcut: str
345348
346- :return: :class:`DSLDirective` instance
349+ :param name: The fragment name, required when ``shortcut == "fragment"``.
350+ :type name: Optional[str]
351+
352+ :return: A DSL object corresponding to the given shortcut.
353+ :rtype: DSLMetaField | DSLInlineFragment | DSLFragment | DSLDirective
347354
348- :raises ValueError: if shortcut format is not supported
355+ :raises ValueError: If the shortcut is not recognized,
356+ or if ``name`` is missing for a fragment shortcut.
349357 """
358+
359+ if shortcut in ("__typename" , "__schema" , "__type" ):
360+ return DSLMetaField (name = shortcut )
361+ if shortcut == "..." :
362+ return DSLInlineFragment ()
363+ if shortcut == "fragment" :
364+ if not isinstance (name , str ):
365+ raise ValueError (f"Missing name: { name } for fragment shortcut" )
366+ return DSLFragment (name = name )
350367 if shortcut .startswith ("@" ):
351368 return DSLDirective (name = shortcut [1 :], dsl_schema = self )
352- # Future support:
353- # if name.startswith("__"): return DSLMetaField(name)
354- # if name == "...": return DSLInlineFragment()
355- # if name.startswith("fragment "): return DSLFragment(name[9:])
356369
357370 raise ValueError (f"Unsupported shortcut: { shortcut } " )
358371
0 commit comments