Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new Observable(observer => {
observer.next([{ data }, { data: data2 }, { data }]);
setTimeout(observer.complete.bind(observer));
}),
});
const query = gql`
query {
author {
firstName
lastName
}
}
`;
const operation: Operation = createOperation({}, { query });
const operation2: Operation = createOperation({}, { query });
const operation3: Operation = createOperation({}, { query });
batcher.enqueueRequest({ operation }).subscribe({});
batcher.enqueueRequest({ operation: operation2 }).subscribe({});
try {
expect(batcher.queuedRequests.get('').length).toBe(2);
} catch (e) {
done.fail(e);
}
setTimeout(() => {
// The batch shouldn't be fired yet, so we can add one more request.
batcher.enqueueRequest({ operation: operation3 }).subscribe({});
try {
expect(batcher.queuedRequests.get('').length).toBe(3);
} catch (e) {
done.fail(e);
batchHandler: () =>
new Observable(observer => {
observer.next([{ data }, { data: data2 }, { data }]);
setTimeout(observer.complete.bind(observer));
}),
});
const query = gql`
query {
author {
firstName
lastName
}
}
`;
const operation: Operation = createOperation({}, { query });
const operation2: Operation = createOperation({}, { query });
const operation3: Operation = createOperation({}, { query });
batcher.enqueueRequest({ operation }).subscribe({});
batcher.enqueueRequest({ operation: operation2 }).subscribe({});
try {
expect(batcher.queuedRequests.get('').length).toBe(2);
} catch (e) {
done.fail(e);
}
setTimeout(() => {
// The batch shouldn't be fired yet, so we can add one more request.
batcher.enqueueRequest({ operation: operation3 }).subscribe({});
try {
expect(batcher.queuedRequests.get('').length).toBe(3);
} catch (e) {
it('the fallbackConfig is used if no other configs are specified', () => {
const defaultHeaders = {
accept: '*/*',
'content-type': 'application/json',
};
const defaultOptions = {
method: 'POST',
};
const extensions = { yo: 'what up' };
const { options, body } = selectHttpOptionsAndBody(
createOperation({}, { query, extensions }),
fallbackHttpConfig,
);
expect(body).toHaveProperty('query');
expect(body).not.toHaveProperty('extensions');
expect(options.headers).toEqual(defaultHeaders);
expect(options.method).toEqual(defaultOptions.method);
});
it('returns the result of a UriFunction', () => {
const uri = '/somewhere';
const operation = createOperation({}, { query });
expect(selectURI(operation, () => uri)).toEqual(uri);
});
});
it('returns the result of a UriFunction', () => {
const uri = '/somewhere';
const operation = createOperation({}, { query });
expect(selectURI(operation, () => uri)).toEqual(uri);
});
});
it('should be able to consume from a queue containing multiple queries', done => {
const request2: Operation = createOperation(
{},
{
query,
},
);
const BH = createMockBatchHandler(
{
request: { query },
result: { data },
},
{
request: { query },
result: { data },
},
);
it('the fallbackConfig is used if no other configs are specified', () => {
const defaultHeaders = {
accept: '*/*',
'content-type': 'application/json',
};
const defaultOptions = {
method: 'POST',
};
const extensions = { yo: 'what up' };
const { options, body } = selectHttpOptionsAndBody(
createOperation({}, { query, extensions }),
fallbackHttpConfig,
);
expect(body).toHaveProperty('query');
expect(body).not.toHaveProperty('extensions');
expect(options.headers).toEqual(defaultHeaders);
expect(options.method).toEqual(defaultOptions.method);
});
return forward[0](operation[0]).map(d => [d]);
});
const link = ApolloLink.from([
new BatchLink({
batchInterval,
batchMax: 0,
batchHandler,
}),
() => Observable.of(42),
]);
execute(
link,
createOperation(
{},
{
query,
},
),
).subscribe({
next: data => {
try {
expect(data).toBe(42);
} catch (e) {
done.fail(e);
}
},
complete: () => {
mock(batchHandler.mock.calls.length);
},
batchHandler: () => {
return null;
},
});
const query = gql`
query {
author {
firstName
lastName
}
}
`;
const request: BatchableRequest = {
operation: createOperation({}, { query }),
};
expect(batcher.queuedRequests.get('')).toBeUndefined();
batcher.enqueueRequest(request).subscribe({});
expect(batcher.queuedRequests.get('').length).toBe(1);
batcher.enqueueRequest(request).subscribe({});
expect(batcher.queuedRequests.get('').length).toBe(2);
});