Amplify-cli: Allow more than one GraphQL API in a project

Created on 22 Oct 2018  路  9Comments  路  Source: aws-amplify/amplify-cli

Is your feature request related to a problem? Please describe.
Currently it is not possible to add more than one GraphQL endpoint in a project. There are use cases where multiple GraphQL endpoints are required, for security isolation, for code maintenance, or for multiple backend microservices.

Describe the solution you'd like
To allow multiple GraphQL endpoints in an Amplify project. To share Amplify CLI created resources (e.g. DynamoDB, User Pool) between these endpoints in a project.

feature-request

Most helpful comment

Thanks for the feature request. We will use this ticket to track this item as we prioritize. It would be nice to allow multiple APIs in one project. The goto use case to me is to allow a publically available API with IAM auth enabled and then a user based API with user pools enabled in the same project.

All 9 comments

Thanks for the feature request. We will use this ticket to track this item as we prioritize. It would be nice to allow multiple APIs in one project. The goto use case to me is to allow a publically available API with IAM auth enabled and then a user based API with user pools enabled in the same project.

I was able to use two different GraphQL endpoints in my React Native project by simply setting awsExports.API.aws_appsync_graphqlEndpoint and reinvoking Amplify.configure(amplifyConfig)

Thanks for the feature request. We will use this ticket to track this item as we prioritize. It would be nice to allow multiple APIs in one project. The goto use case to me is to allow a publically available API with IAM auth enabled and then a user based API with user pools enabled in the same project.

This use case you're describing is what got me here. I want to add data to a database which should be publically available without logging in with Cognito. Add data while logged in and read it from anywhere. Is there any other thread since this got closed, or will it be re-opened when feature is being worked on?

Why was this closed? I also need this as i need to access different graphql endpoints for different tasks obviously.
A very hacky solution would be this:

Configuration

 API: {
  graphql_endpoint: '',//this needs to be empty!
  graphql_endpoint_iam_region: 'eu-central-1',
  endpoints: [
    {
      name: "Live",
      endpoint: "https://??????????.execute-api.eu-central-1.amazonaws.com/live/endpoint1"
    },
    {
      name: Beta1",
      endpoint: "https://??????????.execute-api.eu-central-1.amazonaws.com/beta/endpoint1",
    },
    {
      name: "Beta2",
      endpoint: "https://??????????.execute-api.eu-central-1.amazonaws.com/beta/endpoint2",
    }
  ],
  graphql_headers: async () => { const currentUser = await Auth.currentSession(); return {
   'Authorization': "????"
  }}
}

Usage

//switch api before each request when needed by setting it manually into the graphl_endpoints config
API._options.graphql_endpoint = API._options.endpoints[0].endpoint;
//execute graphql 
const data = await API.graphql(graphqlOperation("query", { }));

Any updates on this?

Wanted to share my +1.

My use case is that I first created an API using the standard DynamoDB-backed data source, but now want to migrate some, but not all, aspects of the API to Aurora Serverless as they're a better fit for relational querying. I'd like to slowly migrate feature by feature, and it would be awesome to be able to use the out-of-the-box Amplify CLI capabilities to declare both APIs side by side.

@jaxondu & @mikeparisstuff, seconding question above. Why was this issue closed?

I'm using the way that i posted above, and honestly the only drawback i see is that if you change the endpoint you have to change it back.

So basically the solution is there, it should only be improved. Maybe a helper function could be made which changes back the endpoint do the default one (first) if a call to a different one has been made

@jaxondu could you reopen the feature request? You might not be interested in it anymore, but others seem to be :)

I second @michaelwittig's view. It's a major deficiency of Amplify to only allow one GraphQL API per project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DonPepone picture DonPepone  路  70Comments

baharev picture baharev  路  44Comments

simon-lanf picture simon-lanf  路  42Comments

mikeparisstuff picture mikeparisstuff  路  48Comments

lennybr picture lennybr  路  46Comments