Exemple #1
0
        public DragonMutation(IDragonService dragonService,
                              IValidatorService validator)
        {
            Name = "Mutation";

            Field <IdGraphType>("createDragon",
                                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                }
            },
                                resolve: context =>
            {
                var token = context.GetArgument <string>("token");
                validator.ValidateToken(token);

                return(dragonService.CreateDragonAsync());
            });
        }
 /// <summary>
 /// Some coment.
 /// </summary>
 public DragonsController(IDragonService dragonService)
 {
     _dragonService = dragonService;
 }
Exemple #3
0
        public DragonQuery(IDragonService dragonService,
                           IValidatorService validatorService)
        {
            Name = "Query";

            Field <DragonType>(
                "dragonById",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <IdGraphType> {
                    Name = "id"
                }
            },
                resolve: context =>
            {
                var token = context.GetArgument <string>("token");
                var id    = context.GetArgument <int>("id");

                validatorService.ValidateToken(token);

                return(dragonService.FindDragonByIdAsync(id));
            });

            Field <ListGraphType <DragonType> >(
                "dragons",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <NonNullGraphType <IdGraphType> > {
                    Name = "pageNumber"
                },
                new QueryArgument <StringGraphType> {
                    Name = "beginningOfTheName"
                },
                new QueryArgument <IdGraphType> {
                    Name = "maxHpMoreThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "maxHpLessThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "hpMoreThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "hpLessThen"
                },
            },
                resolve: context =>
            {
                var token              = context.GetArgument <string>("token");
                var pageNumber         = context.GetArgument <int>("pageNumber");
                var beginningOfTheName = context.GetArgument <string>("beginningOfTheName", defaultValue: "");
                var maxHpMoreThen      = context.GetArgument <int>("maxHpMoreThen", defaultValue: 80);
                var maxHpLessThen      = context.GetArgument <int>("maxHpLessThen", defaultValue: 100);
                var hpMoreThen         = context.GetArgument <int>("hpMoreThen", defaultValue: 0);
                var hpLessThen         = context.GetArgument <int>("hpLessThen", defaultValue: 100);

                validatorService.ValidateToken(token);

                var dragons = dragonService.GetDragonsAsync().Result;
                dragons     = dragonService.GetPageWithDragonsAsync(dragons, pageNumber).Result;

                dragons = dragonService.FilterDragonsByNameAsync(dragons, beginningOfTheName).Result;
                dragons = dragonService.FilterDragonsByHp(dragons, hpMoreThen, hpLessThen).Result;
                dragons = dragonService.FilterDragonsByMaxHp(dragons, maxHpMoreThen, maxHpLessThen).Result;

                return(dragons);
            }
                );
        }
 public DragonController(IDragonService service) : base(service)
 {
     _service = service;
 }
Exemple #5
0
 public DragonsController(IDragonService service, IOptions <AppSettings> appSettings)
 {
     _service     = service;
     _appSettings = appSettings.Value;
 }