英文:
Split an AWS GraphQL API Schema into multiple files
问题
目前我正在通过AWS CDK开发一个GraphQL API。我在本地编写了schema.graphql
,然后通过cdk deploy
部署到AWS实例。
我的Schema文件现在有600行代码,不包括代码或文档注释。我尝试找到一种将这个文件拆分成多个文件以便更好维护的方法。是否有人对我目前的情况有解决方案或提示?
英文:
Currently I develop an GraphQL API via CDK on AWS.
So I write the schema.graphql
locally and deploy afterwards via cdk deploy
to an AWS Instance.
My Schema-File has now 600 LOC without code/documentation comments. I try to find a way to split this one file into multiple files for better maintenance. Does anyone has a solution or hint for this situation I am in.
The AWS documentation does not mention anything for that.
答案1
得分: 1
If you're using codebuild in some fashion, you could have one of the build steps be to build a unified file out of a collection of files.
So have a folder like
schema/part-a.js
schema/part-b.js
// part-a.js
function a () {
return `
some part of the schema
`
(Do this for each part of the schema you subdivide)
Then have a main script which imports all of the part-*.js
files and calls their function to combine them into a single string. THEN
import { a } from 'part-a.js'
...
const bigTemplateString = `${a}${b}${c}...`
await fs.writeFile(bigTemplateString, 'schema.graphql')
英文:
If you're using codebuild in some fashion, you could have one of the build steps be to build a unified file out of a collection of files.
So have a folder like
schema/part-a.js
schema/part-b.js
// part-a.js
function a () {
return `
some part of the schema
`
(Do this for each part of the schema you subdivide)
Then have a main script which imports all of the part-*.js
files and calls their function to combine them into a single string. THEN
import { a } from 'part-a.js'
...
const bigTemplateString = `${a}${b}${c}...`
await fs.writeFile(bigTemplateString, 'schema.graphql')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论