Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate Models from GraphQL schema #786

Open
Odaym opened this issue Feb 7, 2024 · 2 comments
Open

Cannot generate Models from GraphQL schema #786

Odaym opened this issue Feb 7, 2024 · 2 comments
Labels
feature-request New feature or request Java Target language: Java

Comments

@Odaym
Copy link

Odaym commented Feb 7, 2024

Amplify CLI Version

12.10.1

Question

So I have this schema that I use in my Amplify project on AWS. This schema works perfectly fine when going through the motions of integrating Amplify into a project on iOS.

On Android however, there is an issue.

To reproduce this I do:

  • amplify pull --appId xxxxxxxx
  • amplify pull
  • amplify codegen

This successfully generates the Queries, Mutations and Subscriptions under graphql folder with schema.json sitting in that folder.

At this stage the Models are not generated, the actual classes behind that schema, even though on iOS they are in that step above, on Android I have to do an extra step:

  • amplify codegen models

And here is where the issue lies, I always get this exception when running that command to get my Models:

Error: Unknown type Vendor for field vendor. Did you forget to add the @model directive
    at AppSyncModelJavaVisitor.getNativeType (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-visitor.js:220:19)
    at AppSyncModelJavaVisitor.getNativeType (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:479:34)
    at AppSyncModelJavaVisitor.generateModelField (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:239:32)
    at /snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:149:18
    at Array.forEach (<anonymous>)
    at AppSyncModelJavaVisitor.generateModelClass (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:147:22)
    at /snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:113:43
    at Array.forEach (<anonymous>)
    at AppSyncModelJavaVisitor.generateModelClasses (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:112:50)
    at AppSyncModelJavaVisitor.generate (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:44:21)
    at Object.plugin (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/plugin.js:55:24)
    at /snapshot/amplify-cli/build/node_modules/@graphql-codegen/core/cjs/execute-plugin.js:36:54
    at /snapshot/amplify-cli/build/node_modules/@graphql-codegen/core/node_modules/@graphql-codegen/plugin-helpers/cjs/profiler.js:7:49

I have a workaround wherein I replace Vendor and Product from interface to type and have them both implement a duplicate inteface instead, and in all occurrences of implements Product and implements Vendor I place implements IProduct and implements IVendor. This makes the codegen generate the Models successfully, but I don't want to have to do that.

What can I do to have this schema work as it should?

Is this schema AppSync comaptible?

If not, how can I convert it to be compatible and have this flow work as it should? Because remember, I still don't have the code for the Queries/Mutations/Subscriptions that are supposed to be using the generated Models, that still has to happen when I run my project and the appsync gradle plugin does its job (which it also fails for another reason).

What can I do?

Thanks.

@Odaym Odaym added pending-triage Issues that need further discussion to determine question Further information is requested labels Feb 7, 2024
@ykethan
Copy link

ykethan commented Feb 7, 2024

Hey, 👋 thanks for raising this! I'm going to transfer this over to our codegen repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Feb 7, 2024
@AaronZyLee AaronZyLee added the Java Target language: Java label Feb 12, 2024
@dpilch
Copy link
Contributor

dpilch commented Feb 27, 2024

interface is not currently supported for the Amplify GraphQLAPI or the codegen utilities.

@dpilch dpilch added feature-request New feature or request and removed question Further information is requested pending-triage Issues that need further discussion to determine labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request Java Target language: Java
Projects
None yet
Development

No branches or pull requests

4 participants