本文整理汇总了TypeScript中apollo-link.Operation.getContext方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Operation.getContext方法的具体用法?TypeScript Operation.getContext怎么用?TypeScript Operation.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apollo-link.Operation
的用法示例。
在下文中一共展示了Operation.getContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: terminatingCheck
terminatingCheck(done, () => {
// The batch should've been fired by now.
expect(operation.getContext()).toEqual({ response: { data } });
expect(operation2.getContext()).toEqual({ response: { data: data2 } });
expect(operation3.getContext()).toEqual({ response: { data } });
expect(batcher.queuedRequests.get('')).toBeUndefined();
}),
示例2: Error
entityObserver.subscribe(entity => {
const query = queries[entity.fieldName];
if (!query) {
throw new Error(`unknown fieldName: ${entity.fieldName}`);
}
let executeQuery = this._executeQuery;
if (!executeQuery) {
const client: ApolloClient<never> = operation.getContext().client;
if (client instanceof ApolloClient === false) {
console.error(`client can't fine`, operation.getContext());
throw new Error(`client can't find`);
}
executeQuery = ({ query, variables }) => {
return client.query({
query,
variables,
});
};
}
executeQuery({
query,
variables: { id: entity.id },
})
.then(result => {
observer.next(result);
})
.catch(e => {
observer.error(e);
});
});
示例3: selectURI
((operation: Operation) => {
const context = operation.getContext();
const contextConfig = {
http: context.http,
options: context.fetchOptions,
credentials: context.credentials,
headers: context.headers,
};
//may throw error if config not serializable
return selectURI(operation, uri) + JSON.stringify(contextConfig);
});
示例4: graphql
next: ({ data, errors }) => {
const observerErrorHandler = observer.error.bind(observer);
const context = operation.getContext();
handlingNext = true;
//data is from the server and provides the root value to this GraphQL resolution
//when there is no resolver, the data is taken from the context
graphql(resolver, query, data, context, operation.variables, {
fragmentMatcher,
})
.then(nextData => {
observer.next({
data: nextData,
errors,
});
if (complete) {
observer.complete();
}
handlingNext = false;
})
.catch(observerErrorHandler);
},
示例5: setter
.then(req => setter(req, operation.getContext()))