本文整理匯總了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()))