{
  humans {
    id
    name
    height
  }
}
La réponse que pourrait nous faire GraphQL serait par exemple de ce type :
{
  "data": {
    "humans": [
      {
        "id": "1",
        "name": "Luke Skywalker",
        "height": 1.72
      },
      {
        "id": "2",
        "name": "Obiwan Kenobi",
        "height": 1.75
      }
    ]
  }
}

{
  human(id: 1) {
    name
    height
    planet
    friends {
      name
    }
  }
}

{
  "data": {
    "human": [
      {
        "name": "Luke Skywalker",
        "height": 1.72,
        "planet": "Tatooine",
        "friends": [
          {
            "name": "R2-D2",
          },
          {
            "name": "Hann Solo",
          }
        ]
      }
    ]
  }
}

{
jedi: human (id: 1) {
                name
 }
           sith: human (id: 5) {
          name
          }
}

{
    "data": {
        "jedi": {
            "name": "Luke Skywalker"
        },
        "sith": {
            "name": "Dark Vador"
        }
    }
}

{
  "human": {
    "name": "Boba Fett"
  }
}

{
  "data": {
    "createHuman": {
      "id": 5,
      "name": "Boba Fett"
    }
  }
}

{
  hero
}

{
  "errors": [
    {
      "message": "Field \"hero\" of type \"Character\" must have a selection of subfields. Did you mean \"hero { ... }\"?",
      "locations": [
        {
          "line": 3,
          "column": 3
        }
      ]
    }
  ]
}

public class Droid
{
    public string Id { get; set; }
    public string Name { get; set; }
}

Il nous faut alors créer un type « GraphQL » pour le définir. On l’appelle donc DroidType et on le fait dériver de  l’ObjectGraphType<Droid> de cette manière :
public class DroidType : ObjectGraphType<Droid>
{
    public DroidType()
    {
        Name = "Droid";
        Description = "A mechanical creature in the Star Wars universe.";
        Field(d => d.Id).Description("The id of the droid.");
        Field(d => d.Name, nullable: true).Description("The name of the droid.");
    }
}

public class Droid
{
    public string Id { get; set; }
    public string Name { get; set; }
    public List<Episode> AppearsIn { get; set; }
}
 
public class Episode
{
    public string Name { get; set; }
    public int Year { get; set; }
    public int Order { get; set; }
}

public class DroidType : ObjectGraphType<Droid>
{
    public DroidType()
    {
        Name = "Droid";
        Description = "A mechanical creature in the Star Wars universe.";
        Field(d => d.Id).Description("The id of the droid.");
        Field(d => d.Name, nullable: true).Description("The name of the droid.");
        Field<ListGraphType<EpisodeType>>(
            "appearsIn",
            resolve: context => context.Source.AppearsIn);
    }
}

public class StarWarsQuery : ObjectGraphType<object>
{
    public StarWarsQuery(StarWarsData data)
    {
        Name = "Query";
        Field<DroidType>(
            "droid",
            arguments: new QueryArguments(
                new QueryArgument<NonNullGraphType<StringGraphType>>
                {
                    Name = "id",
                    Description = "id of the droid"
                }
            ),
            resolve: data.GetDroidById(id);
        );
    }
}

public class StarWarsSchema : Schema
{
    public StarWarsSchema(IDependencyResolver resolver)
        : base(resolver)
    {
        Query = resolver.Resolve<StarWarsQuery>();
    }
}

public class GraphQLService : IGraphQLService
{
    private readonly ISchema _query;
    public GraphQLService(ISchema query)
    {
        _query = query;
    }
    public async Task<ExecutionResult> ExecuteQueryAsync(string query)
        => await new DocumentExecuter()
            .ExecuteAsync(options =>
            {
                options.Schema = _query;
                options.Query = query;
            });
}

public async Task<IActionResult> GetAsync([FromQuery] string query)
{
    ExecutionResult result = await _graphQLService.ExecuteQueryAsync(query);

    return Ok(result);
}

{
    droid(id: "AF669ABD-AAEB-4C7B-870D-0360FDFA02D5") {
        id
        name
        appearsIn {
            name
            year
            order
        }
    }
}

{
    "data": {
        "droid": {
            "id": "AF669ABD-AAEB-4C7B-870D-0360FDFA02D5",
            "name": "R2-D2",
            "appearsIn": [
                {
                    "name": "Un nouvel espoir",
                    "year": 1977,
                    "order": 4
                },
                {
                    "name": "L'empire contre-attaque",
                    "year": 1980,
                    "order": 5
                },
                {
                    "name": "Le retour du Jedi",
                    "year": 1983,
                    "order": 6
                }
            ]
        }
    }
}

public class DroidInputType : InputObjectGraphType
{
    public DroidInputType()
    {
        Name = "DroidInput";
        Field<NonNullGraphType<StringGraphType>>("name");
    }
}

public class StarWarsMutation : ObjectGraphType<object>
{
    public StarWarsMutation(StarWarsData data)
    {
        Name = "Mutation";
        Field<DroidType>(
            "createDroid",
            arguments: new QueryArguments(
                new QueryArgument<NonNullGraphType<DroidInputType>> {Name = "droid"}
            ),
            resolve: context =>
            {
                var droid = context.GetArgument<Droid>("droid");
                return data.AddDroid(droid);
            });
    }
}

public class StarWarsSchema : Schema
{
    public StarWarsSchema(IDependencyResolver resolver)
        : base(resolver)
    {
        Query = resolver.Resolve<StarWarsQuery>();
        Mutation = resolver.Resolve<StarWarsMutation>();
    }
}

public class GraphQLService : IGraphQLService
{
    private readonly ISchema _query;
    public GraphQLService(ISchema query)
    {
        _query = query;
    }
    public Task<ExecutionResult> ExecuteQueryAsync(string query)
        => new DocumentExecuter()
            .ExecuteAsync(options =>
            {
                options.Schema = _query;
                options.Query = query;
            });
    public Task<ExecutionResult> ExecuteMutationAsync(string query, string variables)
        => new DocumentExecuter()
            .ExecuteAsync(options =>
            {
                options.Schema = _query;
                options.Query = query;
                options.Inputs = variables.ToInputs();
            });
}

public async Task<IActionResult> DoMutationsAsync([FromBody] string query, [FromBody] string variables)
{
    ExecutionResult result = await _graphQLService.ExecuteMutationAsync(query, variables);

    return Ok(result);
}

{
    "query": "mutation ($droid: DroidInput!){ createDroid(droid: $droid) { id name } }",
    "variables": {
        "droid": {
            "name": "R2-D2"
        }
    }
}

{
    "data": {
        "droid": {
            "id": "AF669ABD-AAEB-4C7B-870D-0360FDFA02D5",
            "name": "R2-D2"
        }
    }
}

public class StarWarsQuery : ObjectGraphType<object>
{
    public StarWarsQuery(StarWarsData data)
    {
        Name = "Query";
        Field<DroidType>(
            "droid",
            arguments: new QueryArguments(
                new QueryArgument<NonNullGraphType<StringGraphType>>
                {
                    Name = "id",
                    Description = "id of the droid"
                }
            ),
            resolve: context =>
            {
                var droid = data.GetDroidById(id);
                if (data == null)
                {
                    context.Errors.Add(new GraphQL.ExecutionError("Le droid n’existe pas.");
                }
                return droid;
        );
    }
}

{
    "errors": [
        {
            "message": "Le droid n’existe pas."
        }
    ]
}