wgc 0.78.1 → 0.78.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +2 -2
- package/dist/src/commands/mcp/tools/utils/__tests__/schema.test.d.ts +1 -0
- package/dist/src/commands/mcp/tools/utils/__tests__/schema.test.js +78 -0
- package/dist/src/commands/mcp/tools/utils/__tests__/schema.test.js.map +1 -0
- package/dist/src/commands/mcp/tools/utils/schema.d.ts +9 -0
- package/dist/src/commands/mcp/tools/utils/schema.js +28 -0
- package/dist/src/commands/mcp/tools/utils/schema.js.map +1 -0
- package/dist/src/commands/mcp/tools/verify-query-against-in-memory-schema.js +5 -5
- package/dist/src/commands/mcp/tools/verify-query-against-in-memory-schema.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wgc",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.3",
|
|
4
4
|
"description": "The official CLI tool to manage the GraphQL Federation Platform Cosmo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"prettier": "^3.5.2",
|
|
88
88
|
"tsx": "^4.17.0",
|
|
89
89
|
"typescript": "5.5.2",
|
|
90
|
-
"vitest": "^
|
|
90
|
+
"vitest": "^3.1.2"
|
|
91
91
|
},
|
|
92
92
|
"gitHead": "c37aed755e1b19ed91d30f9b5f7041e15c56901a"
|
|
93
93
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { lexicographicSortSchema, printSchema } from 'graphql';
|
|
3
|
+
import { buildSchemaWithoutDirectives } from '../schema.js';
|
|
4
|
+
describe('buildSchemaWithoutDirectives', () => {
|
|
5
|
+
it('should remove all directive definitions and usages from a federation schema', () => {
|
|
6
|
+
const schemaWithDirectives = `
|
|
7
|
+
directive @key(fields: String!) on OBJECT | INTERFACE
|
|
8
|
+
directive @external on FIELD_DEFINITION
|
|
9
|
+
directive @requires(fields: String!) on FIELD_DEFINITION
|
|
10
|
+
directive @provides(fields: String!) on FIELD_DEFINITION
|
|
11
|
+
directive @extends on OBJECT | INTERFACE
|
|
12
|
+
|
|
13
|
+
type Query {
|
|
14
|
+
topProducts: [Product]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Product @key(fields: "id") {
|
|
18
|
+
id: ID!
|
|
19
|
+
name: String!
|
|
20
|
+
price: Int @external
|
|
21
|
+
weight: Int @external
|
|
22
|
+
shippingEstimate: Int @requires(fields: "price weight")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type User @key(fields: "id") @extends {
|
|
26
|
+
id: ID! @external
|
|
27
|
+
username: String @external
|
|
28
|
+
reviews: [Review] @provides(fields: "author")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Review {
|
|
32
|
+
id: ID!
|
|
33
|
+
author: User
|
|
34
|
+
product: Product!
|
|
35
|
+
rating: Int!
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const expectedSchema = `type Product {
|
|
39
|
+
id: ID!
|
|
40
|
+
name: String!
|
|
41
|
+
price: Int
|
|
42
|
+
shippingEstimate: Int
|
|
43
|
+
weight: Int
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type Query {
|
|
47
|
+
topProducts: [Product]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type Review {
|
|
51
|
+
author: User
|
|
52
|
+
id: ID!
|
|
53
|
+
product: Product!
|
|
54
|
+
rating: Int!
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type User {
|
|
58
|
+
id: ID!
|
|
59
|
+
reviews: [Review]
|
|
60
|
+
username: String
|
|
61
|
+
}`;
|
|
62
|
+
const schema = buildSchemaWithoutDirectives(schemaWithDirectives);
|
|
63
|
+
// Sort the schema to ensure consistent output
|
|
64
|
+
const sortedSchema = lexicographicSortSchema(schema);
|
|
65
|
+
const cleanedSchemaString = printSchema(sortedSchema);
|
|
66
|
+
// Compare the actual cleaned schema with expected schema
|
|
67
|
+
expect(cleanedSchemaString.trim()).toBe(expectedSchema.trim());
|
|
68
|
+
});
|
|
69
|
+
it('should throw an error for an invalid schema', () => {
|
|
70
|
+
const invalidSchema = `
|
|
71
|
+
type Query {
|
|
72
|
+
invalidField: NonExistentType
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
expect(() => buildSchemaWithoutDirectives(invalidSchema)).toThrowError('Failed to parse schema: Unknown type: "NonExistentType".');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.test.js","sourceRoot":"","sources":["../../../../../../../src/commands/mcp/tools/utils/__tests__/schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAE5D,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,EAAE,CAAC,6EAA6E,EAAE,GAAG,EAAE;QACrF,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+B5B,CAAC;QAEF,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;EAuBzB,CAAC;QAEC,MAAM,MAAM,GAAG,4BAA4B,CAAC,oBAAoB,CAAC,CAAC;QAClE,8CAA8C;QAC9C,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QACrD,MAAM,mBAAmB,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;QAEtD,yDAAyD;QACzD,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,aAAa,GAAG;;;;KAIrB,CAAC;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,4BAA4B,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CACpE,0DAA0D,CAC3D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Removes all directive definitions and directive usages from a GraphQL schema string
|
|
4
|
+
* and returns a built GraphQLSchema.
|
|
5
|
+
*
|
|
6
|
+
* @param schemaString - The GraphQL schema string to process
|
|
7
|
+
* @returns A built GraphQLSchema with all directives removed
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildSchemaWithoutDirectives(schemaString: string): GraphQLSchema;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parse, visit } from 'graphql';
|
|
2
|
+
import { buildASTSchema } from '@wundergraph/composition';
|
|
3
|
+
/**
|
|
4
|
+
* Removes all directive definitions and directive usages from a GraphQL schema string
|
|
5
|
+
* and returns a built GraphQLSchema.
|
|
6
|
+
*
|
|
7
|
+
* @param schemaString - The GraphQL schema string to process
|
|
8
|
+
* @returns A built GraphQLSchema with all directives removed
|
|
9
|
+
*/
|
|
10
|
+
export function buildSchemaWithoutDirectives(schemaString) {
|
|
11
|
+
// Parse the schema into an AST
|
|
12
|
+
try {
|
|
13
|
+
const ast = parse(schemaString, { noLocation: true });
|
|
14
|
+
// Visit the AST and remove all directives
|
|
15
|
+
const cleanedAst = visit(ast, {
|
|
16
|
+
// Remove directive definitions
|
|
17
|
+
DirectiveDefinition: () => null,
|
|
18
|
+
// Remove directive usages from any node that can have directives
|
|
19
|
+
Directive: () => null,
|
|
20
|
+
});
|
|
21
|
+
// Build and return the schema
|
|
22
|
+
return buildASTSchema(cleanedAst, { assumeValid: true, assumeValidSDL: true });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`Failed to parse schema: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../src/commands/mcp/tools/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,cAAc,EAAa,MAAM,0BAA0B,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAAC,YAAoB;IAC/D,+BAA+B;IAC/B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,0CAA0C;QAC1C,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,EAAE;YAC5B,+BAA+B;YAC/B,mBAAmB,EAAE,GAAG,EAAE,CAAC,IAAI;YAC/B,iEAAiE;YACjE,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;SACtB,CAAC,CAAC;QAEH,8BAA8B;QAC9B,OAAO,cAAc,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { parse, validate } from 'graphql';
|
|
3
|
+
import { buildSchemaWithoutDirectives } from './utils/schema.js';
|
|
3
4
|
/**
|
|
4
5
|
* Registers the verify-query-against-in-memory-schema tool with the MCP server.
|
|
5
6
|
*
|
|
@@ -9,7 +10,6 @@ import { buildSchema, parse, validate } from 'graphql';
|
|
|
9
10
|
*/
|
|
10
11
|
export const registerVerifyQueryAgainstInMemorySchemaTool = ({ server, opts, }) => {
|
|
11
12
|
server.tool('verify_query_against_in_memory_schema', 'Verify if a GraphQL query is valid against a local in memory Supergraph or GraphQL SDL.', { query: z.string(), schema: z.string() }, ({ query, schema: schemaString }) => {
|
|
12
|
-
// Renamed schema to schemaString to avoid conflict
|
|
13
13
|
try {
|
|
14
14
|
let document;
|
|
15
15
|
try {
|
|
@@ -20,14 +20,14 @@ export const registerVerifyQueryAgainstInMemorySchemaTool = ({ server, opts, })
|
|
|
20
20
|
content: [{ type: 'text', text: `Query parsing failed:\n${syntaxError.message}` }],
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
// Build the schema from the string
|
|
23
|
+
// Build the schema from the string, removing all directives
|
|
24
24
|
let schema;
|
|
25
25
|
try {
|
|
26
|
-
schema =
|
|
26
|
+
schema = buildSchemaWithoutDirectives(schemaString);
|
|
27
27
|
}
|
|
28
28
|
catch (schemaError) {
|
|
29
29
|
return {
|
|
30
|
-
content: [{ type: 'text', text:
|
|
30
|
+
content: [{ type: 'text', text: schemaError.message }],
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
// Validate the query against the schema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-query-against-in-memory-schema.js","sourceRoot":"","sources":["../../../../../src/commands/mcp/tools/verify-query-against-in-memory-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"verify-query-against-in-memory-schema.js","s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