Skip to content

Commit

Permalink
fix(auth): ownerfield as pk in relational models (#1389)
Browse files Browse the repository at this point in the history
* fix(auth): ownerfield as pk in relational models

* fix hasone belongsto relation of owner pk auth

* fix: use stash for sort key value

* fix unit test

* fix: unit tests

* rm yarn lock change

* add e2e test

* change snapshot
  • Loading branch information
AaronZyLee committed Apr 12, 2023
1 parent 3ffb788 commit bfb3807
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ const generateAuthOnRelationalModelQueryExpression = (
iff(
and([not(ref(IS_AUTHORIZED_FLAG)), methodCall(ref('util.isNull'), ref('ctx.stash.authFilter'))]),
compoundExpression([
qref(methodCall(ref(`ctx.${claim}.put`), str(field), ref(`primaryRole${idx}`))),
qref(
methodCall(claim === 'source'
? ref(`ctx.stash.connectionAttributes.put`)
: ref(`ctx.${claim}.put`),
str(field),
ref(`primaryRole${idx}`)
)),
set(ref(IS_AUTHORIZED_FLAG), bool(true)),
]),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -286,6 +287,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -412,6 +414,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -463,6 +466,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -1089,6 +1093,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -1136,6 +1141,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -1183,6 +1189,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -1236,6 +1243,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -1645,6 +1653,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -1693,6 +1702,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -1816,6 +1826,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -1864,6 +1875,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -2164,6 +2176,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -2205,6 +2218,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -2246,6 +2260,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -2293,6 +2308,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -2546,6 +2562,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -2597,6 +2614,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -2723,6 +2741,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -2774,6 +2793,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -3392,6 +3412,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -3439,6 +3460,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -3521,6 +3543,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "PostTable",
Expand Down Expand Up @@ -3922,6 +3945,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -3970,6 +3994,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -4093,6 +4118,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -4141,6 +4167,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down Expand Up @@ -4441,6 +4468,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -4482,6 +4510,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -4523,6 +4552,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.toJson({})",
],
Expand Down Expand Up @@ -4570,6 +4600,7 @@ $util.qr($ctx.stash.metadata.put(\\"apiId\\", \\"",
"Ref": "referencetotransformerrootstackGraphQLAPI20497F53ApiId",
},
"\\"))
$util.qr($ctx.stash.put(\\"connectionAttributes\\", {}))
$util.qr($ctx.stash.put(\\"tableName\\", \\"",
Object {
"Ref": "CommentTable",
Expand Down
Loading

0 comments on commit bfb3807

Please sign in to comment.