Reputation: 225
I am using the code-first approach in @aws-cdk/aws-appsync for generating my graphql schema. For Typescript code generation purposes I need a way to retrieve the schema.graphql before deployment (maybe somehow extracting it from the cdk synth
command?).
Upvotes: 0
Views: 1773
Reputation: 225
For getting the automatically created schema before deployment, use this script:
readFile('cdk.out/<YOUR-APP-NAME>.template.json', 'utf8', (err, data) => {
if (err) {
throw err;
}
const definition = JSON.parse(data)
.Resources
.<YOUR-SCHEMA-ID> // replace with your schema id
.Properties
.Definition;
writeFile('lib/domain/generated.graphql', definition, (error) => {
if (error) throw error;
});
});
Upvotes: 0
Reputation: 930
I am not sure if we are facing the same issue. Basically I wanted to access the GQL schema in my client react app which was in a different repository than the cdk app in which the infrastructure is defined.
I ended up using the aws-cli to extract the appsync schema using the following command:
aws appsync get-introspection-schema --api-id [API-ID] --format SDL --no-include-directives outfile=[OUTFILE]
Upvotes: 2