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 = _fixture.CreateSchema(starwars);
            var options = new ExecutionOptions
            {
                Schema = executableSchema,
                Document =  ParseDocument(query),
                OperationName = null,
                InitialValue = null,
                VariableValues = null
            };

            /* When */
            var actual = await ExecuteAsync(options).ConfigureAwait(false);

            /* 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""
                      }
                    ]
                  }
                }");
        }