Ejemplo n.º 1
0
        public StarWarsQuery(IStarWarsRepo repo)
        {
            Name = "Query";

            Field <ListGraphType <HumanType> >(
                name: "humans",
                resolve: context => repo.GetHumansAsync()
                );

            Field <HumanType>(
                name: "human",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the human"
            }
                    ),
                resolve: context => repo.GetHumanAsync(context.GetArgument <Guid>("id"))
                );

            Field <ListGraphType <DroidType> >(
                name: "droids",
                resolve: context => repo.GetDroidsAsync()
                );

            Field <DroidType>(
                name: "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "droid ID"
            }),
                resolve: context => repo.GetDroidAsync(context.GetArgument <Guid>("id")));
        }
Ejemplo n.º 2
0
        public StarWarsMutation(IStarWarsRepo repo)
        {
            Name = "Mutation";

            Field <HumanType>(
                "createHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <HumanInputType> > {
                Name = "human"
            }
                    ),
                resolve: context =>
            {
                Human human = context.GetArgument <Human>("human");
                return(repo.AddHumanAsync(human));
            });

            Field <HumanType>(
                name: "deleteHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <HumanInputType> >
            {
                Name = "human"
            }),
                resolve: context =>
            {
                Human human = context.GetArgument <Human>("human");
                return(repo.DeleteHumanAsync(human));
            });
        }
Ejemplo n.º 3
0
        public DroidType(IStarWarsRepo repo)
        {
            Name        = "Droid";
            Description = "A mechanical creature in the Star Wars universe.";

            Field(d => d.Id).Description("The id of the droid.");
            Field(d => d.Name, nullable: true).Description("The name of the droid.");

            Field <ListGraphType <CharacterInterface> >(
                "friends",
                resolve: context => repo.GetFriendsAsync(context.Source)
                );
            Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in.");
            Field(d => d.PrimaryFunction, nullable: true).Description("The primary function of the droid.");

            Interface <CharacterInterface>();
        }
Ejemplo n.º 4
0
        public HumanType(IStarWarsRepo repo)
        {
            Name = "Human";

            Field(h => h.Id).Description("The id of the human.");
            Field(h => h.Name, nullable: true).Description("The name of the human.");

            Field <ListGraphType <CharacterInterface> >(
                "friends",
                resolve: context => repo.GetFriendsAsync(context.Source)
                );
            Field <ListGraphType <EpisodeEnum> >("appearsIn", "Which movie they appear in.");

            Field(h => h.HomePlanet, nullable: true).Description("The home planet of the human.");

            Interface <CharacterInterface>();
        }