question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs: Add simple examples to Introspection > Object Types

See original GitHub issue

Throughout the last couple of weeks, I have been spending some time going through the documentation and trying understand the fundamentals of SDL and EdgeQL. One part that was particularly elusive for me was figuring out how to perform a basic introspection to determine the names of properties and links that are associated with a specific object.

Here’s the Movie and Person SDL migration from the tutorial (transaction omitted):

CREATE MIGRATION movies TO {
    type Movie {
        required property title -> str;
        # the year of release
        property year -> int64;
        required link director -> Person;
        multi link cast -> Person;
    },
    type Person {
        required property first_name -> str;
        required property last_name -> str;
    },
};

Now let’s say the user wanted to query the data stored in any Movie object, but forgot the names of the links and properties. In a real-world scenario, the user could be using a preexisting database where they aren’t familiar with the schema structure. In order to determine those names, it would be very useful to know how to use a simple introspect:

 SELECT INTROSPECT Movie { 
     properties: { 
         name,
     },
     links: { 
         name,
     }, 
 } 

I think something like this would definitely be worth mentioning in the EdgeQL section of the tutorial, perhaps just after the section starting with “The above query simply returned all the Movie objects…”.

As someone primarily experienced with RDBMS with some minimal experience using document-object DBs, I had an unanswered question that bothered me for the remainder of the tutorial after seeing this example:

SELECT Movie;
{
    Object { id: <uuid>'4d0c8ddc-54d4-11e9-8c54-7776f6130e05' },
    Object { id: <uuid>'64d024dc-54d5-11e9-8c54-a3f59e1d995e' },
}

If I were entering a preexisting database or don’t recall the schema definition for a given object, how am supposed to figure out the names? I couldn’t exactly use SELECT * from table or a GUI dropdown menu to look at the schema structure. I knew that SELECT * wouldn’t be at all be suitable for EdgeQL as a strongly static language and that a GUI wasn’t a necessity, but my question was still unanswered.

As is apparent from the above examples, I later figured it out from the Introspection > Object Types section. But even the first example wasn’t immediately obvious that it was showing me what I was looking for:

WITH MODULE schema
SELECT ObjectType {
    name,
    links: {
        name,
    },
    properties: {
        name,
    },
}
FILTER .name = 'schema::ObjectType';

This example is fairly abstract and uses a filter that wouldn’t be needed if the user only wanted a specific object. This example and the one below it lead me to believe something like this would be the minimum way to figure out the properties and links for Movie:

WITH MODULE schema
SELECT ObjectType {
    name,
    links: {
        name,
    },
    properties: {
        name,
    },
}
FILTER .name = 'default::Movie';

As a result, I think it would be worthwhile to add something along the lines of my introspection example to the tutorial and perhaps a couple of additional simple examples to Introspection > Object Types. I’d be glad to open a couple of PRs to add (one for the tutorial and another for Introspection > Object Types) an example either or both sections.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
1st1commented, May 25, 2020

@ambv Please take a look.

0reactions
aeroscommented, Oct 7, 2019

Changed title of the PR to reflect the modified proposal, since @elprans mentioned the introspection examples might be too advanced for the tutorial.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introspection - GraphQL
Introspection · Query, Character, Human, Episode, Droid - These are the ones that we defined in our type system. · String, Boolean -...
Read more >
Fragments - Apollo GraphQL Docs
This example lists three interfaces ( Character , Test , and Snake ) and the object types that implement them. If your schema...
Read more >
Introspection - Xojo documentation
Returns a TypeInfo object for the passed object. Each TypeInfo instance is unique and immutable, so two objects of the same class will...
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. The most fundamental support consists of the types Any, Union, Callable, ...
Read more >
Protocol Buffer Basics: Java - Google Developers
By walking through creating a simple example application, it shows you how to ... Many standard simple data types are available as field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found