colin
07/12/2021, 7:15 PMgraphql-tools
and also see there are a few experimental methods in the appsync sdk for creating fields, types, etc… but I was hoping to just do some sort of simple concatenation (without being too low level) and pass it into my AppSyncApi config.
graphqlApi: {
schema: 'src/schema/schema.graphql',
}
Any ideas here?
Hoping to have a structure something like
src/schema/
-- project.schema
-- other-entity.schema
Frank
colin
07/12/2021, 9:58 PMserverless.yml
file
appSync:
name: apinamehere
schema:
- types/base.graphql
- types/employer.graphql
- types/projects.graphql
...
Frank
Frank
new sst.AppSyncApi(this, "AppSyncApi", {
graphqlApi: {
schema: [
"src/appsync/schema.graphql",
"src/appsync/schema2.graphql",
],
},
...
})
And internally they get merged using @graphql-tools/merge.Frank
npm install --save --save-exact @serverless-stack/cli@0.32.2-next.0+723d9cb3 @serverless-stack/resources@0.32.2-next.0+723d9cb3
Frank
Alex Price
07/13/2021, 10:55 AM@graphql-tools/merge
to generate one schema atm. Happy to share a snippet if you needcolin
07/13/2021, 2:54 PMcolin
07/13/2021, 2:55 PMFrank
import { print } from "graphql";
import { mergeTypeDefs } from "@graphql-tools/merge";
import { loadFilesSync } from "@graphql-tools/load-files";
// Schemas is an array of file names
const mergedSchema = mergeTypeDefs(
loadFilesSync(schemas)
);
// Write the merged schema to a file
fs.writeFileSync("merged.graphql", print(mergedSchema));
// Create the AppSync schema using the file
appsync.Schema.fromAsset("merged.graphql");
colin
07/13/2021, 6:18 PMgraphql/validate
for the schema before it gets set as mainSchema
.
I had a bad path and it took me until the CloudFormation error from sst start
to realize it.
something like below. I can add some tests for this if its something you’d want to do.
const errors = validate(mergedSchema)
if (errors.length > 0) throw new Error(`Invalid schema: ${errors}`)
Frank
colin
07/13/2021, 6:24 PMsrc
directory when initializing the AppSyncApi.
// Single file schema (worked)
{
schema: 'src/schema/base.graphql'
}
// Array schema (broken)
{
schema: ['schema/base.graphql', 'schema/project.graphql']
}
I’m thinking this gave me a “blank” schema but took me a second to realize.Frank
Frank
validate
would be useful if we checked for missing files?colin
07/13/2021, 6:28 PMfs.access()
call? not sure here) as well as a graphql validation call to catch small typos and things… but its a little more overhead on the build processFrank
Frank
colin
07/20/2021, 6:43 PMFrank
colin
08/16/2021, 2:03 PM