Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Mar 21, 2024
1 parent a3feb6b commit b14e138
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/api-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"dependencies": {
"@aws-amplify/api-rest": "4.0.21",
"@aws-amplify/core": "6.0.21",
"@aws-amplify/data-schema-types": "^0.7.10",
"@aws-amplify/data-schema-types": "^0.7.11",
"@aws-sdk/types": "3.387.0",
"graphql": "15.8.0",
"rxjs": "^7.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type CustomOpsProperty<
? CustomQueries<T>
: OpType extends 'mutations'
? CustomMutations<T>
: CustomSubscriptions<T>;
: OpType extends 'subscriptions'
? CustomSubscriptions<T>
: never;

const operationTypeMap = {
queries: 'query',
Expand Down
14 changes: 12 additions & 2 deletions packages/api-graphql/src/internals/operations/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ type OpArgs =
// Client or SSR Cookies Client without Args defined
| [CustomOperationOptions];

/**
* Type guard for checking whether a Custom Operation argument is a contextSpec object
*/
const argIsContextSpec = (
arg: OpArgs[number],
): arg is AmplifyServer.ContextSpec => {
return typeof (arg as AmplifyServer.ContextSpec)?.token?.value === 'symbol';
};

/**
* Builds an operation function, embedded with all client and context data, that
* can be attached to a client as a custom query or mutation.
Expand Down Expand Up @@ -115,8 +124,9 @@ export function customOpFactory(
let arg: QueryArgs | undefined;

if (useContext) {
contextSpec = args[0] as AmplifyServer.ContextSpec;
if (contextSpec?.token === undefined) {
if (argIsContextSpec(args[0])) {
contextSpec = args[0];
} else {
throw new Error(
`Invalid first argument passed to ${operation.name}. Expected contextSpec`,
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b14e138

Please sign in to comment.