Type Name Introspection

Specification

Any query can include the __typename meta-field. It returns the name of the object type currently being queried.

Query the actual type name of when querying on interface


    [Fact]
    public async Task Query_typename_of_characters()
    {
        /* Given */
        var starwars = new Starwars();

        var query = @"{
                    characters {
                        __typename
                        id
                        name
                        appearsIn
                    }
                }";

        var executableSchema = await _fixture.CreateSchema(starwars);

        /* When */
        var actual = await Executor.Execute(executableSchema, query);

        /* Then */
        actual.ShouldMatchJson(
            @"{
                  ""data"": {
                    ""characters"": [
                      {
                        ""appearsIn"": [
                          ""JEDI"",
                          ""EMPIRE"",
                          ""NEWHOPE""
                        ],
                        ""name"": ""Han"",
                        ""id"": ""humans/han"",
                        ""__typename"": ""Human""
                      },
                      {
                        ""appearsIn"": [
                          ""JEDI"",
                          ""EMPIRE"",
                          ""NEWHOPE""
                        ],
                        ""name"": ""Luke"",
                        ""id"": ""humans/luke"",
                        ""__typename"": ""Human""
                      }
                    ]
                  }
                }");
    }