Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release(required): api-graphql - default selection set regression #13188

Merged
merged 1 commit into from
Mar 28, 2024
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
@@ -1,5 +1,5 @@
/**
* Generated from `./schema.ts` by samsara.
* Generated from `./schema.ts` by amplify-backend generate config.
*
* Cognito fields etc. omitted.
*/
Expand Down Expand Up @@ -1656,6 +1656,68 @@ const amplifyConfig = {
sortKeyFieldNames: [],
},
},
ModelStaticGroup: {
name: 'ModelStaticGroup',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'ModelStaticGroups',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'auth',
properties: {
rules: [
{
groupClaim: 'cognito:groups',
provider: 'userPools',
allow: 'groups',
groups: ['Admin'],
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
},
enums: {
Status: {
Expand Down
5 changes: 5 additions & 0 deletions packages/api-graphql/__tests__/fixtures/modeled/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ const schema = a.schema({
description: a.string(),
})
.authorization([a.allow.groupsDefinedIn('groupsField')]),
ModelStaticGroup: a
.model({
description: a.string(),
})
.authorization([a.allow.specificGroup('Admin')]),
// #endregion
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('generateClient', () => {
'CustomImplicitOwner',
'ModelGroupDefinedIn',
'ModelGroupsDefinedIn',
'ModelStaticGroup',
];

it('generates `models` property when Amplify.getConfig() returns valid GraphQL provider config', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/api-graphql/__tests__/resolveOwnerFields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('owner field resolution', () => {
ThingWithOwnerFieldSpecifiedInModel: ['owner'],
ThingWithAPIKeyAuth: [],
ThingWithoutExplicitAuth: [],
ModelGroupDefinedIn: ['groupField'],
ModelGroupsDefinedIn: ['groupsField'],
ModelStaticGroup: [],
};

for (const [modelName, expected] of Object.entries(expectedResolutions)) {
Expand All @@ -23,7 +26,7 @@ describe('owner field resolution', () => {
const model: SchemaModel = modelIntroSchema.models[modelName];

const resolvedField = resolveOwnerFields(model);
expect(resolvedField).toEqual(expected);
expect(resolvedField).toStrictEqual(expected);
});
}
});
5 changes: 4 additions & 1 deletion packages/api-graphql/src/utils/resolveOwnerFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function resolveOwnerFields(model: Model): string[] {
for (const rule of attr.properties.rules) {
if (rule.allow === 'owner') {
ownerFields.add(rule.ownerField || 'owner');
} else if (rule.allow === 'groups') {
} else if (rule.allow === 'groups' && rule.groupsField !== undefined) {
// only valid for dynamic group(s)
// static group auth will have an array of predefined groups in the attribute, groups: string[]
// but `groupsField` will be undefined
ownerFields.add(rule.groupsField);
}
}
Expand Down
Loading