{
  "version": 3,
  "sources": ["../../src/compilerTransforms/annotateFragmentReferenceTransform.ts"],
  "sourcesContent": ["import {\n  CompilerContext,\n  Fragment,\n  InlineFragment,\n  LinkedField,\n  Root,\n  ScalarField,\n} from \"relay-compiler\";\nimport { IRTransform } from \"relay-compiler/lib/core/CompilerContext\";\nimport { visit } from \"relay-compiler/lib/core/IRVisitor\";\nimport { implementsNodeInterface } from \"./utils\";\n\nconst FRAGMENTS_SELECTION: ScalarField = {\n  kind: \"ScalarField\",\n  name: \"__fragments\",\n  alias: \"__fragments\",\n  type: \"String!\",\n  directives: [\n    {\n      kind: \"Directive\",\n      name: \"client\",\n      args: [],\n      loc: { kind: \"Generated\" },\n      metadata: undefined,\n    },\n  ],\n  args: [],\n  loc: { kind: \"Generated\" },\n  metadata: undefined,\n};\n\nconst FRAGMENTS_ON_NODE_SELECTION: InlineFragment = {\n  kind: \"InlineFragment\",\n  typeCondition: \"Node\",\n  selections: [FRAGMENTS_SELECTION],\n  directives: [],\n  loc: { kind: \"Generated\" },\n  metadata: undefined,\n};\n\n/**\n * Inserts a `__fragments` selection at the place where a fragment reference\n * boundary exists. This is either done in a `Node` inline fragment or directly\n * on the `Query` type.\n *\n * This field, which is an Apollo Client client-side field as declared with the\n * `@client` directive, will be used to pass context between the `use*Fragment`\n * hooks. (Currently this is limited to request variables.) The data for this\n * field is resolved by the `fragmentReferencesFieldPolicy` function.\n */\nexport const annotateFragmentReferenceTransform: IRTransform = (context) => {\n  const visitor = visitNodeWithSelections.bind(null, context);\n  let nextContext = context;\n\n  context.forEachDocument((document) => {\n    const nextDocument = visit(document, {\n      Root: visitor,\n      Fragment: visitor,\n      InlineFragment: visitor,\n      LinkedField: visitor,\n    });\n    nextContext = nextContext.replace(nextDocument);\n  });\n\n  return nextContext;\n};\n\nfunction visitNodeWithSelections(\n  context: CompilerContext,\n  node: Root | Fragment | InlineFragment | LinkedField\n): Root | Fragment | InlineFragment | LinkedField | undefined {\n  for (const selection of node.selections) {\n    if (selection.kind === \"FragmentSpread\") {\n      const fragment = context.getFragment(selection.name);\n      if (implementsNodeInterface(context, fragment)) {\n        return {\n          ...node,\n          selections: [...node.selections, FRAGMENTS_ON_NODE_SELECTION],\n        };\n      } else if (fragment.type === context.getSchema().getQueryType()) {\n        return {\n          ...node,\n          selections: [...node.selections, FRAGMENTS_SELECTION],\n        };\n      }\n    }\n  }\n}\n"],
  "mappings": ";AASA,SAAS,aAAa;AACtB,SAAS,+BAA+B;AAExC,IAAM,sBAAmC;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM,CAAC;AAAA,MACP,KAAK,EAAE,MAAM,YAAY;AAAA,MACzB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,MAAM,CAAC;AAAA,EACP,KAAK,EAAE,MAAM,YAAY;AAAA,EACzB,UAAU;AACZ;AAEA,IAAM,8BAA8C;AAAA,EAClD,MAAM;AAAA,EACN,eAAe;AAAA,EACf,YAAY,CAAC,mBAAmB;AAAA,EAChC,YAAY,CAAC;AAAA,EACb,KAAK,EAAE,MAAM,YAAY;AAAA,EACzB,UAAU;AACZ;AAYO,IAAM,qCAAkD,CAAC,YAAY;AAC1E,QAAM,UAAU,wBAAwB,KAAK,MAAM,OAAO;AAC1D,MAAI,cAAc;AAElB,UAAQ,gBAAgB,CAAC,aAAa;AACpC,UAAM,eAAe,MAAM,UAAU;AAAA,MACnC,MAAM;AAAA,MACN,UAAU;AAAA,MACV,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf,CAAC;AACD,kBAAc,YAAY,QAAQ,YAAY;AAAA,EAChD,CAAC;AAED,SAAO;AACT;AAEA,SAAS,wBACP,SACA,MAC4D;AAC5D,aAAW,aAAa,KAAK,YAAY;AACvC,QAAI,UAAU,SAAS,kBAAkB;AACvC,YAAM,WAAW,QAAQ,YAAY,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