Skip to content

Commit

Permalink
release: Amplify JS release 2024-03-04 (#13080)
Browse files Browse the repository at this point in the history
  • Loading branch information
elorzafe authored Mar 4, 2024
2 parents 777faea + 7a8ec81 commit 53df8d2
Show file tree
Hide file tree
Showing 111 changed files with 1,105 additions and 797 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
// 'packages/api',
'packages/api-graphql',
// 'packages/api-rest',
'packages/auth',
// 'packages/auth',
// 'packages/aws-amplify',
// 'packages/core',
'packages/datastore',
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export { createServerRunner } from './createServerRunner';
export { NextServer } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,106 @@ const amplifyConfig = {
sortKeyFieldNames: [],
},
},
Product: {
name: 'Product',
fields: {
sku: {
name: 'sku',
isArray: false,
type: 'String',
isRequired: true,
attributes: [],
},
factoryId: {
name: 'factoryId',
isArray: false,
type: 'String',
isRequired: true,
attributes: [],
},
warehouseId: {
name: 'warehouseId',
isArray: false,
type: 'String',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
trackingMeta: {
name: 'trackingMeta',
isArray: false,
type: {
nonModel: 'ProductTrackingMeta',
},
isRequired: false,
attributes: [],
},
owner: {
name: 'owner',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'Products',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['sku', 'factoryId', 'warehouseId'],
},
},
{
type: 'auth',
properties: {
rules: [
{
provider: 'userPools',
ownerField: 'owner',
allow: 'owner',
identityClaim: 'cognito:username',
operations: ['create', 'update', 'delete', 'read'],
},
{
allow: 'public',
operations: ['read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: true,
primaryKeyFieldName: 'sku',
sortKeyFieldNames: ['factoryId', 'warehouseId'],
},
},
},
enums: {
Status: {
Expand Down Expand Up @@ -1313,6 +1413,69 @@ const amplifyConfig = {
},
},
},
ProductMeta: {
name: 'ProductMeta',
fields: {
releaseDate: {
name: 'releaseDate',
isArray: false,
type: 'AWSDate',
isRequired: false,
attributes: [],
},
status: {
name: 'status',
isArray: false,
type: {
enum: 'ProductMetaStatus',
},
isRequired: false,
attributes: [],
},
deepMeta: {
name: 'deepMeta',
isArray: false,
type: {
nonModel: 'ProductMetaDeepMeta',
},
isRequired: false,
attributes: [],
},
},
},
ProductTrackingMeta: {
name: 'ProductTrackingMeta',
fields: {
productMeta: {
name: 'productMeta',
isArray: false,
type: {
nonModel: 'ProductMeta',
},
isRequired: false,
attributes: [],
},
note: {
name: 'note',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
},
},
ProductMetaDeepMeta: {
name: 'ProductMetaDeepMeta',
fields: {
content: {
name: 'content',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
},
},
},
queries: {
echo: {
Expand Down
31 changes: 27 additions & 4 deletions packages/api-graphql/__tests__/internals/APIClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('APIClient', () => {
const normalized = normalizeMutationInput(
note,
noteModelDef,
modelIntroSchema,
modelIntroSchema
);

expect(normalized).toEqual(expectedInput);
Expand Down Expand Up @@ -427,6 +427,15 @@ describe('flattenItems', () => {
expect(selSet).toEqual(expected);
});

it('generates default selection set for nested custom types', () => {
const generated = generateSelectionSet(modelIntroSchema, 'Product');

const expected =
'sku factoryId warehouseId description trackingMeta { productMeta { releaseDate status deepMeta { content } } note } owner createdAt updatedAt';

expect(generated).toEqual(expected);
});

test('it should generate custom selection set - top-level fields', () => {
const selSet = generateSelectionSet(modelIntroSchema, 'Todo', [
'id',
Expand Down Expand Up @@ -476,6 +485,20 @@ describe('flattenItems', () => {

expect(selSet).toEqual(expected);
});

it('generates custom selection set for nested custom types', () => {
const generated = generateSelectionSet(modelIntroSchema, 'Product', [
'sku',
'trackingMeta.note',
'trackingMeta.productMeta.status',
'trackingMeta.productMeta.deepMeta.content',
]);

const expected =
'sku trackingMeta { note productMeta { status deepMeta { content } } }';

expect(generated).toEqual(expected);
});
});
});

Expand All @@ -489,7 +512,7 @@ describe('generateGraphQLDocument()', () => {
models: {
User: userSchemaModel,
Product: productSchemaModel,
}
},
};

test.each([
Expand All @@ -501,11 +524,11 @@ describe('generateGraphQLDocument()', () => {
const document = generateGraphQLDocument(
mockModelDefinitions,
modelName,
modelOperation,
modelOperation
);

expect(document.includes(expectedArgs)).toBe(true);
},
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ describe('generateClient', () => {
'SecondaryIndexModel',
'Post',
'Comment',
'Product',
];

it('generates `models` property when Amplify.getConfig() returns valid GraphQL provider config', () => {
Expand Down
Loading

0 comments on commit 53df8d2

Please sign in to comment.