Ejemplo n.º 1
0
        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);

            FieldDelegate <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: func
                );
        }
Ejemplo n.º 2
0
        public StarWarsQuery(StarWarsData data)
        {
            Name = "Query";

            Field <CharacterInterface>(
                "hero",
                arguments: new QueryArguments(
                    new QueryArgument <EpisodeEnum> {
                Name = "Episode", Description = "Episode of star wars", DefaultValue = Episodes.NEWHOPE
            }
                    ),
                resolve: context => data.GetHero(context.GetArgument <Episodes>("Episode", Episodes.NEWHOPE))
                );

            Field <CharacterInterface>(
                "character",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id", Description = "id of the character"
            }
                    ),
                resolve: context => data.GetCharacter(context.GetArgument <string>("id"))
                );

            Field <HumanType>(
                "human",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id", Description = "id of the human"
            }
                    ),
                resolve: context => data.GetHumanByIdAsync(context.GetArgument <string>("id"))
                );

            Field <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: context => data.GetDroidByIdAsync(context.GetArgument <string>("id"))
                );

            Field <StarShipType>(
                "starship",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id", Description = "id of the starship"
            }
                    ),
                resolve: context => data.GetStarShipByIdAsync(context.GetArgument <string>("id"))
                );
        }
Ejemplo n.º 3
0
        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));
            });
        }
Ejemplo n.º 4
0
        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"))
            );
            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"))
            );
        }
Ejemplo n.º 5
0
        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.Argument <string>("id"))
                );
            Field <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: context => data.GetDroidByIdAsync(context.Argument <string>("id"))
                );
        }
Ejemplo n.º 6
0
        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"))
                );
            Field <ListGraphType <HumanType> >(
                "filterHumans",
                arguments: new QueryArguments(
                    new QueryArgument <HumanFilterType> {
                Name = "filter", Description = "filter applied on humans"
            },
                    new QueryArgument <HumanOrderByType> {
                Name = "orderBy"
            },
                    new QueryArgument <DecimalGraphType> {
                Name = "skip"
            },
                    new QueryArgument <DecimalGraphType> {
                Name = "top"
            }
                    ),
                resolve: context =>
            {
                var filter  = context.GetArgument <HumanFilter>("filter");
                var orderBy = context.GetArgument <HumanOrderBy>("orderBy");
                var skip    = context.GetArgument <int?>("skip");
                var top     = context.GetArgument <int?>("top");

                var query = data.GetHumans()
                            .ApplyFilter(filter)
                            .ApplyOrderBy(orderBy);

                if (skip.HasValue)
                {
                    query = query.Skip(skip.Value);
                }
                if (top.HasValue)
                {
                    query = query.Take(top.Value);
                }

                // TODO: project in anonymous type / tuple required fields to filter
                // out selected fields

                return(Task.FromResult(query.ToList()));
            }
                );

            Func <ResolveFieldContext, string, object> 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
                );
        }