@embrace-ai/infra-api-schema-sync 1.0.3 → 1.0.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.5](https://github.com/Embrace-AI/infra-api-schema-sync/compare/v1.0.4...v1.0.5) (2025-10-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **fetch:** use signed fetch to get graphql schema ([#19](https://github.com/Embrace-AI/infra-api-schema-sync/issues/19)) ([ec1d24b](https://github.com/Embrace-AI/infra-api-schema-sync/commit/ec1d24b9f672342bbf07911fcd3b5375de177eb6))
9
+
10
+ ## [1.0.4](https://github.com/Embrace-AI/infra-api-schema-sync/compare/v1.0.3...v1.0.4) (2025-10-14)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **fetch-schema:** use GET and remove introspection for schema fetch ([#17](https://github.com/Embrace-AI/infra-api-schema-sync/issues/17)) ([023c64f](https://github.com/Embrace-AI/infra-api-schema-sync/commit/023c64f3d5a05dba31ef817cbbb26d6fee675b9e))
16
+
3
17
  ## [1.0.3](https://github.com/Embrace-AI/infra-api-schema-sync/compare/v1.0.2...v1.0.3) (2025-10-08)
4
18
 
5
19
 
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-schema.d.ts","sourceRoot":"","sources":["../../src/fetch-schema.js"],"names":[],"mappings":"AAKO;;;kBAwDN"}
1
+ {"version":3,"file":"fetch-schema.d.ts","sourceRoot":"","sources":["../../src/fetch-schema.js"],"names":[],"mappings":"AAOO;;;kBAqCN"}
@@ -1,38 +1,29 @@
1
+ import { AWS_REGION } from "@embrace-ai/common-sst-app-utils";
2
+ import { createSignedFetch } from "@scaldwell77/aws-signed-fetch";
1
3
  import fs from "fs";
2
4
  import fse from "fs-extra";
3
- import { buildClientSchema, getIntrospectionQuery, printSchema } from "graphql";
4
5
  import path from "path";
5
6
  export const fetchSchema = async ({ url, output }) => {
6
7
  try {
7
8
  console.log(`🔄 Fetching GraphQL schema from ${url}...`);
8
- const introspectionQuery = getIntrospectionQuery();
9
- const response = await fetch(url, {
10
- method: "POST",
9
+ const signedFetch = createSignedFetch({
10
+ service: "execute-api",
11
+ awsRegion: AWS_REGION,
12
+ });
13
+ const response = await signedFetch(url, {
14
+ method: "GET",
11
15
  headers: {
12
- "Content-Type": "application/json",
13
- Accept: "application/json",
16
+ Accept: "application/graphql, text/plain",
14
17
  },
15
- body: JSON.stringify({
16
- query: introspectionQuery,
17
- }),
18
18
  });
19
19
  if (!response.ok) {
20
20
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
21
21
  }
22
- const result = await response.json();
23
- if (result.errors) {
24
- throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(", ")}`);
25
- }
26
- if (!result.data) {
27
- throw new Error("No data returned from introspection query");
28
- }
29
- const schema = buildClientSchema(result.data);
30
- const schemaSDL = printSchema(schema);
22
+ const schemaSDL = await response.text();
31
23
  const outputDir = path.dirname(output);
32
24
  fse.ensureDirSync(outputDir);
33
25
  fs.writeFileSync(output, schemaSDL, "utf8");
34
26
  console.log(`✅ Schema successfully saved to ${output}`);
35
- console.log(`📊 Schema contains ${Object.keys(schema.getTypeMap()).length} types`);
36
27
  }
37
28
  catch (error) {
38
29
  console.error(`❌ Failed to fetch schema: ${error.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-schema.js","sourceRoot":"","sources":["../../src/fetch-schema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;IACnD,IAAI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,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACrE,CAAC;QAGD,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAGxC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,GAAG,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAG7B,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAE5C,OAAO,CAAC,GAAG,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAGF,eAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embrace-ai/infra-api-schema-sync",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "bin": {
5
5
  "api-tool": "./dist/src/index.js"
6
6
  },
@@ -22,9 +22,11 @@
22
22
  "keywords": [],
23
23
  "type": "module",
24
24
  "dependencies": {
25
+ "@embrace-ai/common-sst-app-utils": "^1.8.2",
25
26
  "@graphql-codegen/cli": "^5.0.7",
26
27
  "@graphql-codegen/typescript": "^4.1.6",
27
28
  "@graphql-inspector/cli": "^5.0.8",
29
+ "@scaldwell77/aws-signed-fetch": "^4.0.0",
28
30
  "commander": "^14.0.0",
29
31
  "fs-extra": "^11.3.0",
30
32
  "globals": "^16.2.0",
@@ -1,48 +1,34 @@
1
+ import { AWS_REGION } from "@embrace-ai/common-sst-app-utils";
2
+
3
+ import { createSignedFetch } from "@scaldwell77/aws-signed-fetch";
1
4
  import fs from "fs";
2
5
  import fse from "fs-extra";
3
- import { buildClientSchema, getIntrospectionQuery, printSchema } from "graphql";
4
6
  import path from "path";
5
7
 
6
8
  export const fetchSchema = async ({ url, output }) => {
7
9
  try {
8
10
  console.log(`🔄 Fetching GraphQL schema from ${url}...`);
9
11
 
10
- // Prepare introspection query
11
- const introspectionQuery = getIntrospectionQuery();
12
+ // Create AWS signed fetch for API Gateway authentication
13
+ const signedFetch = createSignedFetch({
14
+ service: "execute-api",
15
+ awsRegion: AWS_REGION,
16
+ });
12
17
 
13
- // Fetch schema using introspection
14
- const response = await fetch(url, {
15
- method: "POST",
18
+ // Fetch schema SDL directly via GET
19
+ const response = await signedFetch(url, {
20
+ method: "GET",
16
21
  headers: {
17
- "Content-Type": "application/json",
18
- Accept: "application/json",
22
+ Accept: "application/graphql, text/plain",
19
23
  },
20
- body: JSON.stringify({
21
- query: introspectionQuery,
22
- }),
23
24
  });
24
25
 
25
26
  if (!response.ok) {
26
27
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
27
28
  }
28
29
 
29
- const result = await response.json();
30
-
31
- if (result.errors) {
32
- throw new Error(
33
- `GraphQL errors: ${result.errors.map((e) => e.message).join(", ")}`,
34
- );
35
- }
36
-
37
- if (!result.data) {
38
- throw new Error("No data returned from introspection query");
39
- }
40
-
41
- // Build schema from introspection result
42
- const schema = buildClientSchema(result.data);
43
-
44
- // Convert schema to SDL (Schema Definition Language)
45
- const schemaSDL = printSchema(schema);
30
+ // Read response as text (schema SDL)
31
+ const schemaSDL = await response.text();
46
32
 
47
33
  // Ensure output directory exists
48
34
  const outputDir = path.dirname(output);
@@ -52,9 +38,6 @@ export const fetchSchema = async ({ url, output }) => {
52
38
  fs.writeFileSync(output, schemaSDL, "utf8");
53
39
 
54
40
  console.log(`✅ Schema successfully saved to ${output}`);
55
- console.log(
56
- `📊 Schema contains ${Object.keys(schema.getTypeMap()).length} types`,
57
- );
58
41
  } catch (error) {
59
42
  console.error(`❌ Failed to fetch schema: ${error.message}`);
60
43
  process.exit(1);