Skip to content

Commit 7288df9

Browse files
committed
fix: add check for studio enabled projects
1 parent 83de4ef commit 7288df9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

packages/amplify-provider-awscloudformation/src/__tests__/admin-modelgen.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jest.mock('fs-extra');
88
jest.mock('../aws-utils/aws-s3');
99
jest.mock('@aws-amplify/amplify-cli-core');
1010
jest.mock('graphql-transformer-core');
11-
jest.mock('../utils/admin-helpers');
1211
jest.mock('@aws-amplify/amplify-prompts');
1312

1413
const fsMock = fs as jest.Mocked<typeof fs>;
@@ -37,6 +36,10 @@ fsMock.createWriteStream.mockReturnValue({
3736
},
3837
} as unknown as fs.WriteStream);
3938
fsMock.createReadStream.mockImplementation((filePath) => `mock body of ${filePath}` as unknown as fs.ReadStream);
39+
jest.mock('../utils/admin-helpers', () => ({
40+
...jest.requireActual('../utils/admin-helpers'),
41+
isAmplifyAdminApp: jest.fn().mockResolvedValue({ isAdminApp: true }),
42+
}));
4043

4144
const s3FactoryMock = S3 as jest.Mocked<typeof S3>;
4245

@@ -128,7 +131,7 @@ describe('project with single schema file that exists', () => {
128131
});
129132
});
130133

131-
describe('project without a single schema file or with multiple schema files', () => {
134+
describe('studio enabled project with multiple schema files or non-existent single schema file', () => {
132135
beforeEach(() => {
133136
jest.clearAllMocks();
134137
contextStub = {
@@ -139,7 +142,7 @@ describe('project without a single schema file or with multiple schema files', (
139142
fsMock.existsSync.mockReturnValue(false);
140143
});
141144

142-
it('early returns and throws appropriate warning', async () => {
145+
it('early returns and throws appropriate warning for a studio app', async () => {
143146
await adminModelgen(contextStub, resources);
144147

145148
expect(invokePluginMock.mock.calls.length).toBe(0);

packages/amplify-provider-awscloudformation/src/admin-modelgen.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from 'path';
55
import { S3 } from './aws-utils/aws-s3';
66
import { ProviderName as providerName } from './constants';
77
import { printer } from '@aws-amplify/amplify-prompts';
8+
import { isAmplifyAdminApp } from './utils/admin-helpers';
89

910
/**
1011
* Generates DataStore Models for Admin UI CMS to consume
@@ -28,11 +29,14 @@ export const adminModelgen = async (context: $TSContext, resources: $TSAny[]): P
2829
}
2930

3031
const localSchemaPath = path.join(pathManager.getResourceDirectoryPath(undefined, 'api', resourceName), 'schema.graphql');
31-
// Early return with useful warning if the schema file does not exist
32+
// Early return with a warning if the schema file does not exist
3233
if (!fs.existsSync(localSchemaPath)) {
33-
printer.warn(
34-
`Could not find the GraphQL schema file at "${localSchemaPath}". Amplify Studio's schema editor might not work as intended if you're using multiple schema files.`,
35-
);
34+
const { isAdminApp } = await isAmplifyAdminApp(appId);
35+
if (isAdminApp) {
36+
printer.warn(
37+
`Could not find the GraphQL schema file at "${localSchemaPath}". Amplify Studio's schema editor might not work as intended if you're using multiple schema files.`,
38+
);
39+
}
3640
return;
3741
}
3842

0 commit comments

Comments
 (0)