Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO: the proper thing to do here is throw an error saying to
// add `client.onResetStore(link.writeDefaults);`
// waiting on https://github.com/apollographql/apollo-client/pull/3010
return (
// Support nested fields
(aliasNeeded ? aliasedNode : preAliasingNode) ||
(defaults || {})[fieldName]
);
};
if (server) operation.query = server;
const obs =
server && forward
? forward(operation)
: Observable.of({
data: {},
});
return new Observable(observer => {
// Works around race condition between completion and graphql execution
// finishing. If complete is called during the graphql call, we will
// miss out on the result, since the observer will have completed
let complete = false;
let handlingNext = false;
obs.subscribe({
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
public request (operation: Operation, forward?: NextLink) {
const isRestQuery = hasDirectives(['rest'], operation.query)
if (!isRestQuery && forward) return forward(operation)
const nonRestQuery = removeRestDirective(operation.query)
const typeNamedQuery = addTypenameToDocument(operation.query)
const observable =
nonRestQuery && forward
? // tslint:disable-next-line:prefer-object-spread
forward(Object.assign(operation, { query: nonRestQuery }))
: Observable.of({ data: {} })
return observable.flatMap(
({ data, ...rest }) =>
new Observable(subscriber => {
graphql(
resolver,
typeNamedQuery,
data,
this.resolverMap,
operation.variables
)
.then(resolvedData => {
subscriber.next({ data: resolvedData, ...rest })
subscriber.complete()
})
.catch(err => {
if (err.name === 'AbortError') return
request => {
expect(request.operationName).toBe('myMutationName');
return Observable.of({ data });
},
]);
const link = new ApolloLink(() =>
Observable.of({ data: { baz: { foo: true, __typename: 'Baz' } } }),
);
const link = new ApolloLink((operation, forward) => {
const { getCacheKey } = operation.getContext();
expect(getCacheKey).toBeDefined();
expect(getCacheKey({ id: 1, __typename: 'Book' })).toEqual('Book:1');
return Observable.of({ data: bookData });
});
const stub = jest.fn(() => Observable.of(data));
const link = ApolloLink.from([retry, stub]);
const terminating = new ApolloLink(operation => {
try {
expect(operation.query).toEqual(query);
} catch (e) {
done.fail(e);
}
return Observable.of(operation.variables.count);
});
() => new BatchLink({ batchHandler: () => Observable.of() }),
).not.toThrow();
new ApolloLink((operation, forward) => {
if (fetchPolicy === "no-cache") return forward(operation);
const { cache } = operation.getContext();
const { variables, query } = operation;
try {
const results = cache.readQuery({ query, variables });
if (results) return Observable.of({ data: results });
} catch (e) {}
return forward(operation);
});
export const passthroughLink = (op, forward) => (forward ? forward(op) : Observable.of());