@embrace-ai/infra-api-schema-sync 1.0.6 → 1.0.8
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 +14 -0
- package/dist/src/generate-schema-url.d.ts +1 -0
- package/dist/src/generate-schema-url.d.ts.map +1 -1
- package/dist/src/generate-schema-url.js +10 -0
- package/dist/src/generate-schema-url.js.map +1 -1
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/update-local-schema.d.ts +12 -0
- package/dist/src/update-local-schema.d.ts.map +1 -0
- package/dist/src/update-local-schema.js +144 -0
- package/dist/src/update-local-schema.js.map +1 -0
- package/dist/src/update-local-schema.test.d.ts +2 -0
- package/dist/src/update-local-schema.test.d.ts.map +1 -0
- package/dist/src/update-local-schema.test.js +143 -0
- package/dist/src/update-local-schema.test.js.map +1 -0
- package/dist/src/validate-schema.js +1 -1
- package/dist/src/validate-schema.js.map +1 -1
- package/package.json +1 -1
- package/src/generate-schema-url.js +28 -0
- package/src/index.js +16 -0
- package/src/update-local-schema.js +216 -0
- package/src/update-local-schema.test.js +233 -0
- package/src/validate-schema.js +1 -1
- package/templates/workflows/graphql-schema-validate.yml +149 -68
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# .github/workflows/graphql-schema-validate.yml
|
|
2
1
|
name: Validate GraphQL Schema Updates
|
|
3
2
|
|
|
4
3
|
on:
|
|
@@ -7,24 +6,30 @@ on:
|
|
|
7
6
|
workflow_dispatch:
|
|
8
7
|
inputs:
|
|
9
8
|
schema_url:
|
|
10
|
-
description: "
|
|
11
|
-
required:
|
|
12
|
-
|
|
9
|
+
description: "GraphQL schema URL to validate/update"
|
|
10
|
+
required: true
|
|
11
|
+
type: string
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
contents: write
|
|
16
|
+
pull-requests: write
|
|
13
17
|
|
|
14
18
|
jobs:
|
|
15
19
|
validate-schema:
|
|
16
|
-
|
|
20
|
+
if: ${{ !startsWith(github.repository, 'Embrace-AI/template-') }}
|
|
21
|
+
runs-on: codebuild-GithubDev-${{ github.run_id }}-${{ github.run_attempt }}
|
|
17
22
|
|
|
18
23
|
steps:
|
|
19
|
-
- uses: actions/checkout@
|
|
24
|
+
- uses: actions/checkout@v5
|
|
20
25
|
|
|
21
26
|
- name: Setup pnpm
|
|
22
27
|
uses: pnpm/action-setup@v4
|
|
23
28
|
|
|
24
29
|
- name: Setup node cache
|
|
25
|
-
uses: actions/setup-node@
|
|
30
|
+
uses: actions/setup-node@v5
|
|
26
31
|
with:
|
|
27
|
-
node-version: 22.
|
|
32
|
+
node-version: 22.19.0
|
|
28
33
|
cache: "pnpm"
|
|
29
34
|
|
|
30
35
|
- name: Setup NPM
|
|
@@ -33,100 +38,174 @@ jobs:
|
|
|
33
38
|
run: pnpm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
|
|
34
39
|
|
|
35
40
|
- name: Install GraphQL schema sync tool
|
|
36
|
-
|
|
37
|
-
run: pnpm install -w @embrace-ai/infra-api-schema-sync@latest
|
|
41
|
+
run: pnpm add -g @embrace-ai/infra-api-schema-sync@latest
|
|
38
42
|
|
|
39
43
|
- name: Configure aws credentials
|
|
40
|
-
uses: aws-actions/configure-aws-credentials@
|
|
44
|
+
uses: aws-actions/configure-aws-credentials@v5.0.0
|
|
41
45
|
with:
|
|
42
46
|
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_DEV }}
|
|
43
47
|
aws-region: ${{ vars.AWS_REGION }}
|
|
44
48
|
|
|
45
|
-
- name:
|
|
46
|
-
id: schema-url
|
|
49
|
+
- name: Set schema URL and source repo
|
|
50
|
+
id: set-schema-url
|
|
47
51
|
run: |
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
echo "📡 Using schema URL from dispatch event: $SCHEMA_URL"
|
|
52
|
-
elif [ -n "${{ github.event.inputs.schema_url }}" ]; then
|
|
53
|
-
# Use the schema URL from workflow_dispatch input
|
|
54
|
-
SCHEMA_URL="${{ github.event.inputs.schema_url }}"
|
|
55
|
-
echo "🔧 Using schema URL from workflow input: $SCHEMA_URL"
|
|
56
|
-
else
|
|
57
|
-
echo "❌ Error: No schema URL provided"
|
|
58
|
-
exit 1
|
|
52
|
+
SCHEMA_URL="${{ github.event.client_payload.schemaUrl || github.event.inputs.schema_url || '' }}"
|
|
53
|
+
if [ -z "$SCHEMA_URL" ]; then
|
|
54
|
+
echo "❌ schemaUrl not provided via repository_dispatch payload or workflow input"; exit 1
|
|
59
55
|
fi
|
|
60
|
-
echo "
|
|
56
|
+
echo "schema_url=$SCHEMA_URL" >> "$GITHUB_OUTPUT"
|
|
61
57
|
|
|
62
58
|
- name: Display schema update context
|
|
63
59
|
run: |
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
echo "Timestamp: ${{ github.event.client_payload.timestamp }}"
|
|
70
|
-
else
|
|
71
|
-
echo "Event type: ${{ github.event_name }}"
|
|
72
|
-
echo "Schema URL: ${{ steps.schema-url.outputs.url }}"
|
|
73
|
-
fi
|
|
60
|
+
echo "Schema update received from: ${{ github.event.client_payload.sourceRepo }}"
|
|
61
|
+
echo "Schema URL: ${{ steps.set-schema-url.outputs.schema_url }}"
|
|
62
|
+
echo "Source commit: ${{ github.event.client_payload.commit }}"
|
|
63
|
+
echo "Source branch: ${{ github.event.client_payload.branch }}"
|
|
64
|
+
echo "Timestamp: ${{ github.event.client_payload.timestamp }}"
|
|
74
65
|
|
|
75
66
|
- name: Fetch updated schema
|
|
76
|
-
run:
|
|
67
|
+
run: api-tool fetch --url ${{ steps.set-schema-url.outputs.schema_url }} --output new-schema.graphql
|
|
77
68
|
|
|
69
|
+
- name: Update local schema files
|
|
70
|
+
id: update-schema
|
|
71
|
+
run: |
|
|
72
|
+
echo "🔍 Searching for local schema files to update..."
|
|
73
|
+
api-tool update-local-schema \
|
|
74
|
+
--schema-url "${{ steps.set-schema-url.outputs.schema_url }}" \
|
|
75
|
+
--schema-file new-schema.graphql \
|
|
76
|
+
--output schema-update-result.json
|
|
77
|
+
|
|
78
|
+
# Read the results
|
|
79
|
+
if [ -f schema-update-result.json ]; then
|
|
80
|
+
SERVICE_NAME=$(jq -r '.serviceName // "unknown"' schema-update-result.json)
|
|
81
|
+
UPDATED_COUNT=$(jq -r '.updatedFiles | length' schema-update-result.json)
|
|
82
|
+
HAS_CHANGES=$(jq -r '.hasChanges' schema-update-result.json)
|
|
83
|
+
|
|
84
|
+
echo "service_name=$SERVICE_NAME" >> $GITHUB_OUTPUT
|
|
85
|
+
echo "updated_count=$UPDATED_COUNT" >> $GITHUB_OUTPUT
|
|
86
|
+
echo "has_changes=$HAS_CHANGES" >> $GITHUB_OUTPUT
|
|
87
|
+
|
|
88
|
+
if [ "$HAS_CHANGES" = "true" ]; then
|
|
89
|
+
echo "✅ Updated $UPDATED_COUNT schema file(s) for service: $SERVICE_NAME"
|
|
90
|
+
jq -r '.updatedFiles[]' schema-update-result.json | while read file; do
|
|
91
|
+
echo " - $file"
|
|
92
|
+
done
|
|
93
|
+
else
|
|
94
|
+
echo "ℹ️ No changes detected in schema files"
|
|
95
|
+
fi
|
|
96
|
+
else
|
|
97
|
+
echo "has_changes=false" >> $GITHUB_OUTPUT
|
|
98
|
+
echo "⚠️ No schema files found to update"
|
|
99
|
+
fi
|
|
78
100
|
- name: Validate queries against new schema
|
|
79
101
|
id: validate
|
|
80
|
-
run:
|
|
102
|
+
run: api-tool validate --schema new-schema.graphql --queries 'src/**/*.graphql' --output report.json
|
|
81
103
|
|
|
82
104
|
- name: Check for issues
|
|
83
105
|
id: check-issues
|
|
84
106
|
run: |
|
|
85
|
-
if [ -s report.json ] && [ "$(jq 'length' report.json)" -gt 0 ]; then
|
|
107
|
+
if [ -s report.json ] && [ "$(jq '.issues | length' report.json)" -gt 0 ]; then
|
|
86
108
|
echo "has_issues=true" >> $GITHUB_OUTPUT
|
|
87
|
-
echo "issue_count=$(jq 'length' report.json)" >> $GITHUB_OUTPUT
|
|
109
|
+
echo "issue_count=$(jq '.issues | length' report.json)" >> $GITHUB_OUTPUT
|
|
88
110
|
else
|
|
89
111
|
echo "has_issues=false" >> $GITHUB_OUTPUT
|
|
90
112
|
echo "issue_count=0" >> $GITHUB_OUTPUT
|
|
91
113
|
fi
|
|
92
114
|
|
|
93
|
-
- name: Generate summary
|
|
115
|
+
- name: Generate validation summary
|
|
94
116
|
id: gen-summary
|
|
95
|
-
|
|
96
|
-
|
|
117
|
+
run: |
|
|
118
|
+
# Always generate summary, even if no issues (for consistency)
|
|
119
|
+
if [ ! -f report.json ]; then
|
|
120
|
+
echo "[]" > report.json
|
|
121
|
+
fi
|
|
122
|
+
api-tool summarize --report report.json --output GRAPHQL_ISSUES.md
|
|
123
|
+
|
|
124
|
+
# Also generate a summary of updated files
|
|
125
|
+
if [ -f schema-update-result.json ]; then
|
|
126
|
+
echo "## 📝 Updated Schema Files" > SCHEMA_CHANGES.md
|
|
127
|
+
echo "" >> SCHEMA_CHANGES.md
|
|
128
|
+
jq -r '.updatedFiles[]' schema-update-result.json | while read file; do
|
|
129
|
+
echo "- \`$file\`" >> SCHEMA_CHANGES.md
|
|
130
|
+
done
|
|
131
|
+
echo "" >> SCHEMA_CHANGES.md
|
|
132
|
+
fi
|
|
133
|
+
|
|
134
|
+
# Expose summaries as step outputs for later steps (multiline-safe)
|
|
135
|
+
{
|
|
136
|
+
echo 'issues_summary<<EOF'
|
|
137
|
+
cat GRAPHQL_ISSUES.md
|
|
138
|
+
echo EOF
|
|
139
|
+
} >> $GITHUB_OUTPUT
|
|
140
|
+
|
|
141
|
+
{
|
|
142
|
+
echo 'schema_changes<<EOF'
|
|
143
|
+
if [ -f SCHEMA_CHANGES.md ]; then
|
|
144
|
+
cat SCHEMA_CHANGES.md
|
|
145
|
+
else
|
|
146
|
+
echo "- No files updated"
|
|
147
|
+
fi
|
|
148
|
+
echo EOF
|
|
149
|
+
} >> $GITHUB_OUTPUT
|
|
150
|
+
- name: Clean up non-source artifacts before PR
|
|
151
|
+
run: |
|
|
152
|
+
rm -f new-schema.graphql report.json GRAPHQL_ISSUES.md SCHEMA_CHANGES.md schema-update-result.json
|
|
97
153
|
|
|
98
|
-
- name: Commit and create PR
|
|
154
|
+
- name: Commit and create PR
|
|
155
|
+
if: steps.update-schema.outputs.has_changes == 'true'
|
|
156
|
+
id: create-pr
|
|
99
157
|
uses: peter-evans/create-pull-request@v6
|
|
100
158
|
with:
|
|
101
|
-
commit-message: "chore(api): GraphQL schema update${{ github.event_name == 'repository_dispatch' && format(' from {0}', github.event.client_payload.sourceRepo) || '' }}"
|
|
159
|
+
commit-message: "chore(api): Update GraphQL schema for ${{ steps.update-schema.outputs.service_name }}${{ github.event_name == 'repository_dispatch' && format(' from {0}', github.event.client_payload.sourceRepo) || '' }}"
|
|
102
160
|
branch: "graphql/schema-update-${{ github.run_id }}"
|
|
103
|
-
title: "GraphQL Schema Update (${{ steps.check-issues.outputs.issue_count }} issues)"
|
|
161
|
+
title: "GraphQL Schema Update - ${{ steps.update-schema.outputs.service_name }} (${{ steps.check-issues.outputs.issue_count }} issues)"
|
|
104
162
|
body: |
|
|
105
163
|
# GraphQL Schema Update Impact Report
|
|
106
164
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
**
|
|
165
|
+
## Summary
|
|
166
|
+
|
|
167
|
+
**Service:** `${{ steps.update-schema.outputs.service_name }}`
|
|
168
|
+
**Updated Files:** ${{ steps.update-schema.outputs.updated_count }}
|
|
169
|
+
**Validation Issues:** ${{ steps.check-issues.outputs.issue_count }}
|
|
170
|
+
**Status:** ${{ steps.check-issues.outputs.has_issues == 'true' && '⚠️ Action Required' || '✅ Ready to Merge' }}
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Schema Files Updated
|
|
175
|
+
|
|
176
|
+
The following schema files have been updated with the latest schema from the source:
|
|
177
|
+
|
|
178
|
+
${{ steps.gen-summary.outputs.schema_changes }}
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## ${{ steps.check-issues.outputs.has_issues == 'true' && '⚠️ Validation Issues Found' || '✅ No Validation Issues' }}
|
|
183
|
+
|
|
184
|
+
${{ steps.check-issues.outputs.has_issues == 'true' && 'The following GraphQL queries are incompatible with the updated schema and need to be fixed:\n\n' || 'All existing GraphQL queries are compatible with the updated schema. No changes to queries are required.\n\n' }}${{ steps.gen-summary.outputs.issues_summary }}
|
|
113
185
|
|
|
114
186
|
---
|
|
115
|
-
## ${{ steps.check-issues.outputs.has_issues == 'true' && 'Detected Issues' || '🎉 No Issues Found' }}
|
|
116
|
-
${{ steps.check-issues.outputs.has_issues == 'true' && steps.gen-summary.outputs.summary || 'The updated schema is compatible with your existing GraphQL queries' }}
|
|
117
187
|
|
|
118
|
-
##
|
|
119
|
-
1. Review any compatibility issues above
|
|
120
|
-
2. Update your GraphQL queries to match the new schema
|
|
121
|
-
3. Test your changes thoroughly
|
|
122
|
-
4. Merge this PR once all issues are resolved
|
|
188
|
+
## Source Information
|
|
123
189
|
|
|
124
|
-
|
|
190
|
+
${{ github.event_name == 'repository_dispatch' && format('- **Schema Source:** {0}', github.event.client_payload.sourceRepo) || '' }}
|
|
191
|
+
- **Schema URL:** ${{ github.event.client_payload.schemaUrl }}
|
|
192
|
+
${{ github.event_name == 'repository_dispatch' && format('- **Source Commit:** {0}', github.event.client_payload.commit) || '' }}
|
|
193
|
+
${{ github.event_name == 'repository_dispatch' && format('- **Source Branch:** {0}', github.event.client_payload.branch) || '' }}
|
|
194
|
+
${{ github.event_name == 'repository_dispatch' && format('- **Update Time:** {0}', github.event.client_payload.timestamp) || '' }}
|
|
195
|
+
- **Trigger:** ${{ github.event_name }}
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 🚀 Next Steps
|
|
200
|
+
|
|
201
|
+
${{ steps.check-issues.outputs.has_issues == 'true' && '1. ⚠️ **Review the validation issues above**\n2. 🔧 **Update the affected GraphQL queries** to match the new schema\n3. **Test your changes**\n4. **Push your fixes** to this branch\n5. **Merge this PR** once all issues are resolved' || '1. **Review the schema changes** in the Files Changed tab\n2. **Verify the changes** look correct\n3. **Merge this PR** to update your schema' }}
|
|
202
|
+
|
|
203
|
+
- name: Display validation results
|
|
125
204
|
if: github.event_name == 'workflow_dispatch'
|
|
126
205
|
run: |
|
|
127
|
-
echo "##
|
|
206
|
+
echo "## GraphQL Schema Validation Results" >> $GITHUB_STEP_SUMMARY
|
|
128
207
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
129
|
-
echo "**Schema URL:** ${{ steps.schema-url.outputs.
|
|
208
|
+
echo "**Schema URL:** ${{ steps.set-schema-url.outputs.schema_url }}" >> $GITHUB_STEP_SUMMARY
|
|
130
209
|
echo "**Event:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
|
|
131
210
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
132
211
|
|
|
@@ -142,12 +221,14 @@ jobs:
|
|
|
142
221
|
echo "The schema is compatible with all existing GraphQL queries." >> $GITHUB_STEP_SUMMARY
|
|
143
222
|
fi
|
|
144
223
|
|
|
145
|
-
- name:
|
|
146
|
-
if: steps.
|
|
224
|
+
- name: No changes needed
|
|
225
|
+
if: steps.update-schema.outputs.has_changes == 'false'
|
|
147
226
|
run: |
|
|
148
|
-
echo "✅
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
227
|
+
echo "✅ Schema is already up to date - no PR needed"
|
|
228
|
+
echo "### ✅ Schema Already Up To Date" >> $GITHUB_STEP_SUMMARY
|
|
229
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
230
|
+
echo "The fetched schema matches the current schema file(s). No changes or action needed." >> $GITHUB_STEP_SUMMARY
|
|
231
|
+
if [ "${{ steps.check-issues.outputs.has_issues }}" = "false" ]; then
|
|
232
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
233
|
+
echo "All existing queries are compatible with the schema." >> $GITHUB_STEP_SUMMARY
|
|
153
234
|
fi
|