I'm building a React + aws AppSync graphql web app with amplify. Have been enjoying this fantastic tool, but couldn't get the codegen
to work as I expected - it doesn't generate base types for TypeScript frontend.
Say I feed this schema.graphql
file to amplify codegen
:
type Event @model {
id: ID!
name: String
effects: [EventEffects]
}
type EventEffect {
name: String
delta: Int
}
with this config.yml
:
projects:
myapi:
schemaPath: amplify/backend/api/myapi/build/schema.graphql
includes:
- src/graphql/**/*.ts
excludes:
- ./amplify/**
extensions:
amplify:
codeGenTarget: typescript
generatedFileName: src/API.ts
docsFilePath: src/graphql
extensions:
amplify:
version: 3
Then codegen gives me API.ts
and queries.ts
, mutations.ts
, subscriptions.ts
and schema.json
. The problem is, there's no base types generated.
I can get interface for Event with:
export interface Event
extends Omit<Exclude<GetEventQuery["getEvent"], null>, "__typename"> {}
But there's no way to get interface for EventEffect
, since I didn't add @modal
directive.
To narrow down my questions:
Is it by design that amplify doesn't generate base types?
How to get base type for EventEffect
?
What is the schema.json
generated used for?
Do you expect generated classes for Event and EventEffect that you can use with DataStore.save() ? Try this:
amplify codegen models
It should create/update the src/models directory with the index.d.ts file containing the 2 classes that you are looking for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.