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
88 stars 76 forks source link

[Question] Recommendation when the cli won't generate graphql on using amplify pull #77

Open joedevgee opened 2 years ago

joedevgee commented 2 years ago

Page: /cli/teams/multi-frontend

Feedback:

Running amplify pull does not generate graphql types

Background: My amplify backend and my frontend(react native) lives under two different repos

In my frontend repo, I chose not to modify backend in amplify pull. The command will generate a models folder in my src, which includes typescript types from the published graphql models. However, the command will skip generating all the graphql queries/mutations types.

I can always manually download schema.json and do a codegen but that seems unnecessary. What is the recommended approach when we have multiple frontends and the cli won't generate graphql types

BryceAMcDaniel commented 2 years ago

I'd like to bump this. As the current multi-env suggestion or even mono-repo structure does not seem to be working on latest CLI.

suing aws to pull the schema.json is a valid solution, however, even after doing so, it still says it requires a backend file to generate the types and statements for me.

josefaidt commented 2 years ago

Hey @joedevgee and @BryceAMcDaniel :wave: are you seeing a case where running amplify pull and choosing not to modify the backend is generating the models in src/models? Similar to how amplify codegen models behaves?

To the second point, as you both have noted we will be required to download the schema before running amplify codegen types/statements. For that I will mark this as a feature request 🙂

BryceAMcDaniel commented 2 years ago

Hi @josefaidt,

I am not seeing a case where a simple pull command generates models. The only item in src for me is aws-exports.js as I expect.

After trying different methods, I was able to get what I needed and my steps are listed below.

  1. amplify pull choosing not to modify backend.
  2. aws appsync get-introspection-schema --api-id=**** --format=JSON ./schema.json
  3. amplify add codegen

My confusion came from needing to amplify add codegen.

However, I still feel as if introspection should occur without the need for step 2 (aws appsync get-introspection) as this would always ensure schema is uptodate with each codegen.

josefaidt commented 2 years ago

Hey @BryceAMcDaniel thank you for that clarification! I was also seeing that, and amplify codegen models will run off the annotated schema file rather than the built schema or introspection file.

However, I still feel as if introspection should occur without the need for step 2 (aws appsync get-introspection) as this would always ensure schema is uptodate with each codegen.

I agree with you, it would be a better experience if we are not required to first download something using another CLI and instead the file came along with the choice to not modify the backend.