Ilja
Ilja

Reputation: 46479

How to generate Typescript definitions from AppSync GraphQL schema if I am not using amplify?

I have my AppSync api set up using aws-cdk and am not using their amplify framework. I am trying to figure out how / if I can generate Typescript definitions from my AppSync schema.graphql file while not using amplify, i.e. no access to amplify codegen command. I did try installing and running it, but I assume amplify expects files to be located in certain directories, hence failing.

I looked into https://graphql-code-generator.com but it wont work due to special types AppSync uses like AWSDateTime, a work around for this is to have api published and get schema from a graphql endpoint, but this is not ideal i.e. I'd like to be able and generate these types locally without publishing the schema.

Is this doable?

Upvotes: 5

Views: 1660

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

If there's some custom scalars (like AWSDateTime) that aren't part of your schema.graphql file, you can just create a separate file like scalars.graphql and add those missing type definitions yourself:

scalar AWSDateTime
scalar AWSPhone
scalar AWSJSON

Then just pass a glob to GraphQL Code Generator that matches both files -- they'll be combined into a single schema.

Upvotes: 3

Related Questions