Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the __type__ link at stdlib > Types #7043

Merged
merged 1 commit into from Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/stdlib/type.rst
Expand Up @@ -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
scotttrinh marked this conversation as resolved.
Show resolved Hide resolved
carries various information about the object's type, including the type's
``name``.

.. code-block:: edgeql-repl

db> select <json>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 <json>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.

----------


Expand Down