public CommentMutation(ICommentProxy commentProxy, IMapper mapper) { FieldAsync <CommentType>( "createcomment", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CommentCreateInputType> > { Name = nameof(CommentCreateInputType).FirstCharToLower() } ), resolve: async context => { var requestData = context.GetArgument <Comment>(nameof(CommentCreateInputType).FirstCharToLower()); if (requestData == null) { throw new GraphQL.ExecutionError("Vui lòng nhập dữ liệu"); } return(await commentProxy.AddUpdateComments(requestData, context.CancellationToken)); }); FieldAsync <CommentType>( "updatecomment", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CommentUpdateInputType> > { Name = nameof(CommentUpdateInputType).FirstCharToLower() } ), resolve: async context => { var requestData = context.GetArgument <Comment>(nameof(CommentUpdateInputType).FirstCharToLower()); if (requestData == null) { throw new GraphQL.ExecutionError("Vui lòng nhập dữ liệu"); } var data = await commentProxy.GetCommentById(requestData.Id, context.CancellationToken); //Map without null properties data = mapper.Map <Comment, Comment>(requestData, data); return(await commentProxy.AddUpdateComments(data, context.CancellationToken)); }); }
public CommentQuery(ICommentProxy conmentProxy) { FieldAsync <ListGraphType <CommentType> >("queryComment", arguments: new QueryArguments(new List <QueryArgument> { new QueryArgument <IdGraphType> { Name = nameof(Comment.Id).FirstCharToLower() }, //new QueryArgument<GraphQL.Types.StringGraphType> //{ // Name = nameof(Comment.Name).FirstCharToLower() //}, //new QueryArgument<GraphQL.Types.StringGraphType> //{ // Name =nameof(Comment.Email).FirstCharToLower() //}, new QueryArgument <GraphQL.Types.IntGraphType> { Name = nameof(Comment.PostId).FirstCharToLower() } }), resolve: async context => { var queryParams = new Dictionary <string, string>(); var postIdArgument = context.GetArgument <int?>(nameof(Comment.PostId).FirstCharToLower()); if (postIdArgument.HasValue) { queryParams.Add(nameof(Comment.PostId).FirstCharToLower(), postIdArgument.Value.ToString()); } var idArgument = context.GetArgument <int?>(nameof(Comment.Id).FirstCharToLower()); if (idArgument.HasValue) { queryParams.Add(nameof(Comment.Id).FirstCharToLower(), idArgument.Value.ToString()); } return(await conmentProxy.GetComments(queryParams, context.CancellationToken)); } ); }