{
  "version": 3,
  "sources": ["../../src/storeObservation/nodeFromCacheFieldPolicy.ts"],
  "sourcesContent": ["import { FieldReadFunction } from \"@apollo/client\";\nimport { FragmentSpreadNode, FragmentDefinitionNode } from \"graphql\";\nimport invariant from \"invariant\";\n\n/**\n * Use this as the field policy function for the node root field, which is what\n * gets invoked when using relay-compiler's refetch query. Queries that use a\n * cache-only cache-policy will read the data from the store, which is expected\n * to be populated by a different query beforehand.\n *\n * This specific version is for when you're using Apollo Client's default\n * configuration, which prefixes the `id` value with the typename for its store\n * keys.\n */\nexport const nodeFromCacheFieldPolicyWithDefaultApolloClientStoreKeys: FieldReadFunction =\n  (_existingCacheData, options) => {\n    const nodeId = options.args?.id;\n    invariant(nodeId, \"Expected an `id` argument\");\n\n    const fragmentNames = (\n      options.field?.selectionSet?.selections.filter(\n        (sel) => sel.kind === \"FragmentSpread\",\n      ) as FragmentSpreadNode[]\n    ).map((fragmentSpreadNode) => fragmentSpreadNode.name.value);\n    invariant(\n      fragmentNames.length === 1,\n      \"Expected a single fragment spread in the watch node query, instead got `%s`\",\n      fragmentNames.length,\n    );\n    const fragmentName = fragmentNames[0];\n\n    const fragment = options.query.definitions.find(\n      (defNode) =>\n        defNode.kind === \"FragmentDefinition\" &&\n        defNode.name.value === fragmentName,\n    ) as FragmentDefinitionNode;\n    invariant(\n      fragment,\n      \"Expected document to contain a fragment by name `%s`\",\n      fragmentName,\n    );\n\n    return options.toReference({\n      __typename: fragment.typeCondition.name.value,\n      id: nodeId,\n    });\n  };\n\n/**\n * Use this as the field policy function for the node root field, which is what\n * gets invoked when using relay-compiler's refetch query. Queries that use a\n * cache-only cache-policy will read the data from the store, which is expected\n * to be populated by a different query beforehand.\n *\n * This specific version is for when your Apollo Client instance is configured\n * to strictly follow the Global Object Identification and there's no need for\n * Apollo Client to prefix the `id` value with the typename for its store keys.\n *\n * @example\n * \n  ```ts\n  new InMemoryCache({\n    dataIdFromObject(responseObject) {\n      return (\n        responseObject.id?.toString() ||\n        defaultDataIdFromObject(responseObject)\n      );\n    }\n  })\n  ```\n * \n * @see {https://www.apollographql.com/docs/react/caching/cache-configuration/}\n */\nexport const nodeFromCacheFieldPolicyWithGlobalObjectIdStoreKeys: FieldReadFunction =\n  (_existingCacheData, options) => {\n    const nodeId = options.args?.id?.toString();\n    invariant(nodeId, \"Expected an `id` argument\");\n    return options.toReference(nodeId);\n  };\n"],
  "mappings": ";AAEA,OAAO,eAAe;AAYf,IAAM,2DACX,CAAC,oBAAoB,YAAY;AAfnC;AAgBI,QAAM,UAAS,aAAQ,SAAR,mBAAc;AAC7B,YAAU,QAAQ,2BAA2B;AAE7C,QAAM,kBACJ,mBAAQ,UAAR,mBAAe,iBAAf,mBAA6B,WAAW;AAAA,IACtC,CAAC,QAAQ,IAAI,SAAS;AAAA,KAExB,IAAI,CAAC,uBAAuB,mBAAmB,KAAK,KAAK;AAC3D;AAAA,IACE,cAAc,WAAW;AAAA,IACzB;AAAA,IACA,cAAc;AAAA,EAChB;AACA,QAAM,eAAe,cAAc,CAAC;AAEpC,QAAM,WAAW,QAAQ,MAAM,YAAY;AAAA,IACzC,CAAC,YACC,QAAQ,SAAS,wBACjB,QAAQ,KAAK,UAAU;AAAA,EAC3B;AACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,QAAQ,YAAY;AAAA,IACzB,YAAY,SAAS,cAAc,KAAK;AAAA,IACxC,IAAI;AAAA,EACN,CAAC;AACH;AA2BK,IAAM,sDACX,CAAC,oBAAoB,YAAY;AA1EnC;AA2EI,QAAM,UAAS,mBAAQ,SAAR,mBAAc,OAAd,mBAAkB;AACjC,YAAU,QAAQ,2BAA2B;AAC7C,SAAO,QAAQ,YAAY,MAAM;AACnC;",
  "names": []
}
