aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
158 stars 54 forks source link

support generating GraphQL client code by pointing to an AppSync API ID #1903

Open josefaidt opened 3 weeks ago

josefaidt commented 3 weeks ago

Environment information

n/a

Description

Amplify Gen 2 has a command to generate GraphQL client code by pointing to a Gen 2 backend stack, or an Amplify identifier (app ID + branch). https://docs.amplify.aws/react/reference/cli-commands/#npx-ampx-generate-graphql-client-code

npx ampx generate graphql-client-code --stack <gen2-backend-stack>

Amplify Gen 1 CLI's client codegen command accepted an API ID and region https://docs.amplify.aws/gen1/javascript/build-a-backend/graphqlapi/client-code-generation/#javascript--typescript-graphql-api-client-helper-code

npx @aws-amplify/cli codegen add --apiId <appsync-api-id> --region <appsync-api-aws-region>

When using Amplify to interact with AWS resources, but maintaining a backend separately with CDK, it would be nice if I could use the tooling available to codegen from an existing API.

Alternatively if I have the GraphQL schema, it would be nice to generate from the schema directly.

cassandramckee commented 3 weeks ago

To give some context with my use case as an example, I am building out an app on mobile and web that uses Cognito for authentication. Amplify Gen1's libraries make it simple to authenticate with Cognito and then not have to worry about all the session and token shenanigans behind the scenes. This is good because having individual developers all implementing their own session handling solutions leads to security lapses.

I then use the other clients in Amplify Gen1's libraries to call the AWS services supported by Amplify Gen1. In particular, I use Amplify Gen1's CLI to create an AppSync client from my AppSync API's schema. Because this is all done with Amplify, the auth and session handling is done behind the scenes.

However, I do not use Amplify to manage my infrastructure. Instead, that is managed via CDK directly. Thus, with Amplify Gen2, it would be appreciated if it allowed me to use the libraries and CLI without having to set up an Amplify project/stack. Especially because I do not think there are any other AWS frameworks that allow for this ease of integration with Cognito and services such as AppSync.

A different way to put it, AWS generally has the philosophy of allowing developers to choose the level of abstraction they want with AWS's services. For example, with CDK I can use different levels of constructs based on my needs (https://docs.aws.amazon.com/cdk/v2/guide/constructs.html) Even with AWS's services themselves I can choose different levels of abstraction. I can choose to spin up my own fleet of EC2 services and install Spark on them myself, or I can choose to use EMR, or going even higher level I can choose to use services such as SageMaker or Rekognition. Right now, it seems that Amplify Gen2 doesn't follow this philosophy.

Thank you for your time!

ykethan commented 3 weeks ago

Marking as feature request to codegen a existing AppSync API.

ahansson89 commented 1 week ago

The lack of this feature is a blocker for me right now

bitsplash-andy commented 1 week ago

+1 Additionally it would be nice to simply retain the ability to provide multiple custom API endpoints in the client library config and switch via the apiName parameter of the GraphQLRequest. The current Gen2 AmplifyOutputs is too strict with validation, so legacy config with multiple existing endpoints will begin to fail / become unsupported.