From 5e578d4958db457e7b106996f6756b08dabe962e Mon Sep 17 00:00:00 2001 From: Devon Campbell Date: Mon, 18 Mar 2024 12:25:07 -0400 Subject: [PATCH] Document the `__type__` link at stdlib > Types (#7043) --- docs/stdlib/type.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/stdlib/type.rst b/docs/stdlib/type.rst index aacaef960ed..a2630957e08 100644 --- a/docs/stdlib/type.rst +++ b/docs/stdlib/type.rst @@ -27,6 +27,36 @@ Types - :eql:op-desc:`introspect` +Finding an object's type +------------------------ + +You can find the type of an object via that object's ``__type__`` link, which +carries various information about the object's type, including the type's +``name``. + +.. code-block:: edgeql-repl + + db> select Person { + ... __type__: { + ... name + ... } + ... } limit 1; + {Json("{\"__type__\": {\"name\": \"default::Villain\"}}")} + +This information can be pulled into the top level by assigning a name to +the ``name`` property inside ``__type__``: + +.. code-block:: edgeql-repl + + db> select Person { type := .__type__.name } limit 1; + {Json("{\"type\": \"default::Villain\"}")} + +.. note:: + + There's nothing magical about the ``__type__`` link: it's a standard link + that exists on every object due to their inheritance from + :eql:type:`BaseObject`, linking to the current object's type. + ----------