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

Get the introspection schema with amplify pull (without pulling the backend ressources) #223

Closed
alexboulay opened this issue Sep 29, 2020 · 10 comments
Labels
amplify-codegen Issues on amplify-codegen feature-request New feature or request

Comments

@alexboulay
Copy link

Is your feature request related to a problem? Please describe.
When a front-end engineer wants to use a GraphQL API, he will pull the Amplify project to access it. He does not have the intention of modifying the APIs or Functions within that Amplify project. However, he wants to use amplify codegen which would require to download the introspection schema from the AppSync console. Not a very nice workflow since he want's to regenerate his code as soon as there is new stuff added to the API.

Describe the solution you'd like
It would be nice to be able to do amplify codegen, without having to download the introspection schema manually. The current solution is to pull the backend by saying "yes" when prompted by the CLI to this question "Do you plan on modifying this backend?". Maybe, another question would be, would you like to pull the introspection schema? And each subsequent pull would update the schema in question. This way, it is easy for front-end devs to keep up with the schema.

@nikhname
Copy link
Contributor

Hi @alexboulay, we support the use case of automatically downloading the introspection schema for codegen by using amplify codegen --apiId XXXXX, where --apiID is the unique AppSync identifier for your API (https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/js#using-aws-appsync-sdk).
If you are using codegen in an uninitialized project you will still need to manually download the introspection schema.

@alexboulay
Copy link
Author

When you say "uninitialized project", do you mean a project that's been pulled without the backend? Because my goal is to simply run amplify pull then amplify codegen. If I pull the amplify project, logically, the CLI should know what API i am referring to

@nikhname
Copy link
Contributor

By uninitialized project we mean a project where init or pull has not been executed. It would make sense for codegen to automatically determine the apiId and download the introspection schema after a question so I am marking this as an enhancement.

@alexboulay
Copy link
Author

Sweet. In the meantime, I tried your suggestion. It seems that within my project where I have pulled an existing project(without pulling back end ressources), I run amplify codegen --appId XXXX. I get the following output: Please download the schema.graphql or schema.json From what you said, I don't think this is normal behaviour.

@themse
Copy link

themse commented May 4, 2021

Any updates? How can we download the introspection schema? @nikhname, unfortunately your explanation doesn't work. And codegen isn't perfect (especially models and types). Don't you think about cooperation with graphql-codegen team? Their codegen is perfect. They generate hooks and it helps to avoid code duplication all the time and keep strict typing.

@themse
Copy link

themse commented May 5, 2021

@alexboulay I've found the way how to workaround this issue. It's not the best solution, but better than nothing

$ aws appsync get-introspection-schema --api-id=XXX --format=SDL schema.graphql --profile=XXX

if you don't feel like sending profile, you can configure region (it is required) using command aws configure.
Further

$ amplify codegen

and .graphqlconfig.yml

projects:
  yourProjectName:
    schemaPath: schema.graphql
    includes:
      - src/amplify/generated/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: src/amplify/generated/API.ts
        docsFilePath: src/amplify/generated
        region: us-west-2
        apiId: null
        maxDepth: 2
        frontend: javascript
        framework: react-native
extensions:
  amplify:
    version: 3

or you can generate .graphqlconfig.yml, just use

$ amplify codegen configure

@edwardfoyle edwardfoyle transferred this issue from aws-amplify/amplify-cli Aug 16, 2021
@zirkelc
Copy link

zirkelc commented Oct 28, 2021

I'm also struggling with this. In my project which do not modify the backend I have to download the introspection schema via aws sdk and then generate the types. It would be nice to do that in one go with amplify codegen.

@phani-srikar phani-srikar added feature-request New feature or request amplify-codegen Issues on amplify-codegen labels Mar 29, 2022
@BryceAMcDaniel
Copy link

I would request this be changed from feature-request to bug.

Currently, I am not able to get codegen to use schema.json, schema.graphql or to download and introspect by giving an appId.

Using either of the schema.json or schema.graphql that is downloaded from AppSync still requires a backend listed.

Current example and use case.

  1. 'amplify pull' with choosing No for pulling amplify backend.
  2. pull schema using json or SDL from aws and place in current project dir as stated above.
  3. amplify codegen [statements, types, models] results in error:

ENOENT: no such file or directory, open '[redacted]/amplify/backend/api/[project]/build/schema.graphql'

Only after cp schema to that location does it seem to work, however, the next amplify pull erases this and it must be replaced.

@dpilch
Copy link
Member

dpilch commented Apr 4, 2024

This can be accomplished by:

amplify codegen add --apiId <appsync-api-id> --region <appsync-api-region>
amplify codegen

@dpilch dpilch closed this as completed Apr 4, 2024
Copy link

github-actions bot commented Apr 4, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify-codegen Issues on amplify-codegen feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants