Interfaces Types & Implements Keyword | Entity GraphQL

GraphQL supports Interfaces allowing you to define a abstract base type that multiple other types might implement.

EntityGraphQL automatically marks abstract classes and interfaces as GraphQL interfaces; however, you can also add them manually to a schema with the AddInterface method on the SchemaProvider class.

public abstract class Character {
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<Character> Friends { get; set; }
public IEnumerable<Episode> AppearsIn { get; set; }
}

public class Human : Character {
public IEnumerable<Starship> Starships { get; set; }
public int TotalCredits { get; set;}
}

public class Droid : Character {
public string PrimaryFunction { get; set;}
}

// creating our schema
schema.AddInterface<Character>(name: "Character", description: "represents any character in the Star Wars trilogy");
.AddAllFields();

schema.AddType<Human>("")
.AddAllFields()
.Implements<Character>();

schema.AddType<Droid>("");
.Implements<Character>();