Ejemplo n.º 1
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));
        }