Skip to content

Commit

Permalink
feat: Add introspection, resolverCountLImit and queryDepthLImit config (
Browse files Browse the repository at this point in the history
  • Loading branch information
bboure committed Dec 30, 2023
1 parent 3634639 commit d2f2c60
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ describe('Api', () => {
`);
});

it('should compile the Api Resource with config', () => {
const api = new Api(
given.appSyncConfig({
introspection: false,
queryDepthLimit: 10,
resolverCountLimit: 20,
}),
plugin,
);
expect(api.compileEndpoint()).toMatchInlineSnapshot(`
Object {
"GraphQlApi": Object {
"Properties": Object {
"AuthenticationType": "API_KEY",
"IntrospectionConfig": "DISABLED",
"Name": "MyApi",
"QueryDepthLimit": 10,
"ResolverCountLimit": 20,
"Tags": Array [
Object {
"Key": "stage",
"Value": "Dev",
},
],
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
},
}
`);
});

it('should compile the Api Resource with logs enabled', () => {
const api = new Api(
given.appSyncConfig({
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/validation/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,13 @@ exports[`Valdiation should validate 1`] = `
/unknownPorp: invalid (unknown) property
/xrayEnabled: must be boolean
/visibility: must be \\"GLOBAL\\" or \\"PRIVATE\\"
/introspection: must be boolean
/queryDepthLimit: must be integer
/resolverCountLimit: must be integer
/esbuild: must be an esbuild config object or false"
`;

exports[`Valdiation should validate 2`] = `
"/queryDepthLimit: must be <= 75
/resolverCountLimit: must be <= 1000"
`;
14 changes: 14 additions & 0 deletions src/__tests__/validation/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe('Valdiation', () => {
validateConfig({
...basicConfig,
visibility: 'GLOBAL',
introspection: true,
queryDepthLimit: 10,
resolverCountLimit: 10,
xrayEnabled: true,
tags: {
foo: 'bar',
Expand All @@ -23,11 +26,22 @@ describe('Valdiation', () => {
expect(function () {
validateConfig({
visibility: 'FOO',
introspection: 10,
queryDepthLimit: 'foo',
resolverCountLimit: 'bar',
xrayEnabled: 'BAR',
unknownPorp: 'foo',
esbuild: 'bad',
});
}).toThrowErrorMatchingSnapshot();

expect(function () {
validateConfig({
...basicConfig,
queryDepthLimit: 76,
resolverCountLimit: 1001,
});
}).toThrowErrorMatchingSnapshot();
});

describe('Log', () => {
Expand Down
18 changes: 18 additions & 0 deletions src/resources/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ export class Api {
});
}

if (this.config.introspection !== undefined) {
merge(endpointResource.Properties, {
IntrospectionConfig: this.config.introspection ? 'ENABLED' : 'DISABLED',
});
}

if (this.config.queryDepthLimit !== undefined) {
merge(endpointResource.Properties, {
QueryDepthLimit: this.config.queryDepthLimit,
});
}

if (this.config.resolverCountLimit !== undefined) {
merge(endpointResource.Properties, {
ResolverCountLimit: this.config.resolverCountLimit,
});
}

const resources = {
[logicalId]: endpointResource,
};
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type AppSyncConfig = {
tags?: Record<string, string>;
visibility?: 'GLOBAL' | 'PRIVATE';
esbuild?: BuildOptions | false;
introspection?: boolean;
queryDepthLimit?: number;
resolverCountLimit?: number;
};

export type BaseResolverConfig = {
Expand Down
3 changes: 3 additions & 0 deletions src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export type AppSyncConfig = {
tags?: Record<string, string>;
visibility?: 'GLOBAL' | 'PRIVATE';
esbuild?: BuildOptions | false;
introspection?: boolean;
queryDepthLimit?: number;
resolverCountLimit?: number;
};

export type BaseResolverConfig = {
Expand Down
3 changes: 3 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ export const appSyncSchema = {
enum: ['GLOBAL', 'PRIVATE'],
errorMessage: 'must be "GLOBAL" or "PRIVATE"',
},
introspection: { type: 'boolean' },
queryDepthLimit: { type: 'integer', minimum: 1, maximum: 75 },
resolverCountLimit: { type: 'integer', minimum: 1, maximum: 1000 },
substitutions: { $ref: '#/definitions/substitutions' },
waf: {
type: 'object',
Expand Down

0 comments on commit d2f2c60

Please sign in to comment.