Esempio n. 1
0
        public CarModelQuery(CarModelRepository modelRepository)
        {
            Field <ListGraphType <CarModelType> >("models",
                                                  resolve: context =>
            {
                return(modelRepository.FindAllByPredicate(x => x.Versions));
            });

            Field <CarModelType>("model",
                                 arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <IdGraphType>
                {
                    Name = "id"
                }
            }),
                                 resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                if (id <= 0)
                {
                    context.Errors.Add(new ExecutionError("Model Id is invalid or missing"));
                    return(null);
                }

                return(modelRepository.FindBy(x => x.Id == id, x => x.Versions));
            });
        }