public StarWarsQuery(ITrilogyHeroesRepository trilogyHeroesRepository, IDroidRepository droidRepository,
                             IHumanRepository humanRepository, IMapper mapper)
        {
            Name = "Query";

            FieldAsync <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: async context =>
            {
                var episode   = context.GetArgument <Episodes?>("episode");
                var character = await trilogyHeroesRepository.GetHero((int?)episode);
                var hero      = mapper.Map <Character>(character);
                return(hero);
            }
                );

            FieldAsync <HumanType>(
                "human",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the human"
            }
                    ),
                resolve: async context =>
            {
                var id     = context.GetArgument <int>("id");
                var human  = await humanRepository.GetAsync(id, "HomePlanet");
                var mapped = mapper.Map <Human>(human);
                return(mapped);
            }
                );
            FieldAsync <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: async context =>
            {
                var id     = context.GetArgument <int>("id");
                var droid  = await droidRepository.GetAsync(id);
                var mapped = mapper.Map <Droid>(droid);
                return(mapped);
            }
                );
        }
Esempio n. 2
0
        public Mutation(ITrilogyHeroes trilogyHeroes, IDroidRepository droidRepository,
                        IHumanRepository humanRepository)
        {
            _trilogyHeroes   = trilogyHeroes;
            _droidRepository = droidRepository;
            _humanRepository = humanRepository;

            Name = "Mutation";

            Field <DroidType>(
                Name = "addDroid",
                arguments: new QueryArguments(
                    new QueryArgument <DroidTypeInput> {
                Name = "droid", DefaultValue = null
            }),
                resolve: AddDroid
                );
        }
Esempio n. 3
0
        public StarWarsQueryObject(
            IDroidRepository droidRepository,
            IHumanRepository humanRepository)
        {
            this.Name        = "StarWarsQuery";
            this.Description = "The query type, represents all of the entry points into our object graph.";

            this.FieldAsync <DroidObject, Droid>(
                "droid",
                "Get a droid by its unique identifier.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name        = "id",
                Description = "The unique identifier of the droid.",
            }),
                resolve: context =>
                droidRepository.GetDroidAsync(
                    context.GetArgument("id", defaultValue: new Guid("1ae34c3b-c1a0-4b7b-9375-c5a221d49e68")),
                    context.CancellationToken));

            this.FieldAsync <HumanObject, Human>(
                "human",
                "Get a human by its unique identifier.",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name        = "id",
                Description = "The unique identifier of the human.",
            }),
                resolve: context => humanRepository.GetHumanAsync(
                    context.GetArgument("id", defaultValue: new Guid("94fbd693-2027-4804-bf40-ed427fe76fda")),
                    context.CancellationToken));

            this.Connection <DroidObject>()
            .Name("droids")
            .Description("Gets pages of droids.")
            // Enable the last and before arguments to do paging in reverse.
            .Bidirectional()
            // Set the maximum size of a page, use .ReturnAll() to set no maximum size.
            .PageSize(MaxPageSize)
            .ResolveAsync(context => ResolveConnectionAsync(droidRepository, context));
        }
        public StarWarsMutation(IHumanRepository humanRepository, IMapper mapper)
        {
            Name = "Mutation";

            FieldAsync <HumanType>(
                "createHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <HumanInputType> > {
                Name = "human"
            }
                    ),
                resolve: async context =>
            {
                var human = context.GetArgument <Human>("human");
                var model = mapper.Map <Repositories.Models.Human>(human);
                await humanRepository.AddAsync(model);
                return(mapper.Map <Human>(model));
            });
        }
 public void Search(IHumanRepository rep, int code)
 {
     manlist.Clear();
     if (code == 1 || code == 2)
     {
         rep.Humans.Clear();
         counter = 0;
     }
     this.opcode = code;
     this.rep = rep;
     //создание нового потока для 
     //параллельных вычислений
     Thread threadG = new Thread(GetRawDataG);
     threadG.Name = "GoogleService";
     threadG.Start();
     GetRawDataSoc();
     //ожидание окончания выполнения второго потока
     threadG.Join();
     //подготовить информацию о человеке
     PrepareHuman();
 }
 public HumanController(IHumanRepository humanRepository, ISearchNET searchservice)
 {
     repository = humanRepository;
     service = searchservice;
 }