Esempio n. 1
0
        public StarWarsQuery(IStarWarsLogic logic)
        {
            Name = "Query";

            Field <CharacterInterface>("hero", resolve: context => logic.GetDroidByIdAsync("3"));
            Field <HumanType>("humans",
                              resolve: context => logic.RetrieveAllHumans()
                              );
            Field <HumanType>("human",
                              arguments: new QueryArguments(
                                  new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of human"
            }),
                              resolve: context => logic.GetHumanByIdAsync(context.GetArgument <string>("id"))
                              );

            Func <IResolveFieldContext, string, object> func = (context, id) => logic.GetDroidByIdAsync(id);

            FieldDelegate <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: func
                );
        }
Esempio n. 2
0
        public HumanType(IStarWarsLogic logic)
        {
            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 => logic.GetFriends(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>();
        }
Esempio n. 3
0
        public DroidType(IStarWarsLogic logic)
        {
            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 => logic.GetFriends(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>();
        }
        public StarWarsMutation(IStarWarsLogic logic)
        {
            _logic = logic;

            Name = "Mutation";

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