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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'node:crypto';
import { PlainMessage } from '@bufbuild/protobuf';
import pLimit from 'p-limit';
import { Code, ConnectError, HandlerContext } from '@connectrpc/connect';
import { HandlerContext } from '@connectrpc/connect';
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import {
PublishedOperation,
Expand Down Expand Up @@ -47,10 +47,13 @@ export function publishPersistedOperations(
}

if (req.operations.length > MAX_PERSISTED_OPERATIONS) {
throw new ConnectError(
`Payload Too Large: max ${MAX_PERSISTED_OPERATIONS} operations per request`,
Code.ResourceExhausted,
);
return {
response: {
code: EnumStatusCode.ERR,
details: `Payload Too Large: max ${MAX_PERSISTED_OPERATIONS} operations per request`,
},
operations: [],
};
}

const userId = authContext.userId;
Expand Down
24 changes: 10 additions & 14 deletions controlplane/test/persisted-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,16 @@ describe('Persisted operations', (ctx) => {
contents: `query { hello }`,
}));

let error: unknown;
try {
await client.publishPersistedOperations({
fedGraphName,
namespace: 'default',
clientName: 'test-client',
operations,
});
} catch (err) {
error = err;
}

expect(error).toBeInstanceOf(ConnectError);
expect(error).toMatchObject({ code: Code.ResourceExhausted });
const overLimitResp = await client.publishPersistedOperations({
fedGraphName,
namespace: 'default',
clientName: 'test-client',
operations,
});

expect(overLimitResp.response?.code).toBe(EnumStatusCode.ERR);
expect(overLimitResp.response?.details).toContain('Payload Too Large: max 100 operations per request');
expect(overLimitResp.operations).toEqual([]);
});

test('Should not publish persisted operations with an invalid federated graph name', async (testContext) => {
Expand Down
Loading