Beispiel #1
0
        public StarWarsQuery(StarWarsData data)
        {
            Name = "Query";

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

            Func <ResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id);

            FieldDelegate <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: func
                );
        }
Beispiel #2
0
        public StarWarsMutation(StarWarsData data)
        {
            Name = "Mutation";

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

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

            Field <HumanType>(
                "deleteHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the human"
            }
                    ),
                resolve: context =>
            {
                var human = new Human()
                {
                    Id = Guid.NewGuid().ToString()
                };
                return(human);
            });
            Field <HumanType>(
                "updateHuman",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <HumanInputType> > {
                Name = "human"
            }
                    ),
                resolve: context =>
            {
                var human = context.GetArgument <Human>("human");
                return(data.AddHuman(human));
            });
        }
Beispiel #4
0
        public StarWarsMutation(StarWarsData data)
        {
            Name = "Mutation";

            Field <HumanType>(
                "landingNavigation",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LandingNavigationInputType> > {
                Name = "human"
            }
                    ),
                resolve: context =>
            {
                var human = context.GetArgument <Human>("human");
                Console.WriteLine("Data-1: " + human);
                return(data.AddHuman(human));
            });
        }
Beispiel #5
0
 public StarWarsQuery(StarWarsData data, ICatalogService catalogService, ICustomerService customerService)
 {
     Name = "Query";
     Field <HumanType>(
         "landingNavigationRequest",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <LandingNavigationInputType> > {
         Name = "landingNavigation", Description = "id of the human"
     }
             ),
         resolve: context =>
     {
         var human   = context.GetArgument <HorusContainerRequest>("landingNavigation");
         var headers = (IDictionary <string, object>)context.UserContext;
         // use catalogService and customerService here
         // ....
         return(data.GetHumanByIdAsync(human));
     }
         );
 }
        public StarWarsMutation(StarWarsData data)
        {
            Name = "Mutation";

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

                human = human ?? new Human
                {
                    Id   = Guid.NewGuid().ToString(),
                    Name = "User" + Guid.NewGuid()
                };

                return(data.AddHuman(human));
            });
        }
Beispiel #7
0
        public StarWarsQuery(StarWarsData data)
        {
            Name = "Query";

            Connection <CharacterInterface>()
            .Name("characters")
            .Description("RandomDescription")
            .Bidirectional()
            .Resolve(context =>
            {
                var source     = data.GetAll();
                var totalCount = source.Count;
                IEnumerable <StarWarsCharacter> characters = source;

                if (context.After != null)
                {
                    var index = source.Select(x => x.Id).ToList().IndexOf(context.After);

                    if (index > -1)
                    {
                        characters = characters.Skip(index + 1);
                    }
                }

                if (context.Before != null)
                {
                    var index = source.Select(x => x.Id).ToList().IndexOf(context.Before);

                    source = source.Take(index).ToList();
                }

                if (context.First.HasValue)
                {
                    characters = characters.Take(context.First.Value);
                }
                else if (context.Last.HasValue)
                {
                    characters = source.Skip(Math.Max(0, source.Count - context.Last.Value));
                }

                return(new Connection <StarWarsCharacter>
                {
                    TotalCount = totalCount,
                    PageInfo = new PageInfo
                    {
                        HasNextPage = true,
                        HasPreviousPage = false,
                        StartCursor = "1",
                        EndCursor = "4",
                    },
                    Edges = new List <Edge <StarWarsCharacter> >(characters.Select(node =>
                                                                                   new Edge <StarWarsCharacter>
                    {
                        Cursor = node.Id,
                        Node = node
                    }
                                                                                   ))
                });
            });

            /*Field<ListGraphType<CharacterInterface>>(
             *  "characters", resolve: context => data.GetAllAsync());*/

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

            Func <ResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id);

            FieldDelegate <DroidType>(
                "droid",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id", Description = "id of the droid"
            }
                    ),
                resolve: func
                );
        }