public DeletePostResponseType(ContextServiceLocator contextServiceLocator) { Field(x => x.Success); Field(x => x.Id); Field <ListGraphType <DeleteCommentDetailsType> >("comments", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var postId = context.Source.Id; var data = contextServiceLocator.ComemntService.DeleteCommentsBypostIdAsync(postId).ConfigureAwait(false).GetAwaiter().GetResult(); return(data.Select(x => new DeleteResponse { Success = "deleted", Id = x })); }, description: "all comments on given posts"); }
public UserMutation(ContextServiceLocator contextServiceLocator) { Field <DeletePostResponseType>( "deletePostsByUser", "delete posts by userId with all comments", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var id = context.GetArgument <string>("id"); var data = contextServiceLocator.PostService.DeletePostbyUserIdAsync(id).ConfigureAwait(false).GetAwaiter().GetResult(); return(new DeleteResponse { Success = data ? "deleted" : "failed", Id = id }); }); }
public GetPostResponseType(ContextServiceLocator contextServiceLocator) { Field <StringGraphType>("id", "Id"); Field <StringGraphType>("imageUrl"); Field <StringGraphType>("CreatedOn"); Field <ListGraphType <CommentDetailsType> >("comments", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var postId = (context.Source as PostResponse).Id; return(contextServiceLocator.ComemntService.GetCommentsBypostIdAsync(postId)); }, description: "all comments on given posts"); Field <PaginatedCommentDetailsType>("result", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }, new QueryArgument <IntGraphType> { Name = "pn" }, new QueryArgument <IntGraphType> { Name = "ps" }), resolve: context => { var pageNumber = context.GetArgument <int>("pn"); var pageSize = context.GetArgument <int>("ps"); var req = new PaginationRequest { PageNumber = pageNumber, PageSize = pageSize }; var comments = contextServiceLocator.ComemntService.GetPaginatedCommentsBypostIdAsync(context.Source.Id, req) .ConfigureAwait(false).GetAwaiter().GetResult(); return(comments); }, description: "comments on given posts with pagination"); }
public UserPostQuery(ContextServiceLocator contextServiceLocator) { Field <GetPostResponseType>( "post", "get post by id with al comments", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var id = context.GetArgument <string>("id"); return(contextServiceLocator.PostService.GetPostAsync(id).ConfigureAwait(false).GetAwaiter().GetResult()); }); Field <GetPostResponseType>( "postWithPaginatedComments", "get post by id with comments in paginated format", arguments: new QueryArguments(new QueryArgument <StringGraphType> { Name = "id" }), resolve: context => { var id = context.GetArgument <string>("id"); return(contextServiceLocator.PostService.GetPostAsync(id).ConfigureAwait(false).GetAwaiter().GetResult()); }); }