Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -20,7 +20,7 @@ jobs:

publish-npm:
needs: test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run Tests
on: [push]
jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion API_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Describes the shape and behaviour of the resources object you will pass to `getL
| `isBatchKeyASet` | (Optional) Set to true if the interface of the resource takes the batch key as a set (rather than an array). For example, when using a generated clientlib based on swagger where `uniqueItems: true` is set for the batchKey parameter. Default: false. |
| `propertyBatchKey` | (Optional) The argument to the resource that represents the optional properties we want to fetch. (e.g. usually 'properties' or 'features'). |
| `responseKey` | (Non-optional when propertyBatchKey is used) The key in the response objects corresponds to `batchKey`. This should be the only field that are marked as required in your swagger endpoint response, except nestedPath. |
| `maxBatchSize` | (Optional) Limits the number of items that can be batched together in a single request. When more items are requested than this limit, multiple requests will be made. This can help prevent hitting URI length limits or timeouts for large batches. |
| `maxBatchSize` | (Optional) Limits the number of items that can be batched together in a single request. When more items are requested than this limit, multiple requests will be made. This can help prevent hitting URI length limits or timeouts for large batches. |

### `typings`

Expand Down
52 changes: 26 additions & 26 deletions __tests__/implementation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,26 +1259,26 @@ test('batch endpoint with maxBatchSize', async () => {
},
},
};

// Track each batch of IDs that the resource function receives
const receivedBatches = [];

const resources = {
foo: ({ foo_ids, properties }) => {
receivedBatches.push([...foo_ids]);
return Promise.resolve(
foo_ids.map(id => ({
id,
name: `name-${id}`,
rating: id + 1
}))
foo_ids.map((id) => ({
id,
name: `name-${id}`,
rating: id + 1,
})),
);
},
};

await createDataLoaders(config, async (getLoaders) => {
const loaders = getLoaders(resources);

// Request 5 items at once, which should be split by maxBatchSize later in the test.
const results = await Promise.all([
loaders.foo.load({ foo_id: 1, properties: ['name', 'rating'] }),
Expand All @@ -1287,7 +1287,7 @@ test('batch endpoint with maxBatchSize', async () => {
loaders.foo.load({ foo_id: 4, properties: ['name', 'rating'] }),
loaders.foo.load({ foo_id: 5, properties: ['name', 'rating'] }),
]);

// Verify that all results were returned correctly
expect(results).toEqual([
{ id: 1, name: 'name-1', rating: 2 },
Expand All @@ -1296,10 +1296,10 @@ test('batch endpoint with maxBatchSize', async () => {
{ id: 4, name: 'name-4', rating: 5 },
{ id: 5, name: 'name-5', rating: 6 },
]);

// Verify that the requests were batched correctly
expect(receivedBatches.map(batch => batch.length)).toEqual([3, 2]);
expect(receivedBatches.map((batch) => batch.length)).toEqual([3, 2]);

// Verify that all IDs were requested
const allRequestedIds = receivedBatches.flat().sort();
expect(allRequestedIds).toEqual([1, 2, 3, 4, 5]);
Expand All @@ -1320,26 +1320,26 @@ test('batch endpoint with propertyBatchKey and maxBatchSize', async () => {
},
},
};

// Track each batch of IDs that the resource function receives
const receivedBatches = [];

const resources = {
foo: ({ foo_ids, properties }) => {
receivedBatches.push([...foo_ids]);
return Promise.resolve(
foo_ids.map(id => ({
id,
name: `name-${id}`,
rating: id + 1
}))
foo_ids.map((id) => ({
id,
name: `name-${id}`,
rating: id + 1,
})),
);
},
};

await createDataLoaders(config, async (getLoaders) => {
const loaders = getLoaders(resources);

// Request 5 items at once, which should be split by maxBatchSize later in the test.
const results = await Promise.all([
loaders.foo.load({ foo_id: 1, properties: ['name', 'rating'] }),
Expand All @@ -1348,7 +1348,7 @@ test('batch endpoint with propertyBatchKey and maxBatchSize', async () => {
loaders.foo.load({ foo_id: 4, properties: ['name', 'rating'] }),
loaders.foo.load({ foo_id: 5, properties: ['name', 'rating'] }),
]);

// Verify that all results were returned correctly
expect(results).toEqual([
{ id: 1, name: 'name-1', rating: 2 },
Expand All @@ -1357,10 +1357,10 @@ test('batch endpoint with propertyBatchKey and maxBatchSize', async () => {
{ id: 4, name: 'name-4', rating: 5 },
{ id: 5, name: 'name-5', rating: 6 },
]);

// Verify that the requests were batched correctly
expect(receivedBatches.map(batch => batch.length)).toEqual([2, 2, 1]);
expect(receivedBatches.map((batch) => batch.length)).toEqual([2, 2, 1]);

// Verify that all IDs were requested
const allRequestedIds = receivedBatches.flat().sort();
expect(allRequestedIds).toEqual([1, 2, 3, 4, 5]);
Expand Down