How can I create basic TypeScript types using aws amplify codegen?

Currently, I am in the process of creating a web application using React, AWS AppSync GraphQL, and Amplify. While I have found this to be an incredible tool, I have encountered an issue with the codegen not generating base types as expected for the TypeScript frontend.

Let's take a look at the schema.graphql file that I supplied to amplify codegen:

type Event @model {
  id: ID!
  name: String
  effects: [EventEffects]
}

type EventEffect {
  name: String
  delta: Int
}

Along with this configuration in the 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

When running the codegen command, it produces files such as API.ts, queries.ts, mutations.ts, subscriptions.ts, and schema.json. However, I noticed that no base types are being generated.

I was able to obtain an interface for Event using:

export interface Event
  extends Omit<Exclude<GetEventQuery["getEvent"], null>, "__typename"> {}

Unfortunately, there doesn't seem to be a way to get an interface for EventEffect since I forgot to add the @modal directive.

To sum up my inquiries:

  1. Is it intentional that Amplify does not generate base types?

  2. How can I acquire a base type for EventEffect?

  3. What purpose does the generated schema.json serve?

Answer №1

If you're hoping for automatically generated classes for Event and EventEffect that are compatible with DataStore.save(), give this a shot:

amplify codegen models

When you run this command, it will generate or update the src/models directory and include an index.d.ts file with the desired 2 classes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize JavaScript destructuring to assign values to a fresh object

When working with JavaScript/Typescript code, what is a concise way to destructure an object and then assign selected properties to a new object? const data: MyData = { x: 1, y: 2, z: 3, p: 4, q: 5 } // Destructuring const { x, z, q } = data; // New O ...

Error in RxJS Typescript: The 'reduce' property is not found in the type 'Observable<number>'

Here's a snippet of my code: const observable:Observable<number> = Observable.from([1, 2, 3]) .reduce((sum: number, number: number) => { return sum + number }, 0) observable.subscribeOnNext((sum) => console.log(sum)) Everything see ...

Node.js is having trouble locating a specific folder module within the local directory

My Typescript and NodeJS Visual Studio project compiles successfully, but I encounter a node runtime error regarding the inability to locate a local module. This is the specific error message: https://i.sstatic.net/6ydxj.png I find it perplexing that th ...

Is it feasible to securely remove an item from an array within an object without the need for any assertions in a single function?

My interest in this matter stems from curiosity. The title may be a bit complex, so let's simplify it with an example: type ObjType = { items: Array<{ id: number }>; sth: number }; const obj: ObjType = { sth: 3, items: [{ id: 1 }, { id: 2 } ...

Discover the process of fetching the current day in Angular 2/4 and trimming it down to only three characters

After using currentDate = new Date(); in my typescript file and attempting to display it with {{currentDate}}, the full format appeared as Sun Aug 06 2017 15:36:11 GMT+0530 (IST). Referring to AngularDatePipe, I changed it to {{currentDate | date}}, resul ...

Synchronizing Angular icons with HTML text

Presenting my HTML code <div class="transfer-link" *ngIf="showTransferLink" qa-name="transfer-link"> <a routerLink="/Transfers"> <mat-icon>sync_alt</mat-icon> <div> Transfer </div> ...

Can one capture audio from the microphone within the world of Decentraland?

Currently facing difficulties capturing voice from microphone in Decentraland, but successfully able to convert mp3 files to text. Seeking assistance from anyone experienced with voice capture in Decentraland. 1. Is it feasible to record voice directly fr ...

When compiling in Visual Studio 2019, the process terminated with exit code -1073741819

Today, upon returning to my asp .net core-project with react and typescript as front end, I encountered an error message after running the "Build" command. Can anyone shed some light on what this error means and how it can be fixed? Severity Code De ...

String validation using regular expressions

Below is the code I am using to validate a string using regular expressions (RegEx): if(!this.validate(this.form.get('Id').value)) { this.showErrorStatus('Enter valid ID'); return; } validate(id) { var patt = new RegExp("^[a-zA- ...

What is the method in Angular 6 that allows Observable to retrieve data from an Array?

What is the method to retrieve data of an Array using Observable in Angular 6? ob: Observable<any> array = ['a','b','c'] this.ob.subscribe(data => console.log(data)); ...

What is the appropriate directory to place the `typescript` package in order for WebStorm to recognize it?

According to the information on this webpage: The Configure TypeScript Compiler dialog box provides two options: Detect: WebStorm will look for a typescript package within the current project. If it finds one, it will use that package. Otherwise ...

The TreeView Schema Duplicate is an extension for VS Code

I am currently developing a custom VS Code extension that incorporates a unique viewsContainer. The activation of this container is triggered by an onView: event defined in the package JSON. The functionality works seamlessly, with my view fetching data f ...

What is the correct method for using typedef to define a function with the signature "() => void" in accordance with tslint guidelines?

Currently, I am working on a function that requires specific typing: const checkIfTagNeedsToBeCounted = (listOfTags: string[]): boolean => { const tagsToExcludeFromCounting: string[] = [ "DoNotCount", ]; const excludedTagFound: boolean = lis ...

The Unusual Behavior of Typescript Partial Interfaces

While reviewing the code in a repository I am currently working on, I stumbled upon something that seemed completely incorrect. Here is a snippet of what caught my attention. interface Car { make: string model: string } type SomeType = Partial<Car& ...

Creating a dynamic dropdown using *ngFor

I have successfully implemented a dynamic dropdown feature based on response using *ngFor Response Data Array(3) 0: val_id:1 role_id:1 id:1 is_optional:false is_text:false 1: val_id:1 ...

Encountering Angular 8 error TS2304 at line 39: Cannot find the specified name after shutting down WebStorm

After working on my Angular project and closing the IDE last night, I encountered an odd problem today. The project doesn't seem to recognize certain libraries such as Int8Array, Int16Array, Int32Array... And many others. While the project is still ab ...

Utilizing Angular's classBinding on each individual element through a click event listener

For my school project, I am developing a Quiz App. In the Learning section, I want to implement a feature that changes the color of each answer option when clicked. If the answer is correct, it should turn green; if not, it should turn red. This feature sh ...

Establish a new subpage that can have multiple main pages

I am currently working on implementing a navigation feature in an Angular application. I want to be able to access the same page from different "parent" pages while maintaining the navigation bar's awareness of the origin page. For navigation, I am u ...

Leveraging Aliases in Nuxt 3 Configuration: Unleashing the Power of Aliases in your Config File

Encountering an error while attempting to import files using aliases in the configuration file (nuxt.config.ts): Cannot find module '~/.... For reference, please check out this example: codesnadbox.io Showcasing a Short Example nuxt.config.ts import ...

Learn how to break down Angular 2 with Typescript in just 5 minutes by troubleshooting issues

I've been delving into the world of TypeScript and Angular 2 by following the guide at https://angular.io/guide/quickstart. After going through all the steps, I encountered some errors with the final step npm start. Here's what I got: Microsoft ...