Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Feb 2, 2024
1 parent a620a2c commit 3feedac
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/api-graphql/src/internals/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../types';
import { ClientGenerationParams } from './types';
import { ModelTypes } from '@aws-amplify/data-schema-types';
import { Hub, ResourcesConfig } from '@aws-amplify/core';
import { Hub, HubCapsule, ResourcesConfig } from '@aws-amplify/core';

/**
* @private
Expand Down Expand Up @@ -55,14 +55,11 @@ const generateModelsPropertyOnAmplifyConfigure = <
T extends Record<any, any> = never,
>(clientRef: any) => {
Hub.listen('core', coreEvent => {
const { event, data } = coreEvent.payload;

if (event !== 'configure') {
if (!isConfigureEvent(coreEvent.payload)) {
return;
}

// data is guaranteed to be `ResourcesConfig` when the event is `configure`
const resourceConfig = data as ResourcesConfig;
const { data: resourceConfig } = coreEvent.payload;

if (resourceConfig.API?.GraphQL) {
clientRef.models = generateModelsProperty<T>(
Expand All @@ -73,6 +70,15 @@ const generateModelsPropertyOnAmplifyConfigure = <
});
};

function isConfigureEvent(
payload: HubCapsule<'core', { event: string; data?: unknown }>['payload'],
): payload is {
event: 'configure';
data: ResourcesConfig;
} {
return payload.event === 'configure';
}

const emptyModels = new Proxy(
{},
{
Expand Down

0 comments on commit 3feedac

Please sign in to comment.