-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: allow customtypes ref in arguments/main #497
base: main
Are you sure you want to change the base?
Changes from 12 commits
e7f97fa
0e0561e
1a54cde
ecf2ec2
a0872b9
2f7e948
45074a3
3517643
2e81a9d
c54ed9b
a7dd990
cc50e20
fff0b5d
f4b9171
949e6ee
cdb02d1
2f8c281
6b82830
f1b8e0e
acaa7d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@aws-amplify/data-schema": minor | ||
--- | ||
|
||
Allow CustomType and RefType in arguments for custom operations |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -907,15 +907,15 @@ describe('CustomOperation transform', () => { | |
.query() | ||
.arguments({}) | ||
.handler(a.handler.function(fn1).async()) | ||
.authorization((allow) => allow.authenticated()) | ||
.authorization((allow) => allow.authenticated()), | ||
}); | ||
|
||
const { schema, lambdaFunctions } = s.transform(); | ||
expect(schema).toMatchSnapshot(); | ||
expect(lambdaFunctions).toMatchObject({ | ||
FnGetPostDetails: fn1, | ||
}); | ||
}) | ||
}); | ||
|
||
test('defineFunction sync - async', () => { | ||
const fn1 = defineFunctionStub({}); | ||
|
@@ -927,15 +927,15 @@ describe('CustomOperation transform', () => { | |
a.handler.function(fn1), | ||
a.handler.function(fn1).async(), | ||
]) | ||
.authorization((allow) => allow.authenticated()) | ||
.authorization((allow) => allow.authenticated()), | ||
}); | ||
|
||
const { schema, lambdaFunctions } = s.transform(); | ||
expect(schema).toMatchSnapshot(); | ||
expect(lambdaFunctions).toMatchObject({ | ||
FnGetPostDetails: fn1, | ||
}); | ||
}) | ||
}); | ||
|
||
test('defineFunction sync - async with returns generates type errors', () => { | ||
const fn1 = defineFunctionStub({}); | ||
|
@@ -949,9 +949,9 @@ describe('CustomOperation transform', () => { | |
]) | ||
.authorization((allow) => allow.authenticated()) | ||
// @ts-expect-error | ||
.returns({ }) | ||
.returns({}), | ||
}); | ||
}) | ||
}); | ||
|
||
test('defineFunction async - async', () => { | ||
const fn1 = defineFunctionStub({}); | ||
|
@@ -965,7 +965,7 @@ describe('CustomOperation transform', () => { | |
a.handler.function(fn1).async(), | ||
a.handler.function(fn2).async(), | ||
]) | ||
.authorization((allow) => allow.authenticated()) | ||
.authorization((allow) => allow.authenticated()), | ||
}); | ||
|
||
const { schema, lambdaFunctions } = s.transform(); | ||
|
@@ -974,7 +974,7 @@ describe('CustomOperation transform', () => { | |
FnGetPostDetails: fn1, | ||
FnGetPostDetails2: fn2, | ||
}); | ||
}) | ||
}); | ||
|
||
test('defineFunction async - sync', () => { | ||
const fn1 = defineFunctionStub({}); | ||
|
@@ -987,12 +987,12 @@ describe('CustomOperation transform', () => { | |
a.handler.function(fn1), | ||
]) | ||
.returns(a.customType({})) | ||
.authorization((allow) => allow.authenticated()) | ||
.authorization((allow) => allow.authenticated()), | ||
}); | ||
|
||
const { schema, lambdaFunctions } = s.transform(); | ||
expect(schema).toMatchSnapshot(); | ||
}) | ||
}); | ||
|
||
test('pipeline / mix', () => { | ||
const fn1 = defineFunctionStub({}); | ||
|
@@ -1341,15 +1341,14 @@ describe('custom operations + custom type auth inheritance', () => { | |
|
||
test('implicit custom type inherits auth rules from referencing op', () => { | ||
const s = a.schema({ | ||
MyQueryReturnType: a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
}), | ||
myQuery: a | ||
.query() | ||
.handler(a.handler.function('myFn')) | ||
.returns( | ||
a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
}), | ||
) | ||
.returns(a.ref('MyQueryReturnType')) | ||
.authorization((allow) => allow.publicApiKey()), | ||
}); | ||
|
||
|
@@ -1363,23 +1362,22 @@ describe('custom operations + custom type auth inheritance', () => { | |
|
||
test('nested custom types inherit auth rules from top-level referencing op', () => { | ||
const s = a.schema({ | ||
MyQueryReturnType: a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
nestedCustomType: a.customType({ | ||
nestedA: a.string(), | ||
nestedB: a.string(), | ||
grandChild: a.customType({ | ||
grandA: a.string(), | ||
grandB: a.string(), | ||
}), | ||
}), | ||
}), | ||
myQuery: a | ||
.query() | ||
.handler(a.handler.function('myFn')) | ||
.returns( | ||
a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
nestedCustomType: a.customType({ | ||
nestedA: a.string(), | ||
nestedB: a.string(), | ||
grandChild: a.customType({ | ||
grandA: a.string(), | ||
grandB: a.string(), | ||
}), | ||
}), | ||
}), | ||
) | ||
.returns(a.ref('MyQueryReturnType')) | ||
.authorization((allow) => allow.publicApiKey()), | ||
}); | ||
|
||
|
@@ -1401,6 +1399,28 @@ describe('custom operations + custom type auth inheritance', () => { | |
); | ||
}); | ||
|
||
test('inline custom type inherits auth rules from referencing op', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change description doesn't talk about inherited auth rules. I'm puzzled by the how the test changes in this file related back to the broader change. Took a closer look here expecting to find My thinking is that we would have unit tests covering a many cases and basic behavior testing in the e2e, but I'm open to this being misaligned with guidance from others. Interested to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have overlooked the connection between the test changes and the broader change in the description. The current tests, including those for inherited auth rules, are covering the functionality for custom types and refs in arguments. The e2e define_behavior tests complement the unit tests here by covering end-to-end scenarios. |
||
const s = a.schema({ | ||
myQuery: a | ||
.query() | ||
.handler(a.handler.function('myFn')) | ||
.returns( | ||
a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
}), | ||
) | ||
.authorization((allow) => allow.publicApiKey()), | ||
}); | ||
|
||
const result = s.transform().schema; | ||
|
||
expect(result).toMatchSnapshot(); | ||
expect(result).toEqual( | ||
expect.stringContaining('type MyQueryReturnType @aws_api_key\n{'), | ||
); | ||
}); | ||
|
||
test('top-level custom type with nested top-level custom types inherits combined auth rules from referencing ops', () => { | ||
const s = a.schema({ | ||
myQuery: a | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might expect
Equal<A,B>
to show up here. Could you use type equality instead of setting the type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented as suggested.