public static void Create <TContext>(GraphQLSchema <TContext> schema, Func <TContext, IQueryable <ICharacter> > herosProviderFunc) { schema.AddEnum <EpisodeEnum>(); var characterInterface = schema.AddInterfaceType <ICharacter>(); characterInterface.AddAllFields(); var humanType = schema.AddType <Human>(); humanType.AddAllFields(); humanType.AddInterface(characterInterface); var droidType = schema.AddType <Droid>(); droidType.AddAllFields(); droidType.AddInterface(characterInterface); var starshipType = schema.AddType <Starship>(); starshipType.AddAllFields(); schema.AddUnionType("SearchResult", new[] { typeof(Droid), typeof(Human), typeof(Starship) }); schema.AddField( "hero", new { episode = EpisodeEnum.NEWHOPE }, (db, args) => args.episode == EpisodeEnum.EMPIRE // Luke is the hero of Episode V. ? herosProviderFunc(db).FirstOrDefault(h => h.Id == "1000") // Artoo is the hero otherwise. : herosProviderFunc(db).FirstOrDefault(h => h.Id == "2001")); schema.AddField("human", new { id = "" }, (db, args) => herosProviderFunc(db).OfType <Human>().FirstOrDefault(c => c.Id == args.id)); schema.AddField("droid", new { id = "" }, (db, args) => herosProviderFunc(db).OfType <Droid>().FirstOrDefault(c => c.Id == args.id)); schema.AddField("search", new { text = "" }, (db, args) => args.text == "starship" ? new Starship() as object : (args.text == "droid" ? new Droid() as object : new Human() as object)) .WithReturnType("SearchResult"); }