public HumanType(StarWarsData data) { Name = "Human"; Field(h => h.Id).Description("The id of the human."); Field(h => h.Name, nullable: true).Description("The name of the human."); Field <ListGraphType <CharacterInterface> >( "friends", resolve: context => data.GetFriends(context.Source) ); Connection <CharacterInterface>() .Name("friendsConnection") .Description("A list of a character's friends.") .Bidirectional() .Resolve(context => { return(context.GetPagedResults <Human, StarWarsCharacter>(data, context.Source.Friends)); }); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field(h => h.HomePlanet, nullable: true).Description("The home planet of the human."); Interface <CharacterInterface>(); }
public StarWarsQuery(StarWarsData data) { Name = "Query"; FieldAsync <CharacterInterface>("hero", resolve: async context => await data.GetDroidByIdAsync("3").ConfigureAwait(false)); FieldAsync <HumanType>( "human", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the human" } ), resolve: async context => await data.GetHumanByIdAsync(context.GetArgument <string>("id")).ConfigureAwait(false) ); Func <IResolveFieldContext, string, Task <Droid> > func = (context, id) => data.GetDroidByIdAsync(id); FieldDelegate <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: func ); }
public DroidType(StarWarsData data) { 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 <CharacterInterface> >( "friends", resolve: context => { // simulate loading // await Task.Delay(1000); return(data.GetFriends(context.Source)); } ); Connection <CharacterInterface>() .Name("friendsConnection") .Description("A list of a character's friends.") .Bidirectional() .Resolve(context => context.GetPagedResults <Droid, StarWarsCharacter>(data, context.Source.Friends)); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field(d => d.PrimaryFunction, nullable: true).Description("The primary function of the droid."); Interface <CharacterInterface>(); }
public StarWarsQuery() { var data = new StarWarsData(); Name = "Query"; Field<CharacterInterface>("hero", resolve: context => data.GetDroidById("3")); Field<HumanType>( "human", arguments: new QueryArguments( new [] { new QueryArgument { Name = "id", Type = NonNullGraphType.String} }), resolve: context => data.GetHumanById((string)context.Arguments["id"]) ); Field<DroidType>( "droid", arguments: new QueryArguments( new [] { new QueryArgument { Name = "id", Type = NonNullGraphType.String} }), resolve: context => data.GetDroidById((string)context.Arguments["id"]) ); }
public StarWarsQuery(StarWarsData data) { Name = "Query"; Field <CharacterInterface>("hero", resolve: context => data.GetDroidByIdAsync("3")); Field <HumanType>( "human", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the human" } ), resolve: context => data.GetHumanByIdAsync(context.GetArgument <string>("id")) ); Func <IResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id); Field <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: context => data.GetDroidByIdAsync(context.GetArgument <string>("id")) ); }
public HumanType(StarWarsData data) { Name = "Human"; Field <NonNullGraphType <IdGraphType> >("id", "The id of the human."); Field(h => h.Name, nullable: false).Description("The name of the human."); Field(h => h.Mass, nullable: false).Description("Mass in kilograms, or null if unknown"); Field <NonNullGraphType <FloatGraphType> >( "height", arguments: new QueryArguments( new QueryArgument <HeighEnum> { Name = "unit", Description = "Height in the preferred unit, default is meters", DefaultValue = LengthUnit.METER } ), resolve: context => data.GetHeighOrLenght(context.GetArgument <LengthUnit>("unit", LengthUnit.METER), context.Source.Height) ); Field <ListGraphType <CharacterInterface> >( "friends", resolve: context => data.GetFriends(context.Source) ); Field <ListGraphType <StarShipType> >( "starships", resolve: context => context.Source.Starships ); Field <NonNullGraphType <ListGraphType <NonNullGraphType <EpisodeEnum> > > >("appearsIn", "Which movie they appear in."); Interface <CharacterInterface>(); }
public HttpResponseMessage GetHero() { var data = new StarWarsData(); var item = data.GetDroidByIdAsync("3").Result; return(Request.CreateResponse(HttpStatusCode.OK, item)); }
public async Task <IHttpActionResult> GetDriod(string id) { var data = new StarWarsData(); var item = await data.GetDroidByIdAsync(id); return(Ok(item)); }
public HumanType(StarWarsData data) { Name = "Human"; Field(h => h.Id).Description("The id of the human."); Field(h => h.Name, nullable: true).Description("The name of the human."); Field <ListGraphType <CharacterInterface> >("friends", description: null, arguments: null, context => data.GetFriends(context.Source)); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field(h => h.HomePlanet, nullable: true).Description("The home planet of the human."); Interface <CharacterInterface>(); }
public DroidType(StarWarsData data) { 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 <CharacterInterface> >("friends", description: null, arguments: null, context => data.GetFriends(context.Source)); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field(d => d.PrimaryFunction, nullable: true).Description("The primary function of the droid."); Interface <CharacterInterface>(); }
public EPiServerManType(StarWarsData data) { Name = "EPiServerMan"; Description = "Super man in this world"; Field(x => x.Id); Field(x => x.EmployeeId); Field(x => x.Name); Field(x => x.EpiServerCode); Field(x => x.Department); // Field<EnumerationGraphType<string>> ("AddonsRelated", resolve: context => data.GetAddonRelated(context.Source)); }
public DroidType() { var data = new StarWarsData(); Name = "Droid"; Field <NonNullGraphType <StringGraphType> >("id", "The id of the droid."); Field <NonNullGraphType <StringGraphType> >("name", "The name of the droid."); Field <ListGraphType <CharacterInterface> >( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Interface <CharacterInterface>(); IsTypeOf = value => value is Droid; }
public DroidType() { var data = new StarWarsData(); Name = "Droid"; Field("id", "The id of the droid.", NonNullGraphType.String); Field("name", "The name of the droid.", NonNullGraphType.String); Field<ListGraphType<CharacterInterface>>( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Interface<CharacterInterface>(); }
public StarWarsMutation(StarWarsData data) { Name = "Mutation"; Field <HumanType>( "createHuman", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <HumanInputType> > { Name = "human" } ), resolve: context => { var human = context.GetArgument <Human>("human"); return(data.AddCharacter(human)); }); }
public HumanType(StarWarsData data) { Name = "LandingNavigationRequest"; Field(h => h.Id).Description("The id of the human."); Field(h => h.Name, nullable: true).Description("The name of the human."); // Field<ListGraphType<CharacterInterface>>( // "friends", // resolve: context => data.GetFriends(context.Source) // ); // Field<ListGraphType<EpisodeEnum>>("appearsIn", "Which movie they appear in."); // Field(h => h.HomePlanet, nullable: true).Description("The home planet of the human."); // Interface<CharacterInterface>(); }
public HumanType(StarWarsData data) { Name = "Human"; Field <NonNullGraphType <StringGraphType> >("id", "The id of the human."); Field <StringGraphType>("name", "The name of the human."); Field <ListGraphType <CharacterInterface> >( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movies they appear in."); Field <StringGraphType>("homePlanet", "The home planet of the human."); Interface <CharacterInterface>(); IsTypeOf = value => value is Human; }
public HumanType(StarWarsData data) { Name = "Human"; Field<NonNullGraphType<StringGraphType>>("id", "The id of the human."); Field<StringGraphType>("name", "The name of the human."); Field<ListGraphType<CharacterInterface>>( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Field<ListGraphType<EpisodeEnum>>("appearsIn", "Which movie they appear in."); Field<StringGraphType>("homePlanet", "The home planet of the human."); Interface<CharacterInterface>(); IsTypeOf = value => value is Human; }
public DroidType(StarWarsData data) { Name = "Droid"; Description = "A mechanical creature in the Star Wars universe."; Field <NonNullGraphType <StringGraphType> >("id", "The id of the droid."); Field <StringGraphType>("name", "The name of the droid."); Field <ListGraphType <CharacterInterface> >( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field <StringGraphType>("primaryFunction", "The primary function of the droid."); Interface <CharacterInterface>(); IsTypeOf = value => value is Droid; }
public StarShipType(StarWarsData data) { Name = "Starship"; Field <NonNullGraphType <IdGraphType> >("id", "The ID of the starship"); Field(h => h.Name, nullable: false).Description("The name of the starship"); Field <NonNullGraphType <FloatGraphType> >( "length", arguments: new QueryArguments( new QueryArgument <HeighEnum> { Name = "unit", Description = "Length of the starship, along the longest axis", DefaultValue = LengthUnit.METER } ), resolve: context => data.GetHeighOrLenght(context.GetArgument <LengthUnit>("unit", LengthUnit.METER), context.Source.Length) ); }
public StarWarsQuery(StarWarsData data) { Name = "StarWarsContext"; Description = "StarWars Context"; Func <ResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id); FieldDelegate <DroidType>( "droid", "Get droid by Id", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: func ); }
public DroidType(StarWarsData data) { Name = "Droid"; Description = "A mechanical creature in the Star Wars universe."; Field<NonNullGraphType<StringGraphType>>("id", "The id of the droid."); Field<StringGraphType>("name", "The name of the droid."); Field<ListGraphType<CharacterInterface>>( "friends", resolve: context => data.GetFriends(context.Source as StarWarsCharacter) ); Field<ListGraphType<EpisodeEnum>>("appearsIn", "Which movie they appear in."); Field<StringGraphType>("primaryFunction", "The primary function of the droid."); Interface<CharacterInterface>(); IsTypeOf = value => value is Droid; }
public StarWarsSubscription(StarWarsData data) { Name = "Subscription"; _starWarsData = data; AddField(new EventStreamFieldType { Name = "humanAdded", Type = typeof(HumanType), Resolver = new FuncFieldResolver <Human>(ResolveMessage), Subscriber = new EventStreamResolver <Human>(Subscribe) }); AddField(new EventStreamFieldType { Name = "throwNotImplementedException", Type = typeof(HumanType), Resolver = new FuncFieldResolver <Human>(ResolveMessage), Subscriber = new EventStreamResolver <Human>(ThrowNotImplementedException) }); }
public DroidType(StarWarsData data) { Name = "Droid"; Description = "A mechanical creature in the Star Wars universe."; Field <NonNullGraphType <StringGraphType> >("id", "The id of the droid.", resolve: context => context.Source.Id); Field <StringGraphType>("name", "The name of the droid.", resolve: context => context.Source.Name); Field <ListGraphType <CharacterInterface> >("friends", resolve: context => data.GetFriends(context.Source)); Connection <CharacterInterface>() .Name("friendsConnection") .Description("A list of a character's friends.") .Bidirectional() .Resolve(context => context.GetPagedResults <Droid, StarWarsCharacter>(data, context.Source.Friends)); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field <StringGraphType>("primaryFunction", "The primary function of the droid.", resolve: context => context.Source.PrimaryFunction); Interface <CharacterInterface>(); }
public HumanType(StarWarsData data) { Name = "Human"; Field <NonNullGraphType <StringGraphType> >("id", "The id of the human.", resolve: context => context.Source.Id); Field <StringGraphType>("name", "The name of the human.", resolve: context => context.Source.Name); Field <ListGraphType <CharacterInterface> >("friends", resolve: context => data.GetFriends(context.Source)); Connection <CharacterInterface>() .Name("friendsConnection") .Description("A list of a character's friends.") .Bidirectional() .Resolve(context => context.GetPagedResults <Human, StarWarsCharacter>(data, context.Source.Friends)); Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in."); Field <StringGraphType>("homePlanet", "The home planet of the human.", resolve: context => context.Source.HomePlanet); Interface <CharacterInterface>(); }
public StarWarsMutation(StarWarsData data) { Name = "Mutation"; Field <HumanType>( "createHuman", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <HumanInputType> > { Name = "human" } ), resolve: context => { if (context.GetArgument <Human>("human").Name == "mammad") { context.Errors.Add(new ExecutionError("Mammad is not human, he is an angel.")); return(null); } var human = context.GetArgument <Human>("human"); return(data.AddHuman(human)); }); }
public HeroQuery(StarWarsData starWarsData) { _starWarsData = starWarsData; }
public CreateHumanMutation( StarWarsData starWarsData) { _starWarsData = starWarsData; }
public HumanQuery(StarWarsData starWarsData) { _starWarsData = starWarsData; }
public CountFieldMiddleware(IHttpContextAccessor accessor, StarWarsData data) { // these dependencies are not needed here and are used only for demonstration purposes Debug.Assert(accessor != null); Debug.Assert(data != null); }
public static IEnumerable <ICharacter> AsCharacters(this IEnumerable <CharacterDto> characters, StarWarsData data) { foreach (var character in characters) { switch (character) { case HumanDto humanDto: yield return(new Human(humanDto, data)); break; case DroidDto droidDto: yield return(new Droid(droidDto, data)); break; } } }
public static Connection <U> GetPagedResults <T, U>(this ResolveConnectionContext <T> context, StarWarsData data, List <string> ids) where U : StarWarsCharacter { List <string> idList; List <U> list; string cursor; string endCursor; var pageSize = context.PageSize ?? 20; if (context.IsUnidirectional || context.After != null || context.Before == null) { if (context.After != null) { idList = ids .SkipWhile(x => !Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(x)).Equals(context.After)) .Take(context.First ?? pageSize).ToList(); } else { idList = ids .Take(context.First ?? pageSize).ToList(); } } else { if (context.Before != null) { idList = ids.Reverse <string>() .SkipWhile(x => !Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(x)).Equals(context.Before)) .Take(context.Last ?? pageSize).ToList(); } else { idList = ids.Reverse <string>() .Take(context.Last ?? pageSize).ToList(); } } list = data.GetCharactersAsync(idList).Result as List <U>; cursor = list.Count > 0 ? list.Last().Cursor : null; endCursor = ids.Count > 0 ? Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ids.Last())) : null; return(new Connection <U> { Edges = list.Select(x => new Edge <U> { Cursor = x.Cursor, Node = x }).ToList(), TotalCount = list.Count, PageInfo = new PageInfo { EndCursor = endCursor, HasNextPage = endCursor == null ? false : !cursor.Equals(endCursor) } }); }
public Human(HumanDto dto, StarWarsData data) { _dto = dto ?? throw new ArgumentNullException(nameof(dto)); _data = data ?? throw new ArgumentNullException(nameof(data)); }
public StarWarsQuery(StarWarsData data) { _data = data ?? throw new ArgumentNullException(nameof(data)); }
public DroidQuery( StarWarsData starWarsData) { _starWarsData = starWarsData; }