public NewsfeedQuery(INewsfeedData newsfeedData)
        {
            Name = nameof(NewsfeedQuery);

            Field <ListGraphType <StoryType> >(
                name: "getNewsfeed",
                description: "Get the lastest stories",
                resolve: context => newsfeedData.GetNewsfeed());

            Field <ListGraphType <AuthorType> >(
                name: "getAuthors",
                description: "Get the authors behind the stories in the newsfeed",
                resolve: context => newsfeedData.GetAuthors());

            Field <AuthorType>(
                name: "getAuthor",
                description: "Get a single author",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> >
            {
                Name        = "authorId",
                Description = "The unique ID of the author"
            }
                    ),
                resolve: context => newsfeedData.GetAuthor(context.GetArgument <int>("authorId")));
        }
Exemple #2
0
        public NewsfeedSubscription(INewsfeedData newsfeedData)
        {
            Name = nameof(NewsfeedSubscription);

            AddField(new EventStreamFieldType
            {
                Name       = "subscribeToNewsfeed",
                Type       = typeof(StoryType),
                Resolver   = new FuncFieldResolver <Story>(context => context.Source as Story),
                Subscriber = new EventStreamResolver <Story>(context => newsfeedData.SubscribeToNewsfeed())
            });
        }
        public NewsfeedMutation(INewsfeedData newsfeedData)
        {
            Name = nameof(NewsfeedMutation);

            Field <AuthorType>(
                name: "addAuthor",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "name",
                Description = "The name of the author"
            }),
                resolve: context => newsfeedData.AddAuthor(context.GetArgument <string>("name"))
                );

            Field <StoryType>(
                name: "addStory",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> >
            {
                Name        = "authorId",
                Description = "The unique ID of an author"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "title",
                Description = "The title of the story"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "body",
                Description = "The body text of the story"
            }),
                resolve: context => newsfeedData.AddStory(
                    context.GetArgument <int>("authorId"),
                    context.GetArgument <string>("title"),
                    context.GetArgument <string>("body"))
                );
        }