예제 #1
0
        public RootQuery(
            IDroidRepository droidRepository,
            IHumanRepository humanRepository)
        {
            this.Name        = "Query";
            this.Description = "The query type, represents all of the entry points into our object graph.";

            this.FieldAsync <DroidObject, Droid>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType>
            {
                Name        = "id",
                Description = "The unique identifier of the droid.",
            }),
                resolve: context =>
                droidRepository.GetDroid(
                    context.GetArgument("id", defaultValue: new Guid("1ae34c3b-c1a0-4b7b-9375-c5a221d49e68")),
                    context.CancellationToken));
            this.FieldAsync <HumanObject, Human>(
                "human",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType>()
            {
                Name        = "id",
                Description = "The unique identifier of the human.",
            }),
                resolve: context => humanRepository.GetHuman(
                    context.GetArgument("id", defaultValue: new Guid("94fbd693-2027-4804-bf40-ed427fe76fda")),
                    context.CancellationToken));
        }
예제 #2
0
        public QueryObject(
            IDroidRepository droidRepository,
            IHumanRepository humanRepository)
        {
            this.Name        = "Query";
            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.GetDroid(
                    context.GetArgument("id", defaultValue: new Guid("1ae34c3b-c1a0-4b7b-9375-c5a221d49e68")),
                    context.CancellationToken));

            this.FieldAsync <DroidObject, Droid>(
                "randomDroid",
                "Get a random droid from the database.",
                resolve: context =>
                droidRepository.GetRandomDroid(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.GetHuman(
                    context.GetArgument("id", defaultValue: new Guid("94fbd693-2027-4804-bf40-ed427fe76fda")),
                    context.CancellationToken));

            this.FieldAsync <HumanObject, Human>(
                "randomHuman",
                "Get a random human from the database.",
                resolve: context =>
                humanRepository.GetRandomHuman(context.CancellationToken));

            // Just include static info for info query in this case as it's not hitting the dummy repository/database.
            this.Field <InfoObject>(
                "info",
                resolve: context =>
            {
                return(new Info
                {
                    Id = "ed7584-2124-98fs-00s3-t739478t",
                    Name = "maana.io.template",
                    Description = "Dockerized ASP.NET Core GraphQL Template"
                });
            });
        }
        public QueryObject(
            IDroidRepository droidRepository,
            IHumanRepository humanRepository)
        {
            this.Name        = "Query";
            this.Description = "The query type, represents all of the entry points into our object graph.";

            this.FieldAsync <DroidObject, Droid>(
                "droid",
                "Get a droid by it's unique identifier.",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType>
            {
                Name        = "id",
                Description = "The unique identifier of the droid.",
            }),
                resolve: context =>
                droidRepository.GetDroid(
                    context.GetArgument("id", defaultValue: new Guid("1ae34c3b-c1a0-4b7b-9375-c5a221d49e68")),
                    context.CancellationToken));
            this.FieldAsync <HumanObject, Human>(
                "human",
                "Get a human by it's unique identifier.",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType>()
            {
                Name        = "id",
                Description = "The unique identifier of the human.",
            }),
                resolve: context => humanRepository.GetHuman(
                    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 => ResolveConnection(droidRepository, context));
        }
예제 #4
0
 public async Task <Human> GetHuman(int humanId)
 {
     return(await _repository.GetHuman(humanId));
 }