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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/aio-cli-plugin-api-mesh",
"version": "5.6.6",
"version": "5.7.0-beta.1",
"description": "Adobe I/O CLI plugin to develop and manage API mesh sources",
"keywords": [
"oclif-plugin"
Expand Down Expand Up @@ -38,7 +38,7 @@
"version": "oclif-dev readme && git add README.md"
},
"dependencies": {
"@adobe-apimesh/mesh-builder": "^2.4.1",
"@adobe-apimesh/mesh-builder": "^2.5.1",
"@adobe/aio-cli-lib-console": "^5.0.0",
"@adobe/aio-lib-core-config": "^5.0.0",
"@adobe/aio-lib-core-logging": "^3.0.0",
Expand All @@ -48,6 +48,7 @@
"@adobe/plugin-on-fetch": "0.1.1",
"@adobe/plugin-source-headers": "^0.0.2",
"@envelop/disable-introspection": "^6.0.0",
"@escape.tech/graphql-armor": "3.2.0",
"@graphql-mesh/cli": "0.82.30",
"@graphql-mesh/graphql": "0.34.13",
"@graphql-mesh/http": "^0.96.9",
Expand Down
23 changes: 23 additions & 0 deletions src/commands/__fixtures__/sample_mesh_with_queryConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"meshConfig": {
"sources": [
{
"name": "<api_name>",
"handler": {
"graphql": {
"endpoint": "<gql_endpoint>"
}
}
}
],
"queryConfig": {
"maxDepth": { "enabled": true, "limit": 4 },
"maxAliases": { "enabled": true, "limit": 10 },
"maxTokens": { "enabled": true, "limit": 500 },
"maxDirectives": { "enabled": true, "limit": 20 },
"costLimit": { "enabled": true, "maxCost": 1000 },
"blockFieldSuggestion": { "enabled": true, "mask": "[hidden]" },
"maskErrors": { "enabled": true, "message": "Something went wrong." }
}
}
}
72 changes: 72 additions & 0 deletions src/commands/api-mesh/__tests__/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jest.mock('../../../lib/smsClient');
const CreateCommand = require('../create');
const sampleCreateMeshConfig = require('../../__fixtures__/sample_mesh.json');
const meshConfigWithComposerFiles = require('../../__fixtures__/sample_mesh_with_composer_files.json');
const sampleMeshWithQueryConfig = require('../../__fixtures__/sample_mesh_with_queryConfig.json');
const { initSdk, promptConfirm, interpolateMesh, importFiles } = require('../../../helpers');
const {
getMesh,
Expand Down Expand Up @@ -407,6 +408,77 @@ describe('create command tests', () => {
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
});

test('should pass queryConfig fields through to createMesh without modification', async () => {
createMesh.mockResolvedValueOnce({
mesh: {
meshId: 'dummy_mesh_id',
meshConfig: sampleMeshWithQueryConfig.meshConfig,
},
});
parseSpy.mockResolvedValueOnce({
args: { file: 'src/commands/__fixtures__/sample_mesh_with_queryConfig.json' },
flags: {
ignoreCache: mockIgnoreCacheFlag,
autoConfirmAction: mockAutoApproveAction,
},
});
await CreateCommand.run();
expect(createMesh.mock.calls[0]).toMatchInlineSnapshot(`
[
"CODE1234@AdobeOrg",
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"queryConfig": {
"blockFieldSuggestion": {
"enabled": true,
"mask": "[hidden]",
},
"costLimit": {
"enabled": true,
"maxCost": 1000,
},
"maskErrors": {
"enabled": true,
"message": "Something went wrong.",
},
"maxAliases": {
"enabled": true,
"limit": 10,
},
"maxDepth": {
"enabled": true,
"limit": 4,
},
"maxDirectives": {
"enabled": true,
"limit": 20,
},
"maxTokens": {
"enabled": true,
"limit": 500,
},
},
"sources": [
{
"handler": {
"graphql": {
"endpoint": "<gql_endpoint>",
},
},
"name": "<api_name>",
},
],
},
},
]
`);
});

test('should create and return Ti mesh url if a valid mesh config file for TI client is provided', async () => {
let fetchedMeshConfig = sampleCreateMeshConfig;
fetchedMeshConfig.meshId = 'dummy_id';
Expand Down
20 changes: 20 additions & 0 deletions src/commands/api-mesh/__tests__/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,26 @@ describe('run command tests', () => {
);
});

test('should successfully run the mesh with queryConfig', async () => {
const cliInput = {
args: { file: 'src/commands/__fixtures__/sample_mesh_with_queryConfig.json' },
flags: {
port: 5000,
debug: false,
inspectPort: 9229,
},
};
parseSpy.mockResolvedValueOnce(cliInput);

await RunCommand.run();
expect(start).toHaveBeenCalledWith(
expect.anything(),
cliInput.flags.port,
cliInput.flags.debug,
cliInput.flags.inspectPort,
);
});

test('should escape variables that are preceded by backslash symbol', async () => {
const cliInput = {
args: { file: 'src/commands/__fixtures__/sample_mesh_with_escaped_secrets.json' },
Expand Down
149 changes: 149 additions & 0 deletions src/commands/api-mesh/__tests__/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,155 @@ describe('update command tests', () => {
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
});

test('should pass queryConfig with all fields enabled through to updateMesh', async () => {
const meshWithQueryConfigEnabled = {
meshConfig: {
sources: [{ name: '<api_name>', handler: { graphql: { endpoint: '<gql_endpoint>' } } }],
queryConfig: {
maxDepth: { enabled: true, limit: 4 },
maxAliases: { enabled: true, limit: 10 },
maxTokens: { enabled: true, limit: 500 },
maxDirectives: { enabled: true, limit: 20 },
costLimit: { enabled: true, maxCost: 1000 },
blockFieldSuggestion: { enabled: true, mask: '[hidden]' },
maskErrors: { enabled: true, message: 'Something went wrong.' },
},
},
};
readFile.mockResolvedValueOnce(JSON.stringify(meshWithQueryConfigEnabled));
parseSpy.mockResolvedValueOnce({
args: { file: 'src/commands/__fixtures__/sample_mesh_with_queryConfig.json' },
flags: { ignoreCache: mockIgnoreCacheFlag, autoConfirmAction: mockAutoApproveAction },
});
await UpdateCommand.run();
expect(updateMesh.mock.calls[0]).toMatchInlineSnapshot(`
[
"CODE1234@AdobeOrg",
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
"mesh_id",
{
"meshConfig": {
"queryConfig": {
"blockFieldSuggestion": {
"enabled": true,
"mask": "[hidden]",
},
"costLimit": {
"enabled": true,
"maxCost": 1000,
},
"maskErrors": {
"enabled": true,
"message": "Something went wrong.",
},
"maxAliases": {
"enabled": true,
"limit": 10,
},
"maxDepth": {
"enabled": true,
"limit": 4,
},
"maxDirectives": {
"enabled": true,
"limit": 20,
},
"maxTokens": {
"enabled": true,
"limit": 500,
},
},
"sources": [
{
"handler": {
"graphql": {
"endpoint": "<gql_endpoint>",
},
},
"name": "<api_name>",
},
],
},
},
]
`);
});

test('should pass queryConfig with all fields disabled through to updateMesh', async () => {
const meshWithQueryConfigDisabled = {
meshConfig: {
sources: [{ name: '<api_name>', handler: { graphql: { endpoint: '<gql_endpoint>' } } }],
queryConfig: {
maxDepth: { enabled: false },
maxAliases: { enabled: false },
maxTokens: { enabled: false },
maxDirectives: { enabled: false },
costLimit: { enabled: false },
blockFieldSuggestion: { enabled: false },
maskErrors: { enabled: false },
},
},
};
readFile.mockResolvedValueOnce(JSON.stringify(meshWithQueryConfigDisabled));
parseSpy.mockResolvedValueOnce({
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
flags: { ignoreCache: mockIgnoreCacheFlag, autoConfirmAction: mockAutoApproveAction },
});
await UpdateCommand.run();
expect(updateMesh.mock.calls[0]).toMatchInlineSnapshot(`
[
"CODE1234@AdobeOrg",
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
"mesh_id",
{
"meshConfig": {
"queryConfig": {
"blockFieldSuggestion": {
"enabled": false,
},
"costLimit": {
"enabled": false,
},
"maskErrors": {
"enabled": false,
},
"maxAliases": {
"enabled": false,
},
"maxDepth": {
"enabled": false,
},
"maxDirectives": {
"enabled": false,
},
"maxTokens": {
"enabled": false,
},
},
"sources": [
{
"handler": {
"graphql": {
"endpoint": "<gql_endpoint>",
},
},
"name": "<api_name>",
},
],
},
},
]
`);
});

test('should pass with valid args and ignoreCache flag', async () => {
let sampleMesh = {
meshConfig: {
Expand Down
Loading
Loading