这是我的组件:
import React, { Component } from 'react';
import { gql, graphql, compose } from 'react-apollo';
export class Test extends Component {
render() {
console.log("this.props: " + JSON.stringify(this.props, null, 2));
return null;
}
}
const deletePostMutation = gql`
mutation deletePost ($_id: String) {
deletePost (_id: $_id)
}
`;
export const TestWithMutation = graphql(deletePostMutation)(Test)
这似乎是一个非常简单的例子,但是当我运行它时,道具是空的:
props: {}
您必须在模式中突变的解析函数中添加返回状态。
例:
resolve: function(source, args) {
// Add the user to the data store
exampleCollection.insert({
category: args.category,
subCategory: args.subCategory,
title: args.title,
description: args.description,
salary: args.salary,
region: args.region,
created_at: new Date()
});
// return some value.
return args.title;
}
实际上,上面问题中的代码就是一个很好的示例。 功能就在那里。问题是JSON.stringify没有显示函数🤦🏼 ♂️。至少这个问题可以作为如何做到这一点😀的一个例子