Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Todo @model @auth(rules: [{ allow: private, provider: iam }]) {
id: ID!
name: String!
description: String
description1: String
}
38 changes: 38 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/function_13.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
addApi,
addFunction,
amplifyPush,
amplifyPushCategoryWithYesFlag,
createNewProjectDir,
deleteProject,
deleteProjectDir,
generateRandomShortId,
initJSProjectWithProfile,
updateApiSchema,
} from '@aws-amplify/amplify-e2e-core';

describe('amplify push function cases:', () => {
let projRoot: string;

beforeEach(async () => {
projRoot = await createNewProjectDir('lambda-appsync-nodejs');
});

afterEach(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

it('Test case when IAM is set as default auth and api is already deployed and pushing function', async () => {
const projName = `iammodel${generateRandomShortId()}`;
await initJSProjectWithProfile(projRoot, { name: projName });
await addApi(projRoot, { IAM: {}, transformerVersion: 2 });
updateApiSchema(projRoot, projName, 'iam_simple_model.graphql');
await amplifyPush(projRoot);
// update api
updateApiSchema(projRoot, projName, 'iam_simple_model1.graphql');
await addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs');
// should only push function
await amplifyPushCategoryWithYesFlag(projRoot, 'function', true);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const fsext = require('fs-extra');
const path = require('path');
const { AmplifyCategories, AmplifySupportedService, pathManager } = require('@aws-amplify/amplify-cli-core');

const TransformPackage = require('graphql-transformer-core');
const { S3 } = require('./aws-utils/aws-s3');
Expand Down Expand Up @@ -225,6 +226,27 @@ async function uploadAppSyncFiles(context, resourcesToUpdate, allResources, opti
const resourceDir = path.normalize(path.join(backEndDir, category, resourceName));
const deploymentRootKey = await getDeploymentRootKey(resourceDir);
writeUpdatedParametersJson(resource, deploymentRootKey);
} else {
// case where api is deployed already and non api resources are pushed
// this is done to keep the nested stack same if api resource is in update state (updated gql schema)
const { resourcesToBeCreated, allResources } = await context.amplify.getResourceStatus(AmplifyCategories.API);
const apiResource = allResources.find((resource) => resource.service === AmplifySupportedService.APPSYNC);
const apiResourceToBeCreated = resourcesToBeCreated.find((resource) => resource.service === AmplifySupportedService.APPSYNC);

if (!apiResource) {
return;
}
if (apiResourceToBeCreated) {
return;
}
// get the deployment key from #current-cloud-backend
const currentBackEndDir = pathManager.getCurrentCloudBackendDirPath();
const currentResourceDirectoryPath = path.join(currentBackEndDir, apiResource.category, apiResource.resourceName);
// check api resource folder is present in #current-cloud-backend and is not empty
if (fs.existsSync(currentResourceDirectoryPath) && fs.readdirSync(currentResourceDirectoryPath).length !== 0) {
const deploymentRootKey = await getDeploymentRootKey(currentResourceDirectoryPath);
writeUpdatedParametersJson(apiResource, deploymentRootKey);
}
}
}

Expand Down