public StarWarsQuery(ITrilogyHeroes trilogyHeroes, Core.Data.IDroidRepository droidRepository, Core.Data.IHumanRepository humanRepository, IMapper mapper)
        {
            Name = "Query";

            Field <CharacterInterface>(
                "hero",
                arguments: new QueryArguments(
                    new QueryArgument <EpisodeEnum> {
                Name = "episode", Description = "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
            }
                    ),
                resolve: context =>
            {
                var episode   = context.GetArgument <Episodes?>("episode");
                var character = trilogyHeroes.GetHero((int?)episode).Result;
                var hero      = mapper.Map <Character>(character);
                return(hero);
            }
                );

            Field <HumanType>(
                "human",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the human"
            }
                    ),
                resolve: context =>
            {
                var id    = context.GetArgument <int>("id");
                var human = humanRepository.Get(id).Result;
                if (human != null)
                {
                    Console.Out.WriteLine("Human found: " + human.Id);
                }
                var mapped = mapper.Map <Human>(human);
                return(mapped);
            }
                );
            Field <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: context =>
            {
                var id     = context.GetArgument <int>("id");
                var droid  = droidRepository.Get(id).Result;
                var mapped = mapper.Map <Droid>(droid);
                return(mapped);
            }
                );
        }
Beispiel #2
0
        public QLMutation(Core.Data.IDroidRepository droidRepository, Core.Data.IFriendRepository friendRepository, IMapper mapper)
        {
            Name = "Mutation";

            Field <DroidType>(
                "createDroid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <DroidInputType> > {
                Name = "droid"
            }
                    ),
                resolve: context =>
            {
                var droid    = context.GetArgument <Droid>("droid");
                var mapped   = mapper.Map <Core.Models.Droid>(droid);
                var droidadd = droidRepository.Add(mapped);
                droidRepository.SaveChangesAsync();
                return(mapper.Map <Droid>(droidadd));
            });

            Field <ListGraphType <DroidType> >(
                "createDroids",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ListGraphType <DroidInputType> > > {
                Name = "droids"
            }
                    ),
                resolve: context =>
            {
                var droids    = context.GetArgument <List <Droid> >("droids");
                var mapped    = mapper.Map <List <Core.Models.Droid> >(droids);
                var droidsadd = droidRepository.AddRange(mapped);
                droidRepository.SaveChangesAsync();
                return(mapper.Map <List <Droid> >(droidsadd));
            });
        }
Beispiel #3
0
        public QLQuery(Core.Data.IDroidRepository droidRepository, Core.Data.IFriendRepository friendRepository,
                       Core.Data.IArticaleRepository articaleRepository, Core.Data.IClassificationRepository classificationRepository,
                       Core.Data.IUserRepository userRepository,
                       IMapper mapper)
        {
            Name = "Query";

            Field <ListGraphType <ArticaleType> >(
                "articles",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "classificationId"
            },
                    new QueryArgument <IntGraphType> {
                Name = "userId"
            }
                    ),
                resolve: context => {
                var classificationId = context.GetArgument <int?>("classificationId");
                var userId           = context.GetArgument <int?>("userId");
                var articles         = articaleRepository.GetAll(classificationId, userId, "Classification", "User").Result;
                var mapped           = mapper.Map <List <Articale> >(articles);
                return(mapped);
            });

            Field <ListGraphType <ClassificationType> >(
                "classifications",
                resolve: context => {
                var classifications = classificationRepository.GetAll().Result;
                var mapped          = mapper.Map <List <Classification> >(classifications);
                return(mapped);
            });

            Field <UserType>(
                "user",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }
                    ),
                resolve: context => {
                var id     = context.GetArgument <int>("id");
                var user   = userRepository.Get(id).Result;
                var mapped = mapper.Map <User>(user);
                return(mapped);
            });

            Field <DroidType>(
                "hero",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "id"
            }
                    ),
                resolve: context =>
            {
                var id     = context.GetArgument <int>("id");
                var droid  = droidRepository.Get(id).Result;
                var mapped = mapper.Map <Droid>(droid);
                return(mapped);
            });

            Field <ListGraphType <DroidType> >(
                "heros",
                resolve: context =>
            {
                var droids = droidRepository.GetAll().Result;
                var mapped = mapper.Map <List <Droid> >(droids);
                return(mapped);
                //var droidsview = new List<Droid>();
                //foreach (var item in droids.Result)
                //{
                //    droidsview.Add()
                //}
            });

            Field <FriendType>(
                "friend",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }
                    ),
                resolve: context =>
            {
                var id     = context.GetArgument <int>("id");
                var result = friendRepository.Get(id, include: "Droid").Result;
                var mapped = mapper.Map <Friend>(result);
                return(mapped);
            });

            Field <ListGraphType <FriendType> >(
                "friends",
                arguments: new QueryArguments(
                    new QueryArgument <FriendSexEnum> {
                Name = "sex"
            }
                    ),
                resolve: context =>
            {
                var sex = context.GetArgument <FriendSex?>("sex");
                if (sex.HasValue)
                {
                    var sexfriends = friendRepository.GetFriendBySex((int)sex.Value, "Droid").Result;
                    var sexmapped  = mapper.Map <List <Friend> >(sexfriends);
                    return(sexmapped);
                }
                var friends = friendRepository.GetAll("Droid").Result;
                var mapped  = mapper.Map <List <Friend> >(friends);
                return(mapped);
            });
        }