Skip to content

Support Multiple API endpoints : I want to be able to change my API endpoint for specific business logic #14591

@mattiLeBlanc

Description

@mattiLeBlanc

Is this related to a new or existing framework?

Angular

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

No response

Describe the feature you'd like to request

Hi,

I have a 3 SPA's (Angular) and 3 large Appsync APIS that serve each SPA App.
SPA1: Family app, linked to FamilyAPI
SPA2: Admin app, linked to Admin API
SPA3: MainApp, linked to ClientAPI

Some of the logic, for example image upload and conversion is done in the FamilyAPI. But sometimes I also need to do image upload and conversion in MainApp which is using ClientAPI, and I dont want to duplicate logic and create unnecessary lambda. So I call the FamilyAPI for those specific scenarios.

I configure my Amplify in each of the SPA's in the app.config.ts (loaded in main.ts) via

Amplify.configure(awsConfig.mainApp);

I create multiple resourceConfigs:

export interface ResourcesConfig {
    API?: APIConfig;
    Analytics?: AnalyticsConfig;
    Auth?: AuthConfig;
    Interactions?: InteractionsConfig;
    Notifications?: NotificationsConfig;
    Predictions?: PredictionsConfig;
    Storage?: StorageConfig;
    Geo?: GeoConfig;
}

so that my awsConfig has a config for each App and API.
They all point to the same Cognito Pool.

So in my Angular Api Service, I have a graphql call

private executeGraphQL<V>({ statement: query, variables, type, iam = false, familyApi = false }: queryInput): Observable<V> {
    if (familyApi) {
      Amplify.configure(FAMILY_APP_CONFIG);
    } else {
      Amplify.configure(APP_CONFIG);
    }

in where I can switch the configuration to the Family app config for this call. And otherwise it uses the default config for that App.
This works, but is probably not correct because by doing this I am reinitialising the whole Amplify config and that may cause stopping and starting Appsync subscriptions or causing other conflicts.
I am not sure about the bad sides of this approach.

Can you support a way where I configure Amplify at the main.ts as I do now and allow me to update the endpoint the generateClient is using for a specific call?

Lastly, I know you recommend using one API ( I prefer not too due to separation of concerns for each SPA/API) or even merging the APIs during deploy; I am aware of this but I dont yet have time to explore that due to heavy workload.

Describe the solution you'd like

Can you support a way where I configure Amplify at the main.ts as I do now and allow me to set the endpoint the generateClient is using for a specific call?

Describe alternatives you've considered

The solution I am using in the original request is my alternative

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions