4

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?

Ilja
  • 44,142
  • 92
  • 275
  • 498
  • I am also using the CDK outside of the amplify workflow. I used: "amplify add codegen --apiId xxxxxxxxx" ... which allows selection of Typescript as a generation option. – Nick Ager Feb 13 '21 at 07:07

1 Answers1

3

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.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183