Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform GraphQL Amplify Schema to AppSync Schema #2390

Closed
itzcull opened this issue Mar 27, 2024 · 5 comments
Closed

Transform GraphQL Amplify Schema to AppSync Schema #2390

itzcull opened this issue Mar 27, 2024 · 5 comments
Labels
pending-response question Further information is requested

Comments

@itzcull
Copy link

itzcull commented Mar 27, 2024

Amplify CLI Version

0.0.0

Question

Is it possible to transform the amplify schema with all it's unique directives to the relevant app sync schema without providing cdk stack context.

Phrased differently, I'd like to take our schema with directives like @model, @auth, @primaryKey etc and convert it to what is visible in the AppSync console with directives like @aws_iam, and @aws_cognito_user_pools and AWS Scalars left over.

We generate software artefacts with graphql codegen tools which rely on non-amplify specific SDLs to be present, so it's imperative we transform the schema before running it.

Our team is no longer using amplify cli, we're using SST, a framework for provisioning infrastructure with level 2/3 cdk constructs, we can go lower level if required, we're just looking to reduce effort in the short term due to product delivery pressures

We were reading the generated app sync schema file from the generated cloud formation json AFTER compiling all the cdk constructs, but we still want the 'search' queries associated with the @searchable directive to be included in the output even though we don't deploy Open Search in every environment (we strip the @searchable directive when in a non-prod environment).

@itzcull itzcull added pending-triage question Further information is requested labels Mar 27, 2024
@dpilch
Copy link
Member

dpilch commented Apr 1, 2024

Hi @itzcull, there are three ways I can think of that you could accomplish this.

  1. Create an empty Amplify project and add your GraphQL schema. Then run amplify api gql-compile. The transformed schema will be in amplify/backend/api/<api-name>/build/schema.graphql. Also note that you do not need to amplify push so resources will not be created for this app.
  2. Use the executeTransform function from @aws-amplify/graphql-transformer directly. This is not intended to be used directly by customers so we may not be as strict with breaking changes to this interface. Here is an example usage:
    const executeTransformConfig: ExecuteTransformConfig = {
  3. Create an empty CDK project with the GraphQL API construct. Run cdk synth and the transformed schema will be in cdk.out/.

Option 1 will probably be the most stable. However, I can't confidently say that the transformer behavior between the Gen 1 cli (amplify api gql-compile) and the GraphQL API construct will remain consistent over time. I think option 3 is probably the best for your use case.

@itzcull
Copy link
Author

itzcull commented Apr 2, 2024

Thanks for the response @dpilch!

  1. I wanted to avoid using the Amplify CLI, but if I were to is there a way to change the output directory?
  2. I've tried this, doesn't seem like the schema gets converted at all. I'm using it outside the context of a cdk stack, I wanted to achieve standalone codegen, but could look at integrated it into the cdk synthesis process.

Here's a look at the cdk/sst code
image

@dpilch
Copy link
Member

dpilch commented Apr 2, 2024

  1. There is no way to change the output directory.

  2. In that case you can access the transformed schema by walking the stack.

// @ts-ignore
appsync.node._children.GraphQLAPI.schema.definition

This will contain the transformed schema as a string. However, this is accessing properties that are currently set to private (hence the @ts-ignore). This is treading into our internal representation again. I don't anticipate that these properties will change, but I can't provide any guarantee.

@AnilMaktala
Copy link
Member

Hey 👋 , This issue is being closed due to inactivity. If you are still experiencing the same problem and need further assistance, please feel free to leave a comment. This will enable us to reopen the issue and provide you with the necessary support.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-response question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants