aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Using interface as a field causes codegen error. #1864

Open mnikolic10 opened 1 year ago

mnikolic10 commented 1 year ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.15.1

Amplify CLI Version

12.0.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

I initially had a failure when running amplify push, the cloudformation stack was stuck in update rollback state, so i resolved by manually continuing the rollback.

Describe the bug

When running amplify codegen models i receive an error

"Unknown type Cuisine for field items. Did you forget to add the @model directive"

In the time i've spent debugging I can see the issue is coming from using Cuisine as a field within another type, see example snippet below:

interface Cuisine {
  id: ID!
  name: String!
  type: ItemType
  cuisineColor: String
  locations: [Float]
  allRatings: [Int]
  rating: Float
}

type GlobalCuisine implements Cuisine
  @model
  @auth(rules: [{allow: public}])
  @searchable {
...
}

type ContinentCuisine implements Cuisine
  @model
  @auth(rules: [{allow: public}])
  @searchable {
...
}

type CountryCuisine implements Cuisine
  @model
  @auth(rules: [{allow: public}])
  @searchable {
...
}

type Query {
  searchCuisines(input: CuisineSearchInput): CuisinesConnection
}

type CuisinesConnection {
  items: [Cuisine]
  total: Int
  nextToken: String
}

Expected behavior

Would have expected this to compile correctly as it was previously working.

Reproduction steps

How can this bug be reproduced?

  1. Run amplify codegen models
  2. See error logged and no models file generated.

Will running the exact steps below in an empty directory create an Amplify project that demonstrates the bug behavior?

I believe this likely to be an individual issue within my environment but may be helpful if others encounter a similar issue

Screenshots can be provided in the issue body below.

Screenshot 2023-09-15 at 12 07 40 pm

Project Identifier

33607ffacefa5dabac82046c3bfc9645

Log output

``` # Put your logs below this line Unknown type Cuisine for field items. Did you forget to add the @model directive Error: Unknown type Cuisine for field items. Did you forget to add the @model directive at AppSyncModelJavascriptVisitor.getNativeType (/snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-visitor.js:218:19) at AppSyncModelJavascriptVisitor.getNativeType (/snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-typescript-visitor.js:227:32) at /snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-typescript-visitor.js:132:63 at Array.forEach () at AppSyncModelJavascriptVisitor.generateModelDeclaration (/snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-typescript-visitor.js:130:25) at /snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-javascript-visitor.js:24:38 at Array.map () at AppSyncModelJavascriptVisitor.generate (/snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-javascript-visitor.js:24:18) at Object.plugin (/snapshot/repo/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/plugin.js:55:24) at /snapshot/repo/build/node_modules/@graphql-codegen/core/cjs/execute-plugin.js:36:54 at /snapshot/repo/build/node_modules/@graphql-codegen/core/node_modules/@graphql-codegen/plugin-helpers/cjs/profiler.js:7:49 ```

Additional information

No response

Before submitting, please confirm:

josefaidt commented 1 year ago

Hey @mnikolic10 :wave: thanks for raising this! I'm going to transfer this over to our API repo for better support 🙂

dpilch commented 1 year ago

interface and union are not currently supported by Amplify Codegen.

mnikolic10 commented 1 year ago

interface and union are not currently supported by Amplify Codegen.

Thanks for clarifying. Curious why i was able to previously run the command successfully with the same schema?

dpilch commented 1 year ago

I'm not sure as to why it worked previously. The behavior of interface and union can be unpredictable because we do not test the functionality between releases.