@aws-amplify/data-schema 1.20.1 → 1.20.3

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