Apollo mutation not appearing in props

时间:2017-04-10 03:04:31

标签: reactjs meteor apollo react-apollo apollo-client

Here's my component:

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)

This seems like a pretty simple example, but when I run it the props are empty:

props: {}

2 个答案:

答案 0 :(得分:0)

您必须在架构中的突变解析函数中添加 return statemant。

示例:



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;
}




答案 1 :(得分:0)

实际上上面问题中的代码是如何做到这一点的一个很好的例子。那里的功能。问题是JSON.stringify没有显示函数♂️。至少这个问题是如何做的一个例子