@aws-amplify/data-schema 1.20.1 → 1.20.2

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.
@@ -605,19 +605,26 @@ function getAppSyncAuthDirectiveFromRule(rule) {
605
605
  }
606
606
  function mapToNativeAppSyncAuthDirectives(authorization, isCustomHandler) {
607
607
  const rules = new Set();
608
+ const groupProvider = new Map();
608
609
  for (const entry of authorization) {
609
610
  const rule = (0, Authorization_1.accessData)(entry);
610
611
  isCustomHandler && validateCustomHandlerAuthRule(rule);
611
612
  const provider = getAppSyncAuthDirectiveFromRule(rule);
612
613
  if (rule.groups) {
613
- // example: (cognito_groups: ["Bloggers", "Readers"])
614
- rules.add(`${provider}(cognito_groups: [${rule.groups
615
- .map((group) => `"${group}"`)
616
- .join(', ')}])`);
614
+ if (!groupProvider.has(provider)) {
615
+ groupProvider.set(provider, new Set());
616
+ }
617
+ rule.groups.forEach((group) => groupProvider.get(provider)?.add(group));
617
618
  }
618
619
  else {
619
620
  rules.add(provider);
620
621
  }
622
+ groupProvider.forEach((groups, provider) => {
623
+ rules.add(`${provider}(cognito_groups: [${Array.from(groups)
624
+ .map((group) => `"${group}"`)
625
+ .join(', ')}])`);
626
+ // example: (cognito_groups: ["Bloggers", "Readers"])
627
+ });
621
628
  }
622
629
  const authString = [...rules].join(' ');
623
630
  return { authString };