@aws-amplify/graphql-model-transformer 0.15.7 → 0.16.0-rtf-release-phase-1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,24 @@
1
- import { compoundExpression, Expression, obj, printBlock, str, toJson, nul } from 'graphql-mapping-template';
2
-
1
+ import {
2
+ compoundExpression, Expression, obj, printBlock, str, toJson, nul, iff, not, isNullOrEmpty, ref,
3
+ } from 'graphql-mapping-template';
4
+ /**
5
+ * Generates subscription request template
6
+ */
3
7
  export const generateSubscriptionRequestTemplate = (): string => {
4
8
  const statements: Expression[] = [toJson(obj({ version: str('2018-05-29'), payload: obj({}) }))];
5
9
  return printBlock('Subscription Request template')(compoundExpression(statements));
6
10
  };
7
11
 
12
+ /**
13
+ * Generates subscription response template
14
+ */
8
15
  export const generateSubscriptionResponseTemplate = (): string => {
9
- const statements: Expression[] = [toJson(nul())];
16
+ const statements: Expression[] = [
17
+ iff(
18
+ not(isNullOrEmpty(ref('ctx.args.filter'))),
19
+ ref('extensions.setSubscriptionFilter($util.transform.toSubscriptionFilter($ctx.args.filter))'),
20
+ ),
21
+ toJson(nul()),
22
+ ];
10
23
  return printBlock('Subscription Response template')(compoundExpression(statements));
11
24
  };