Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add schema directives for sync operation when conflict resolutio…
…n is enabled (#8521)
- Loading branch information
Showing
9 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ify-graphql-auth-transformer/src/__tests__/__snapshots__/conflict-resolution.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test multi auth model with conflict resolution 1`] = ` | ||
"## [Start] Authorization Steps. ** | ||
$util.qr($ctx.stash.put(\\"hasAuth\\", true)) | ||
#set( $isAuthorized = false ) | ||
#set( $primaryFieldMap = {} ) | ||
#if( $util.authType() == \\"IAM Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#if( $ctx.identity.userArn == $ctx.stash.authRole ) | ||
#set( $isAuthorized = true ) | ||
#end | ||
#end | ||
#end | ||
#if( $util.authType() == \\"User Pool Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#set( $authFilter = [{ | ||
\\"owner\\": { | ||
\\"eq\\": $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) | ||
} | ||
}] ) | ||
$util.qr($ctx.stash.put(\\"authFilter\\", { \\"or\\": $authFilter })) | ||
#end | ||
#end | ||
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) && $primaryFieldMap.isEmpty() ) | ||
$util.unauthorized() | ||
#end | ||
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}}) | ||
## [End] Authorization Steps. **" | ||
`; | ||
|
||
exports[`test single auth model is enabled with conflict resolution 1`] = ` | ||
"## [Start] Authorization Steps. ** | ||
$util.qr($ctx.stash.put(\\"hasAuth\\", true)) | ||
#set( $isAuthorized = false ) | ||
#set( $primaryFieldMap = {} ) | ||
#if( $util.authType() == \\"User Pool Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#set( $authFilter = [{ | ||
\\"owner\\": { | ||
\\"eq\\": $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) | ||
} | ||
}] ) | ||
$util.qr($ctx.stash.put(\\"authFilter\\", { \\"or\\": $authFilter })) | ||
#end | ||
#end | ||
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) && $primaryFieldMap.isEmpty() ) | ||
$util.unauthorized() | ||
#end | ||
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}}) | ||
## [End] Authorization Steps. **" | ||
`; |
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/amplify-admin-auth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/amplify-graphql-auth-transformer/src/__tests__/conflict-resolution.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { AuthTransformer } from '../graphql-auth-transformer'; | ||
import { ModelTransformer } from '@aws-amplify/graphql-model-transformer'; | ||
import { GraphQLTransform, ConflictHandlerType } from '@aws-amplify/graphql-transformer-core'; | ||
import _ from 'lodash'; | ||
|
||
test('test single auth model is enabled with conflict resolution', () => { | ||
const validSchema = ` | ||
type Post @model @auth(rules: [{ allow: owner}]) { | ||
id: ID! | ||
title: String! | ||
createdAt: String | ||
updatedAt: String | ||
}`; | ||
const transformer = new GraphQLTransform({ | ||
authConfig: { | ||
defaultAuthentication: { | ||
authenticationType: 'AMAZON_COGNITO_USER_POOLS', | ||
}, | ||
additionalAuthenticationProviders: [], | ||
}, | ||
transformConfig: { | ||
ResolverConfig: { | ||
project: { | ||
ConflictDetection: 'VERSION', | ||
ConflictHandler: ConflictHandlerType.AUTOMERGE, | ||
}, | ||
}, | ||
}, | ||
transformers: [new ModelTransformer(), new AuthTransformer()], | ||
}); | ||
const out = transformer.transform(validSchema); | ||
expect(out).toBeDefined(); | ||
expect(out.schema).toContain( | ||
`syncPosts(filter: ModelPostFilterInput, limit: Int, nextToken: String, lastSync: AWSTimestamp): ModelPostConnection`, | ||
); | ||
expect(out.pipelineFunctions['Query.syncPosts.auth.1.req.vtl']).toMatchSnapshot(); | ||
}); | ||
|
||
test('test multi auth model with conflict resolution', () => { | ||
const validSchema = ` | ||
type Post @model @auth(rules: [{ allow: owner }, { allow: private, provider: iam }]) { | ||
id: ID! | ||
title: String! | ||
createdAt: String | ||
updatedAt: String | ||
}`; | ||
const transformer = new GraphQLTransform({ | ||
authConfig: { | ||
defaultAuthentication: { | ||
authenticationType: 'AMAZON_COGNITO_USER_POOLS', | ||
}, | ||
additionalAuthenticationProviders: [{ authenticationType: 'AWS_IAM' }], | ||
}, | ||
transformConfig: { | ||
ResolverConfig: { | ||
project: { | ||
ConflictDetection: 'VERSION', | ||
ConflictHandler: ConflictHandlerType.AUTOMERGE, | ||
}, | ||
}, | ||
}, | ||
transformers: [new ModelTransformer(), new AuthTransformer()], | ||
}); | ||
const out = transformer.transform(validSchema); | ||
expect(out).toBeDefined(); | ||
expect(out.schema).toContain( | ||
`syncPosts(filter: ModelPostFilterInput, limit: Int, nextToken: String, lastSync: AWSTimestamp): ModelPostConnection @aws_iam @aws_cognito_user_pools`, | ||
); | ||
expect(out.pipelineFunctions['Query.syncPosts.auth.1.req.vtl']).toMatchSnapshot(); | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/field-auth-argument.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/group-auth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/multi-auth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/owner-auth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/amplify-graphql-auth-transformer/src/__tests__/searchable-auth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters