diff --git a/packages/api-graphql/src/internals/InternalGraphQLAPI.ts b/packages/api-graphql/src/internals/InternalGraphQLAPI.ts index 8ce074ad111..2e248aca209 100644 --- a/packages/api-graphql/src/internals/InternalGraphQLAPI.ts +++ b/packages/api-graphql/src/internals/InternalGraphQLAPI.ts @@ -456,9 +456,12 @@ export class InternalGraphQLAPIClass { additionalHeaders = {}, customUserAgentDetails?: CustomUserAgentDetails ): Observable { + debugger; if (!this.appSyncRealTime) { const { AppSync } = Amplify.getConfig().API ?? {}; + debugger; + this.appSyncRealTime = new AWSAppSyncRealTimeProvider(); return this.appSyncRealTime.subscribe({ diff --git a/packages/api/src/API.ts b/packages/api/src/API.ts index 16a5c289d58..0f52fedbe15 100644 --- a/packages/api/src/API.ts +++ b/packages/api/src/API.ts @@ -67,42 +67,44 @@ export class APIClass extends InternalAPIClass { models: {}, }; - for (const model of Object.values(modelIntrospection.models)) { - const { name } = model as any; + if (modelIntrospection) { + for (const model of Object.values(modelIntrospection.models)) { + const { name } = model as any; - client.models[name] = {} as any; + client.models[name] = {} as any; - Object.entries(graphQLOperationsInfo).forEach( - ([key, { operationPrefix }]) => { - const operation = key as ModelOperation; + Object.entries(graphQLOperationsInfo).forEach( + ([key, { operationPrefix }]) => { + const operation = key as ModelOperation; - // e.g. clients.models.Todo.update - client.models[name][operationPrefix] = async (arg?: any) => { - const query = generateGraphQLDocument(model, operation); - const variables = buildGraphQLVariables(model, operation, arg); + // e.g. clients.models.Todo.update + client.models[name][operationPrefix] = async (arg?: any) => { + const query = generateGraphQLDocument(model, operation); + const variables = buildGraphQLVariables(model, operation, arg); - const res = (await this.graphql({ - query, - // TODO V6 - // @ts-ignore - variables, - })) as any; + const res = (await this.graphql({ + query, + // TODO V6 + // @ts-ignore + variables, + })) as any; - // flatten response - if (res.data !== undefined) { - const [key] = Object.keys(res.data); + // flatten response + if (res.data !== undefined) { + const [key] = Object.keys(res.data); - if (res.data[key].items) { - return res.data[key].items; - } + if (res.data[key].items) { + return res.data[key].items; + } - return res.data[key]; - } + return res.data[key]; + } - return res; - }; - } - ); + return res; + }; + } + ); + } } return client as V6Client; diff --git a/packages/core/__tests__/parseAWSExports.test.ts b/packages/core/__tests__/parseAWSExports.test.ts index bae0c6ea074..00f6b64f76c 100644 --- a/packages/core/__tests__/parseAWSExports.test.ts +++ b/packages/core/__tests__/parseAWSExports.test.ts @@ -1,5 +1,6 @@ import { parseAWSExports } from '../src/parseAWSExports'; +// TODO: Add API category tests describe('Parser', () => { test('aws_mobile_analytics_app_id', () => { const appId = 'app-id'; diff --git a/packages/core/src/parseAWSExports.ts b/packages/core/src/parseAWSExports.ts index 3a8a1156a50..7e4cb4bbd2e 100644 --- a/packages/core/src/parseAWSExports.ts +++ b/packages/core/src/parseAWSExports.ts @@ -11,15 +11,24 @@ import { ResourcesConfig } from './singleton/types'; * * @returns A {@link ResourcesConfig} object. */ + export const parseAWSExports = ( config: Record = {} ): ResourcesConfig => { const { + aws_appsync_apiKey, + aws_appsync_authenticationType, + aws_appsync_graphqlEndpoint, + aws_appsync_region, aws_cognito_identity_pool_id, + // TODO - which category does this fall under? + // aws_cognito_region, aws_cognito_sign_up_verification_method, aws_mandatory_sign_in, aws_mobile_analytics_app_id, aws_mobile_analytics_app_region, + // TODO - which category does this fall under? + // aws_project_region, aws_user_files_s3_bucket, aws_user_files_s3_bucket_region, aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing, @@ -40,6 +49,18 @@ export const parseAWSExports = ( }; } + // API + if (aws_appsync_graphqlEndpoint) { + amplifyConfig.API = { + AppSync: { + apiKey: aws_appsync_apiKey, + defaultAuthMode: aws_appsync_authenticationType, + endpoint: aws_appsync_graphqlEndpoint, + region: aws_appsync_region, + }, + }; + } + // Auth if (aws_cognito_identity_pool_id || aws_user_pools_id) { amplifyConfig.Auth = { diff --git a/packages/core/src/singleton/API/types.ts b/packages/core/src/singleton/API/types.ts index d1cf72638cd..802ef2fed47 100644 --- a/packages/core/src/singleton/API/types.ts +++ b/packages/core/src/singleton/API/types.ts @@ -20,6 +20,7 @@ export type APIConfig = { defaultAuthMode?: GraphQLAuthMode; region?: string; endpoint?: string; + apiKey: string; // TODO: switch this when dependency is added: // modelIntrospectionSchema: InternalModelIntrospectionSchema; modelIntrospectionSchema?: any;