Search code examples
typescriptamazon-web-servicesschemaaws-cdkaws-appsync

How to migrate Schema to ISchema in aws cdk 2.61.1


Hi since the new aws cdk version (2.61.1) the Schema does no longer exist :/ So it's now impossible to import it from appsync:

import { Schema } from "@aws-cdk/aws-appsync-alpha"

Vscode suggest me to use ISchema instead : https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.ISchema.html

So i try to use SchemaFile but i didn't manage to reproduce my previous comportment

const apiSchema: SchemaFile = SchemaFile.fromAsset("../../playbook-api-schema/schema.graphql")
// const apiSchema = new Schema()
// apiSchema.addToSchema(appSyncCompatibleSchema)

Someone know whot to replace my old code ?


Solution

  • As of 2.55, the "code-first" schema generation functionality was moved out of the CDK repo and to a separate package, @cdklabs/awscdk-appsync-utils:

    import { CodeFirstSchema } from 'awscdk-appsync-utils';
    
    const schema = new CodeFirstSchema();
    
    schema.addType(new ObjectType('demo', {
      definition: { id: GraphqlType.id() },
    }));
    

    By the way, as of 2.60, the "schema-first" SchemaFile construct and the other remaining AppSync L2 constructs were promoted from "alpha" to "stable". They are now available in aws-cdk-lib like all stable APIs. The -alpha package is deprecated.