{
  "version": 3,
  "sources": ["../../src/compilerTransforms/enableNodeWatchQueryTransform.ts"],
  "sourcesContent": ["import { Directive, Fragment } from \"relay-compiler\";\nimport { IRTransform } from \"relay-compiler/lib/core/CompilerContext\";\nimport { implementsNodeInterface } from \"./utils\";\n\n/**\n * Uses relay-compiler's `@refetchable` directive to emit a query operation for\n * a single fragment (on the `Node` interface or `Query` type). This operation\n * is used by the `use*Fragment` hooks to observe the Apollo Client store for\n * changes to _just_ that data selected in the fragment.\n */\nexport const enableNodeWatchQueryTransform: IRTransform = (context) => {\n  let nextContext = context;\n\n  context.forEachDocument((document) => {\n    if (\n      document.kind === \"Fragment\" &&\n      (document.type === context.getSchema().getQueryType() ||\n        implementsNodeInterface(context, document))\n    ) {\n      nextContext = nextContext.replace({\n        ...document,\n        directives: [\n          ...document.directives,\n          emitRefetchableDirective(document),\n        ],\n      });\n    }\n  });\n\n  return nextContext;\n};\n\nfunction emitRefetchableDirective(fragmentDefinition: Fragment): Directive {\n  const fragmentName = fragmentDefinition.name;\n  const fragmentBaseName = fragmentName.replace(/Fragment$/, \"\");\n  return {\n    kind: \"Directive\",\n    name: \"refetchable\",\n    args: [\n      {\n        kind: \"Argument\",\n        name: \"queryName\",\n        value: {\n          kind: \"Literal\",\n          value: `${fragmentBaseName}WatchNodeQuery`,\n          loc: { kind: \"Generated\" },\n        },\n        loc: { kind: \"Generated\" },\n        metadata: undefined,\n      },\n    ],\n    loc: { kind: \"Generated\" },\n    metadata: undefined,\n  };\n}\n"],
  "mappings": ";AAEA,SAAS,+BAA+B;AAQjC,IAAM,gCAA6C,CAAC,YAAY;AACrE,MAAI,cAAc;AAElB,UAAQ,gBAAgB,CAAC,aAAa;AACpC,QACE,SAAS,SAAS,eACjB,SAAS,SAAS,QAAQ,UAAU,EAAE,aAAa,KAClD,wBAAwB,SAAS,QAAQ,IAC3C;AACA,oBAAc,YAAY,QAAQ;AAAA,QAChC,GAAG;AAAA,QACH,YAAY;AAAA,UACV,GAAG,SAAS;AAAA,UACZ,yBAAyB,QAAQ;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,SAAS,yBAAyB,oBAAyC;AACzE,QAAM,eAAe,mBAAmB;AACxC,QAAM,mBAAmB,aAAa,QAAQ,aAAa,EAAE;AAC7D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,MACJ;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,UACL,MAAM;AAAA,UACN,OAAO,GAAG;AAAA,UACV,KAAK,EAAE,MAAM,YAAY;AAAA,QAC3B;AAAA,QACA,KAAK,EAAE,MAAM,YAAY;AAAA,QACzB,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,KAAK,EAAE,MAAM,YAAY;AAAA,IACzB,UAAU;AAAA,EACZ;AACF;",
  "names": []
}
