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

feat: add missing fields for mobile config #689

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-bottles-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/client-config': patch
---

add missing graphql fields to mobile config to support dart libs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export type ClientConfigMobileApi = {
};
};

export type ClientConfigMobileAppsyncAuth = {
ApiUrl: string;
Region: string | undefined;
AuthMode: string | undefined;
ApiKey: string | undefined;
ClientDatabasePrefix: string | undefined;
};

export type ClientConfigMobileAuth = {
plugins: {
awsCognitoAuthPlugin: {
Expand Down Expand Up @@ -55,13 +63,8 @@ export type ClientConfigMobileAuth = {
};
};
AppSync?: {
Default: {
ApiUrl: string;
Region: string | undefined;
AuthMode: string | undefined;
ApiKey: string | undefined;
};
};
Default: ClientConfigMobileAppsyncAuth;
} & Record<string, ClientConfigMobileAppsyncAuth>;
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void describe('client config converter', () => {
aws_appsync_graphqlEndpoint: 'https://test_api_endpoint.amazon.com',
aws_appsync_apiKey: 'test_api_key',
aws_appsync_authenticationType: 'API_KEY',
aws_appsync_additionalAuthenticationTypes:
'AMAZON_COGNITO_USER_POOLS,AWS_IAM',
};
const expectedMobileConfig: ClientConfigMobile = {
UserAgent: expectedUserAgent,
Expand Down Expand Up @@ -178,6 +180,21 @@ void describe('client config converter', () => {
Region: 'test_app_sync_region',
AuthMode: 'API_KEY',
ApiKey: 'test_api_key',
ClientDatabasePrefix: 'data_API_KEY',
},
data_AWS_IAM: {
ApiUrl: 'https://test_api_endpoint.amazon.com',
Region: 'test_app_sync_region',
AuthMode: 'API_KEY',
ApiKey: 'test_api_key',
ClientDatabasePrefix: 'data_AWS_IAM',
},
data_AMAZON_COGNITO_USER_POOLS: {
ApiUrl: 'https://test_api_endpoint.amazon.com',
Region: 'test_app_sync_region',
AuthMode: 'API_KEY',
ApiKey: 'test_api_key',
ClientDatabasePrefix: 'data_AMAZON_COGNITO_USER_POOLS',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,34 @@ export class ClientConfigConverter {
mobileConfig.api = apiConfig;

if (mobileConfig.auth) {
let defaultClientDatabasePrefix = undefined;
if (clientConfig.aws_appsync_authenticationType) {
defaultClientDatabasePrefix = `data_${clientConfig.aws_appsync_authenticationType}`;
}
mobileConfig.auth.plugins.awsCognitoAuthPlugin.AppSync = {
Default: {
ApiUrl: clientConfig.aws_appsync_graphqlEndpoint,
Region: clientConfig.aws_appsync_region,
AuthMode: clientConfig.aws_appsync_authenticationType,
ApiKey: clientConfig.aws_appsync_apiKey,
ClientDatabasePrefix: defaultClientDatabasePrefix,
},
};
if (clientConfig.aws_appsync_additionalAuthenticationTypes) {
for (const additionalAuthenticationType of clientConfig.aws_appsync_additionalAuthenticationTypes.split(
','
)) {
mobileConfig.auth.plugins.awsCognitoAuthPlugin.AppSync[
`data_${additionalAuthenticationType}`
] = {
ApiUrl: clientConfig.aws_appsync_graphqlEndpoint,
Region: clientConfig.aws_appsync_region,
AuthMode: clientConfig.aws_appsync_authenticationType,
ApiKey: clientConfig.aws_appsync_apiKey,
ClientDatabasePrefix: `data_${additionalAuthenticationType}`,
};
}
}
}
}
return mobileConfig;
Expand Down