分割AWS GraphQL API模式为多个文件

huangapple go评论90阅读模式
英文:

Split an AWS GraphQL API Schema into multiple files

问题

目前我正在通过AWS CDK开发一个GraphQL API。我在本地编写了schema.graphql,然后通过cdk deploy部署到AWS实例。

我的Schema文件现在有600行代码,不包括代码或文档注释。我尝试找到一种将这个文件拆分成多个文件以便更好维护的方法。是否有人对我目前的情况有解决方案或提示?

1中的AWS文档没有提及这个问题。

英文:

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')

huangapple
  • 本文由 发表于 2023年3月9日 17:51:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定