relay refetch不显示结果

时间:2017-07-18 08:06:18

标签: graphql relay react-relay relaymodern

我正在尝试创建一个实时搜索结果组件(延迟加载一个)。它首次完美运行,但 refetch 不会更新数据。我在Network标签中看到了请求和重新声明!所以它确实得到了数据,但它没有提供给组件!

任何想法为什么?

import React, { Component } from 'react';
import {
    createRefetchContainer,
    graphql,
} from 'react-relay';

import ProfileShow from './ProfileShow';

class ProfileList extends Component {
    render() {
        console.log("rendering....", this.props)
        return (
            <div className="row">
                <input type="text" onClick={this._loadMe.bind(this)} />
                {this.props.persons.map((person) => {
                    return (
                        <div className="col-md-3">
                            <ProfileShow person={person} />
                        </div>
                    );
                })}

            </div>
        );
    }
    _loadMe(e) {
        const refetchVariables = fragmentVariables => ({
            queryStr: e.target.value,
        });

        this.props.relay.refetch(refetchVariables, null, (...data) => {
            console.log(data)
        });
    }
}

const FragmentContainer = createRefetchContainer(
    ProfileList,
    {
        persons: graphql.experimental`
        fragment ProfileList_persons on Person @relay(plural: true) {
            fullname
            number
            email
            pic
        }
    `
    },
    graphql.experimental`
    query ProfileListRefetchQuery($queryStr: String!) {
        talentList(query: $queryStr) {
        ...ProfileList_persons
        }
    }
  `,
);

export default FragmentContainer;

0 个答案:

没有答案