尝试进行突变时,_this.networkInterface.query不是函数

时间:2018-10-20 18:32:36

标签: graphql react-apollo apollo-client

这是我第一次尝试使用apollo-graphql进行突变,并且似乎遇到了一个我不知道真正含义是什么的错误。

这是我在store.js中创建networkInterface的地方。

import { createStore, applyMiddleware } from 'redux';
import { AsyncStorage } from 'react-native';
import { composeWithDevTools } from 'redux-devtools-extension';
import { ApolloClient, createNetworkInterface } from 'react-apollo';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';
import { SubscriptionClient } from 'subscriptions-transport-ws';

import reducers from './redux/reducers';

const networkInterface = createNetworkInterface({
    uri: 'http://localhost:3000/graphql',
});

const wsClient = new SubscriptionClient('ws://localhost:3000/subscriptions', {
    reconnect: true,
    connectionParams: {}
})

networkInterface.use([{
    async applyMiddleware(req, next) {
        if (!req.options.headers) {
            req.options.headers = {};
        }
        try {
            const token = await AsyncStorage.getItem('@tomj');
            if (token != null) {
                req.options.headers.authorization = `Bearer ${token}` || null;
            }
        } catch (error) {
            throw error;
        }

        return next();
    }
}])

const networkInterfaceWithSubs = ({
    networkInterface,
    wsClient
})

export const client = new ApolloClient({
    networkInterface: networkInterfaceWithSubs
});

const middlewares = [client.middleware(), thunk, createLogger()];

export const store = createStore(
    reducers(client),
    undefined,
    composeWithDevTools(applyMiddleware(...middlewares)),
);

这也是错误来自const { data }

的注册功能
onSignUpPress = async () => {
    const { email, password, phone, role } = this.state;
    this.setState({ loadingVisible: true });
    setTimeout(() => {
        if (typeof email && password && phone && role != '') {
            this.setState({
                loadingVisible: false,
                formValid: true,
            });
            const { data } = this.props.mutate({
                variables: {
                    email,
                    password,
                    phone,
                    role
                }
            })
        } else {
            this.setState({
                loadingVisible: false,
                formValid: false,
            });
        }
    }, 2000);
}

我想提到我正在使用"react-apollo": "^1.4",

0 个答案:

没有答案