Apollo GraphQL一次性查询?

时间:2017-06-10 23:28:49

标签: graphql apollo react-apollo

我正在将我的代码从使用6个月以上版本的Apollo升级到使用当前版本。

此代码用于执行一次性查询,但不再有效:

设置

const subscriptionClient = new SubscriptionClient(`ws://localhost:5000/`, {
    reconnect: true
});

// Create a normal network interface:
const networkInterface = createNetworkInterface({
    uri: 'http://localhost:3000',
    opts: {
        credentials: 'same-origin',
    },
    transportBatching: true,
    batchInterval: 10

});

// Extend the network interface with the WebSocket
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
    networkInterface,
    subscriptionClient
);

const ApolloClientWithSubscribeEnabled = new ApolloClient({
    networkInterface: networkInterfaceWithSubscriptions,
    queryTransformer: addTypename,
    dataIdFromObject: (result) => {
        if (result.id && result.__typename) { // eslint-disable-line no-underscore-dangle
            return result.__typename + result.id; // eslint-disable-line no-underscore-dangle
        }
        return null;
    },
    shouldBatch: true,
    initialState: window.__APOLLO_STATE__, // eslint-disable-line no-underscore-dangle
});

一次性查询

getUserInfoForCurrentUser() {
    const userIsLoggedIn = Meteor.userId() ? true : false;
    if ((userIsLoggedIn) && (this.originatingUser == null)){
        const localThis = this;
        const userID = Meteor.userId();
        this.client.query({
            query: GET_USER_INFO_QUERY,
            variables: {userID: userID},
        }).then((result) => {
            localThis.originatingUser = result.data.getUserData[0];
        });
    }
}

搜索Apollo文档时,我看到a reference to one-off queries,但我还没有找到显示如何操作的文档。在搜索Apollo示例应用程序“GitHunt-React-master”时,我还没有找到如何执行此操作的示例。

在当前1.x版本的Apollo中进行一次性查询的正确方法是什么?

0 个答案:

没有答案