Skip to content

Commit

Permalink
feat: implicit group auth fields in selection sets (#13161)
Browse files Browse the repository at this point in the history
* feat: implicit group auth fields in selection sets

* remove accidental import

* refactor: consolidating test utils
  • Loading branch information
svidgen authored Mar 25, 2024
1 parent 2b71e29 commit 1820354
Show file tree
Hide file tree
Showing 8 changed files with 662 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,301 @@ const amplifyConfig = {
sortKeyFieldNames: ['factoryId', 'warehouseId'],
},
},
ImplicitOwner: {
name: 'ImplicitOwner',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
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: 'ImplicitOwners',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
provider: 'userPools',
ownerField: 'owner',
allow: 'owner',
identityClaim: 'cognito:username',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
CustomImplicitOwner: {
name: 'CustomImplicitOwner',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
customOwner: {
name: 'customOwner',
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: 'CustomImplicitOwners',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
provider: 'userPools',
ownerField: 'customOwner',
allow: 'owner',
identityClaim: 'cognito:username',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
ModelGroupDefinedIn: {
name: 'ModelGroupDefinedIn',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
groupField: {
name: 'groupField',
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: 'ModelGroupDefinedIns',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
groupClaim: 'cognito:groups',
provider: 'userPools',
allow: 'groups',
groupsField: 'groupField',
groupField: 'groups',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
ModelGroupsDefinedIn: {
name: 'ModelGroupsDefinedIn',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
groupsField: {
name: 'groupsField',
isArray: true,
type: 'String',
isRequired: false,
attributes: [],
isArrayNullable: true,
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'ModelGroupsDefinedIns',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
groupClaim: 'cognito:groups',
provider: 'userPools',
allow: 'groups',
groupsField: 'groupsField',
groupField: 'groups',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
},
enums: {
Status: {
Expand Down
23 changes: 23 additions & 0 deletions packages/api-graphql/__tests__/fixtures/modeled/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ const schema = a.schema({
.returns(a.ref('Post'))
.handler(a.handler.custom({ entry: './jsResolver_base.js' })),
//#endregion

// #region implicit ownership models
ImplicitOwner: a
.model({
description: a.string(),
})
.authorization([a.allow.owner()]),
CustomImplicitOwner: a
.model({
description: a.string(),
})
.authorization([a.allow.owner().inField('customOwner')]),
ModelGroupDefinedIn: a
.model({
description: a.string(),
})
.authorization([a.allow.groupDefinedIn('groupField')]),
ModelGroupsDefinedIn: a
.model({
description: a.string(),
})
.authorization([a.allow.groupsDefinedIn('groupsField')]),
// #endregion
});

export type Schema = ClientSchema<typeof schema>;
Loading

0 comments on commit 1820354

Please sign in to comment.