-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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(api-graphql): custom subscriptions #13154
Conversation
@@ -1,7 +1,6 @@ | |||
{ | |||
"editor.detectIndentation": false, | |||
"editor.insertSpaces": false, | |||
"editor.tabSize": 4, |
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.
The workspace settings defined in this file override local VS Code settings, so this effectively forces everyone to use tabSize: 4
. Removing it so contributors can use their tab size of choice.
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.
No blockers jumping out at me.
const options = args[args.length - 1] as CustomOperationOptions; | ||
|
||
let contextSpec: AmplifyServer.ContextSpec | undefined; | ||
let arg: QueryArgs | undefined; | ||
|
||
if (useContext) { | ||
contextSpec = args[0] as AmplifyServer.ContextSpec; | ||
if (contextSpec?.token === undefined) { | ||
throw new Error( | ||
`Invalid first argument passed to ${operation.name}. Expected contextSpec`, | ||
); | ||
} | ||
} | ||
|
||
if (argsDefined) { | ||
if (useContext) { | ||
arg = args[1] as QueryArgs; | ||
} else { | ||
arg = args[0] as QueryArgs; | ||
} | ||
} |
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 can't brain it right now, but it would be slick if there were a way to ingest these variations with some type guarding.
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.
Agreed. contextSpec
and options
have a predictable shape, so we can guard those.
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.
(will update shortly)
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 added a type guard for contextSpec
, but options
and args
are actually not deterministically distinguishable via type guard, because options
consists of only optional params and we can't be sure that args
won't contain an argument with the same name. Updated with a slight improvement, but not fully type guarded.
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.
Gotcha. Could a type guard be applied to ...args
as a whole with guarding based on length and the shape of the first arg?
(Not a blocker.)
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.
That's an interesting idea. I think it can work. Mind if I play around with that as a follow up?
.secondaryIndexes(index => [ | ||
index('title'), | ||
index('description').sortKeys(['viewCount']), |
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.
Lines up the DX with aws-amplify/amplify-data#132
@@ -120,7 +120,7 @@ const schema = a.schema({ | |||
argumentContent: a.string().required(), | |||
}) | |||
.returns(a.ref('EchoResult')) | |||
.function('echoFunction') | |||
.handler(a.handler.function('echoFunction')) |
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.
Migrating these to the new DX as well. We still have tests in data-schema
that ensure the now-deprecated top-level .function
functionality is intact.
packages/api-graphql/src/internals/generateCustomOperationsProperty.ts
Outdated
Show resolved
Hide resolved
6936c55
to
b14e138
Compare
Draft until this is merged: aws-amplify/amplify-data#131TODO:
data-schema
&data-schema-types
dep versions after merging ^Description of changes
Adds custom subscriptions support to data-client.
Given this schema
data-client makes the following subscription functions available:
Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.