示例#1
0
        public HumanObject(IHumanRepository humanRepository)
        {
            this.Name        = "Human";
            this.Description = "A humanoid creature from the Star Wars universe.";
#if (Authorization)
            // this.AuthorizeWith(AuthorizationPolicyName.Admin); // To require authorization for all fields in this type.
#endif

            this.Field(x => x.Id, type: typeof(IdGraphType))
            .Description("The unique identifier of the human.");
            this.Field(x => x.Name)
            .Description("The name of the human.");
            this.Field(x => x.DateOfBirth)
#if (Authorization)
            .AuthorizeWith(AuthorizationPolicyName.Admin)     // Require authorization to access the date of birth field.
#endif
            .Description("The humans date of birth.");
            this.Field(x => x.HomePlanet, nullable: true)
            .Description("The home planet of the human.");
            this.Field(x => x.AppearsIn, type: typeof(ListGraphType <EpisodeEnumeration>))
            .Description("Which movie they appear in.");

            this.FieldAsync <ListGraphType <CharacterInterface>, List <Character> >(
                nameof(Human.Friends),
                "The friends of the character, or an empty list if they have none.",
                resolve: context => humanRepository.GetFriends(context.Source, context.CancellationToken));

            this.Interface <CharacterInterface>();
        }
示例#2
0
        public HumanObject(IHumanRepository humanRepository)
        {
            this.Name = "Human";
            this.Description = "A humanoid creature from the Star Wars universe.";

            this.Field(x => x.Id, type: typeof(IdGraphType)).Description("The unique identifier of the human.");
            this.Field(x => x.Name).Description("The name of the human.");
            this.Field(x => x.HomePlanet, nullable: true).Description("The home planet of the human.");
            this.Field<ListGraphType<EpisodeEnumeration>>(nameof(Character.AppearsIn), "Which movie they appear in.");

            this.FieldAsync<ListGraphType<CharacterInterface>, List<Character>>(
                nameof(Human.Friends),
                "The friends of the character, or an empty list if they have none.",
                resolve: context => humanRepository.GetFriends(context.Source, context.CancellationToken));

            this.Interface<CharacterInterface>();
        }