@graphitation/apollo-react-relay-duct-tape 1.3.23 → 1.4.0
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.
- package/.eslintcache +1 -1
- package/CHANGELOG.md +22 -2
- package/lib/hooks.js +14 -48
- package/lib/hooks.js.map +1 -1
- package/lib/hooks.mjs +14 -51
- package/lib/hooks.mjs.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledFragment.js +3 -19
- package/lib/storeObservation/compiledHooks/useCompiledFragment.js.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledFragment.mjs +3 -22
- package/lib/storeObservation/compiledHooks/useCompiledFragment.mjs.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.js +20 -32
- package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.js.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.mjs +20 -35
- package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.mjs.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.js +9 -33
- package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.js.map +1 -1
- package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.mjs +9 -36
- package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.mjs.map +1 -1
- package/package.json +5 -5
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx":"1","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/useOverridenOrDefaultApolloClient.test.tsx":"2","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/convertFetchPolicy.ts":"3","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/hooks.ts":"4","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/index.ts":"5","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/compiledHooks.test.tsx":"6","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/fragmentReferencesFieldPolicy.test.ts":"7","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/getPossibleTypesAndDataIdFromNode.test.ts":"8","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/nodeFromCacheFieldPolicy.test.ts":"9","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/index.ts":"10","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/types.ts":"11","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledFragment.ts":"12","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledLazyLoadQuery.ts":"13","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts":"14","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts":"15","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useDeepCompareMemoize.ts":"16","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useForceUpdate.ts":"17","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/fragmentReferencesFieldPolicy.ts":"18","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/getPossibleTypesAndDataIdFromNode.ts":"19","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/index.ts":"20","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/nodeFromCacheFieldPolicy.ts":"21","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/shallowCompareFragmentReferences.ts":"22","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/typePolicies.ts":"23","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/types.ts":"24","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/useOverridenOrDefaultApolloClient.ts":"25"},{"size":11649,"mtime":1743088470745,"results":"26","hashOfConfig":"27"},{"size":1922,"mtime":1743088470746,"results":"28","hashOfConfig":"27"},{"size":690,"mtime":1743088470746,"results":"29","hashOfConfig":"27"},{"size":12373,"mtime":1743088470746,"results":"30","hashOfConfig":"27"},{"size":174,"mtime":1743088470746,"results":"31","hashOfConfig":"27"},{"size":45749,"mtime":1743088470747,"results":"32","hashOfConfig":"27"},{"size":1839,"mtime":1743088470747,"results":"33","hashOfConfig":"27"},{"size":1709,"mtime":1743088470747,"results":"34","hashOfConfig":"27"},{"size":3041,"mtime":1743088470747,"results":"35","hashOfConfig":"27"},{"size":445,"mtime":1743088470747,"results":"36","hashOfConfig":"27"},{"size":575,"mtime":1743088470747,"results":"37","hashOfConfig":"27"},{"size":3668,"mtime":1743088470747,"results":"38","hashOfConfig":"27"},{"size":4126,"mtime":1743088470747,"results":"39","hashOfConfig":"27"},{"size":10521,"mtime":1743088470747,"results":"40","hashOfConfig":"27"},{"size":5467,"mtime":1743088470747,"results":"41","hashOfConfig":"27"},{"size":843,"mtime":1743088470748,"results":"42","hashOfConfig":"27"},{"size":152,"mtime":1743088470748,"results":"43","hashOfConfig":"27"},{"size":286,"mtime":1743088470748,"results":"44","hashOfConfig":"27"},{"size":1243,"mtime":1743088470748,"results":"45","hashOfConfig":"27"},{"size":230,"mtime":1743088470748,"results":"46","hashOfConfig":"27"},{"size":2829,"mtime":1743088470748,"results":"47","hashOfConfig":"27"},{"size":2325,"mtime":1743088470748,"results":"48","hashOfConfig":"27"},{"size":1110,"mtime":1743088470748,"results":"49","hashOfConfig":"27"},{"size":2069,"mtime":1743088470748,"results":"50","hashOfConfig":"27"},{"size":1352,"mtime":1743088470748,"results":"51","hashOfConfig":"27"},{"filePath":"52","messages":"53","suppressedMessages":"54","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"obk99i",{"filePath":"55","messages":"56","suppressedMessages":"57","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","suppressedMessages":"60","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"61","messages":"62","suppressedMessages":"63","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","suppressedMessages":"66","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"67","messages":"68","suppressedMessages":"69","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","suppressedMessages":"72","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"73","messages":"74","suppressedMessages":"75","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"76","messages":"77","suppressedMessages":"78","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"79","messages":"80","suppressedMessages":"81","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"82","messages":"83","suppressedMessages":"84","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"85","messages":"86","suppressedMessages":"87","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"88","messages":"89","suppressedMessages":"90","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"91","messages":"92","suppressedMessages":"93","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"94","messages":"95","suppressedMessages":"96","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"97","messages":"98","suppressedMessages":"99","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"100","messages":"101","suppressedMessages":"102","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"103","messages":"104","suppressedMessages":"105","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"106","messages":"107","suppressedMessages":"108","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"109","messages":"110","suppressedMessages":"111","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"112","messages":"113","suppressedMessages":"114","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"115","messages":"116","suppressedMessages":"117","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"118","messages":"119","suppressedMessages":"120","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"121","messages":"122","suppressedMessages":"123","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"124","messages":"125","suppressedMessages":"126","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/useOverridenOrDefaultApolloClient.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/convertFetchPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/hooks.ts",[],["127"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/compiledHooks.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/fragmentReferencesFieldPolicy.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/getPossibleTypesAndDataIdFromNode.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/nodeFromCacheFieldPolicy.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/types.ts",[],["128"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledFragment.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledLazyLoadQuery.ts",[],["129"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts",[],["130","131","132","133","134"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts",[],["135"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useDeepCompareMemoize.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useForceUpdate.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/fragmentReferencesFieldPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/getPossibleTypesAndDataIdFromNode.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/nodeFromCacheFieldPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/shallowCompareFragmentReferences.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/typePolicies.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/types.ts",[],["136","137"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/useOverridenOrDefaultApolloClient.ts",[],["138"],{"ruleId":"139","severity":1,"message":"140","line":320,"column":38,"nodeType":"141","messageId":"142","endLine":320,"endColumn":41,"suggestions":"143","suppressions":"144"},{"ruleId":"139","severity":1,"message":"140","line":16,"column":32,"nodeType":"141","messageId":"142","endLine":16,"endColumn":35,"suggestions":"145","suppressions":"146"},{"ruleId":"139","severity":1,"message":"140","line":104,"column":28,"nodeType":"141","messageId":"142","endLine":104,"endColumn":31,"suggestions":"147","suppressions":"148"},{"ruleId":"139","severity":1,"message":"140","line":174,"column":24,"nodeType":"141","messageId":"142","endLine":174,"endColumn":27,"suggestions":"149","suppressions":"150"},{"ruleId":"139","severity":1,"message":"140","line":177,"column":4,"nodeType":"141","messageId":"142","endLine":177,"endColumn":7,"suggestions":"151","suppressions":"152"},{"ruleId":"139","severity":1,"message":"140","line":179,"column":30,"nodeType":"141","messageId":"142","endLine":179,"endColumn":33,"suggestions":"153","suppressions":"154"},{"ruleId":"139","severity":1,"message":"140","line":189,"column":24,"nodeType":"141","messageId":"142","endLine":189,"endColumn":27,"suggestions":"155","suppressions":"156"},{"ruleId":"139","severity":1,"message":"140","line":225,"column":9,"nodeType":"141","messageId":"142","endLine":225,"endColumn":12,"suggestions":"157","suppressions":"158"},{"ruleId":"139","severity":1,"message":"140","line":38,"column":26,"nodeType":"141","messageId":"142","endLine":38,"endColumn":29,"suggestions":"159","suppressions":"160"},{"ruleId":"139","severity":1,"message":"140","line":5,"column":19,"nodeType":"141","messageId":"142","endLine":5,"endColumn":22,"suggestions":"161","suppressions":"162"},{"ruleId":"139","severity":1,"message":"140","line":10,"column":19,"nodeType":"141","messageId":"142","endLine":10,"endColumn":22,"suggestions":"163","suppressions":"164"},{"ruleId":"139","severity":1,"message":"140","line":17,"column":51,"nodeType":"141","messageId":"142","endLine":17,"endColumn":54,"suggestions":"165","suppressions":"166"},"@typescript-eslint/no-explicit-any","Unexpected any. Specify a different type.","TSAnyKeyword","unexpectedAny",["167","168"],["169"],["170","171"],["172"],["173","174"],["175"],["176","177"],["178"],["179","180"],["181"],["182","183"],["184"],["185","186"],["187"],["188","189"],["190"],["191","192"],["193"],["194","195"],["196"],["197","198"],["199"],["200","201"],["202"],{"messageId":"203","fix":"204","desc":"205"},{"messageId":"206","fix":"207","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"211","desc":"205"},{"messageId":"206","fix":"212","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"213","desc":"205"},{"messageId":"206","fix":"214","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"215","desc":"205"},{"messageId":"206","fix":"216","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"217","desc":"205"},{"messageId":"206","fix":"218","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"219","desc":"205"},{"messageId":"206","fix":"220","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"221","desc":"205"},{"messageId":"206","fix":"222","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"223","desc":"205"},{"messageId":"206","fix":"224","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"225","desc":"205"},{"messageId":"206","fix":"226","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"227","desc":"205"},{"messageId":"206","fix":"228","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"229","desc":"205"},{"messageId":"206","fix":"230","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"231","desc":"205"},{"messageId":"206","fix":"232","desc":"208"},{"kind":"209","justification":"210"},"suggestUnknown",{"range":"233","text":"234"},"Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.","suggestNever",{"range":"233","text":"235"},"Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.","directive","",{"range":"236","text":"234"},{"range":"236","text":"235"},{"range":"237","text":"234"},{"range":"237","text":"235"},{"range":"238","text":"234"},{"range":"238","text":"235"},{"range":"239","text":"234"},{"range":"239","text":"235"},{"range":"240","text":"234"},{"range":"240","text":"235"},{"range":"241","text":"234"},{"range":"241","text":"235"},{"range":"242","text":"234"},{"range":"242","text":"235"},{"range":"243","text":"234"},{"range":"243","text":"235"},{"range":"244","text":"234"},{"range":"244","text":"235"},{"range":"245","text":"234"},{"range":"245","text":"235"},{"range":"246","text":"234"},{"range":"246","text":"235"},[11748,11751],"unknown","never",[567,570],[3065,3068],[5868,5871],[5969,5972],[6069,6072],[6358,6361],[7422,7425],[1283,1286],[158,161],[276,279],[460,463]]
|
|
1
|
+
[{"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx":"1","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/useOverridenOrDefaultApolloClient.test.tsx":"2","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/convertFetchPolicy.ts":"3","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/hooks.ts":"4","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/index.ts":"5","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/compiledHooks.test.tsx":"6","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/fragmentReferencesFieldPolicy.test.ts":"7","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/getPossibleTypesAndDataIdFromNode.test.ts":"8","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/nodeFromCacheFieldPolicy.test.ts":"9","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/index.ts":"10","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/types.ts":"11","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledFragment.ts":"12","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledLazyLoadQuery.ts":"13","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts":"14","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts":"15","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useDeepCompareMemoize.ts":"16","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useForceUpdate.ts":"17","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/fragmentReferencesFieldPolicy.ts":"18","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/getPossibleTypesAndDataIdFromNode.ts":"19","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/index.ts":"20","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/nodeFromCacheFieldPolicy.ts":"21","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/shallowCompareFragmentReferences.ts":"22","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/typePolicies.ts":"23","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/types.ts":"24","/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/useOverridenOrDefaultApolloClient.ts":"25"},{"size":11649,"mtime":1743593505136,"results":"26","hashOfConfig":"27"},{"size":1922,"mtime":1743593505136,"results":"28","hashOfConfig":"27"},{"size":690,"mtime":1743593505136,"results":"29","hashOfConfig":"27"},{"size":12373,"mtime":1743593505136,"results":"30","hashOfConfig":"27"},{"size":174,"mtime":1743593505136,"results":"31","hashOfConfig":"27"},{"size":45749,"mtime":1743593505137,"results":"32","hashOfConfig":"27"},{"size":1839,"mtime":1743593505137,"results":"33","hashOfConfig":"27"},{"size":1709,"mtime":1743593505137,"results":"34","hashOfConfig":"27"},{"size":3041,"mtime":1743593505137,"results":"35","hashOfConfig":"27"},{"size":445,"mtime":1743593505137,"results":"36","hashOfConfig":"27"},{"size":575,"mtime":1743593505137,"results":"37","hashOfConfig":"27"},{"size":3668,"mtime":1743593505137,"results":"38","hashOfConfig":"27"},{"size":4126,"mtime":1743593505137,"results":"39","hashOfConfig":"27"},{"size":10521,"mtime":1743593505137,"results":"40","hashOfConfig":"27"},{"size":5467,"mtime":1743593505137,"results":"41","hashOfConfig":"27"},{"size":843,"mtime":1743593505137,"results":"42","hashOfConfig":"27"},{"size":152,"mtime":1743593505137,"results":"43","hashOfConfig":"27"},{"size":286,"mtime":1743593505137,"results":"44","hashOfConfig":"27"},{"size":1243,"mtime":1743593505138,"results":"45","hashOfConfig":"27"},{"size":230,"mtime":1743593505138,"results":"46","hashOfConfig":"27"},{"size":2829,"mtime":1743593505138,"results":"47","hashOfConfig":"27"},{"size":2325,"mtime":1743593505138,"results":"48","hashOfConfig":"27"},{"size":1110,"mtime":1743593505138,"results":"49","hashOfConfig":"27"},{"size":2069,"mtime":1743593505138,"results":"50","hashOfConfig":"27"},{"size":1352,"mtime":1743593505138,"results":"51","hashOfConfig":"27"},{"filePath":"52","messages":"53","suppressedMessages":"54","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"obk99i",{"filePath":"55","messages":"56","suppressedMessages":"57","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","suppressedMessages":"60","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"61","messages":"62","suppressedMessages":"63","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","suppressedMessages":"66","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"67","messages":"68","suppressedMessages":"69","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","suppressedMessages":"72","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"73","messages":"74","suppressedMessages":"75","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"76","messages":"77","suppressedMessages":"78","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"79","messages":"80","suppressedMessages":"81","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"82","messages":"83","suppressedMessages":"84","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"85","messages":"86","suppressedMessages":"87","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"88","messages":"89","suppressedMessages":"90","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"91","messages":"92","suppressedMessages":"93","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"94","messages":"95","suppressedMessages":"96","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"97","messages":"98","suppressedMessages":"99","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"100","messages":"101","suppressedMessages":"102","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"103","messages":"104","suppressedMessages":"105","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"106","messages":"107","suppressedMessages":"108","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"109","messages":"110","suppressedMessages":"111","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"112","messages":"113","suppressedMessages":"114","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"115","messages":"116","suppressedMessages":"117","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"118","messages":"119","suppressedMessages":"120","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"121","messages":"122","suppressedMessages":"123","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"124","messages":"125","suppressedMessages":"126","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/__tests__/useOverridenOrDefaultApolloClient.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/convertFetchPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/hooks.ts",[],["127"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/compiledHooks.test.tsx",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/fragmentReferencesFieldPolicy.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/getPossibleTypesAndDataIdFromNode.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/__tests__/nodeFromCacheFieldPolicy.test.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/types.ts",[],["128"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledFragment.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledLazyLoadQuery.ts",[],["129"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts",[],["130","131","132","133","134"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts",[],["135"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useDeepCompareMemoize.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/compiledHooks/useForceUpdate.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/fragmentReferencesFieldPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/getPossibleTypesAndDataIdFromNode.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/index.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/nodeFromCacheFieldPolicy.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/shallowCompareFragmentReferences.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/storeObservation/typePolicies.ts",[],[],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/types.ts",[],["136","137"],"/mnt/vss/_work/1/s/packages/apollo-react-relay-duct-tape/src/useOverridenOrDefaultApolloClient.ts",[],["138"],{"ruleId":"139","severity":1,"message":"140","line":320,"column":38,"nodeType":"141","messageId":"142","endLine":320,"endColumn":41,"suggestions":"143","suppressions":"144"},{"ruleId":"139","severity":1,"message":"140","line":16,"column":32,"nodeType":"141","messageId":"142","endLine":16,"endColumn":35,"suggestions":"145","suppressions":"146"},{"ruleId":"139","severity":1,"message":"140","line":104,"column":28,"nodeType":"141","messageId":"142","endLine":104,"endColumn":31,"suggestions":"147","suppressions":"148"},{"ruleId":"139","severity":1,"message":"140","line":174,"column":24,"nodeType":"141","messageId":"142","endLine":174,"endColumn":27,"suggestions":"149","suppressions":"150"},{"ruleId":"139","severity":1,"message":"140","line":177,"column":4,"nodeType":"141","messageId":"142","endLine":177,"endColumn":7,"suggestions":"151","suppressions":"152"},{"ruleId":"139","severity":1,"message":"140","line":179,"column":30,"nodeType":"141","messageId":"142","endLine":179,"endColumn":33,"suggestions":"153","suppressions":"154"},{"ruleId":"139","severity":1,"message":"140","line":189,"column":24,"nodeType":"141","messageId":"142","endLine":189,"endColumn":27,"suggestions":"155","suppressions":"156"},{"ruleId":"139","severity":1,"message":"140","line":225,"column":9,"nodeType":"141","messageId":"142","endLine":225,"endColumn":12,"suggestions":"157","suppressions":"158"},{"ruleId":"139","severity":1,"message":"140","line":38,"column":26,"nodeType":"141","messageId":"142","endLine":38,"endColumn":29,"suggestions":"159","suppressions":"160"},{"ruleId":"139","severity":1,"message":"140","line":5,"column":19,"nodeType":"141","messageId":"142","endLine":5,"endColumn":22,"suggestions":"161","suppressions":"162"},{"ruleId":"139","severity":1,"message":"140","line":10,"column":19,"nodeType":"141","messageId":"142","endLine":10,"endColumn":22,"suggestions":"163","suppressions":"164"},{"ruleId":"139","severity":1,"message":"140","line":17,"column":51,"nodeType":"141","messageId":"142","endLine":17,"endColumn":54,"suggestions":"165","suppressions":"166"},"@typescript-eslint/no-explicit-any","Unexpected any. Specify a different type.","TSAnyKeyword","unexpectedAny",["167","168"],["169"],["170","171"],["172"],["173","174"],["175"],["176","177"],["178"],["179","180"],["181"],["182","183"],["184"],["185","186"],["187"],["188","189"],["190"],["191","192"],["193"],["194","195"],["196"],["197","198"],["199"],["200","201"],["202"],{"messageId":"203","fix":"204","desc":"205"},{"messageId":"206","fix":"207","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"211","desc":"205"},{"messageId":"206","fix":"212","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"213","desc":"205"},{"messageId":"206","fix":"214","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"215","desc":"205"},{"messageId":"206","fix":"216","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"217","desc":"205"},{"messageId":"206","fix":"218","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"219","desc":"205"},{"messageId":"206","fix":"220","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"221","desc":"205"},{"messageId":"206","fix":"222","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"223","desc":"205"},{"messageId":"206","fix":"224","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"225","desc":"205"},{"messageId":"206","fix":"226","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"227","desc":"205"},{"messageId":"206","fix":"228","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"229","desc":"205"},{"messageId":"206","fix":"230","desc":"208"},{"kind":"209","justification":"210"},{"messageId":"203","fix":"231","desc":"205"},{"messageId":"206","fix":"232","desc":"208"},{"kind":"209","justification":"210"},"suggestUnknown",{"range":"233","text":"234"},"Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.","suggestNever",{"range":"233","text":"235"},"Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.","directive","",{"range":"236","text":"234"},{"range":"236","text":"235"},{"range":"237","text":"234"},{"range":"237","text":"235"},{"range":"238","text":"234"},{"range":"238","text":"235"},{"range":"239","text":"234"},{"range":"239","text":"235"},{"range":"240","text":"234"},{"range":"240","text":"235"},{"range":"241","text":"234"},{"range":"241","text":"235"},{"range":"242","text":"234"},{"range":"242","text":"235"},{"range":"243","text":"234"},{"range":"243","text":"235"},{"range":"244","text":"234"},{"range":"244","text":"235"},{"range":"245","text":"234"},{"range":"245","text":"235"},{"range":"246","text":"234"},{"range":"246","text":"235"},[11748,11751],"unknown","never",[567,570],[3065,3068],[5868,5871],[5969,5972],[6069,6072],[6358,6361],[7422,7425],[1283,1286],[158,161],[276,279],[460,463]]
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
# Change Log - @graphitation/apollo-react-relay-duct-tape
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Wed, 02 Apr 2025 11:41:54 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.4.0
|
|
8
|
+
|
|
9
|
+
Wed, 02 Apr 2025 11:41:54 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Changed build target from ES6 to ES2018 (vrazuvaev@microsoft.com_msteamsmdb)
|
|
14
|
+
- Bump @graphitation/apollo-mock-client to v0.12.0
|
|
15
|
+
- Bump @graphitation/graphql-js-operation-payload-generator to v0.13.0
|
|
16
|
+
- Bump @graphitation/graphql-js-tag to v0.10.0
|
|
17
|
+
- Bump @graphitation/apollo-react-relay-duct-tape-compiler to v1.7.0
|
|
18
|
+
|
|
19
|
+
## 1.3.24
|
|
20
|
+
|
|
21
|
+
Fri, 28 Mar 2025 09:57:05 GMT
|
|
22
|
+
|
|
23
|
+
### Patches
|
|
24
|
+
|
|
25
|
+
- Bump @graphitation/apollo-react-relay-duct-tape-compiler to v1.6.20
|
|
26
|
+
|
|
7
27
|
## 1.3.23
|
|
8
28
|
|
|
9
|
-
Thu, 27 Mar 2025
|
|
29
|
+
Thu, 27 Mar 2025 16:19:03 GMT
|
|
10
30
|
|
|
11
31
|
### Patches
|
|
12
32
|
|
package/lib/hooks.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
8
|
var __export = (target, all) => {
|
|
26
9
|
for (var name in all)
|
|
27
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,26 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
26
|
mod
|
|
44
27
|
));
|
|
45
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __async = (__this, __arguments, generator) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
var fulfilled = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
step(generator.next(value));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var rejected = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.throw(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
29
|
var hooks_exports = {};
|
|
67
30
|
__export(hooks_exports, {
|
|
68
31
|
useFragment: () => useFragment,
|
|
@@ -83,23 +46,26 @@ function useLazyLoadQuery(query, variables, options) {
|
|
|
83
46
|
(query == null ? void 0 : query.__brand) === void 0,
|
|
84
47
|
"useLazyLoadQuery: Document must be a valid runtime type."
|
|
85
48
|
);
|
|
86
|
-
const apolloOptions = options &&
|
|
49
|
+
const apolloOptions = options && {
|
|
50
|
+
...options,
|
|
87
51
|
fetchPolicy: (0, import_convertFetchPolicy.convertFetchPolicy)(options.fetchPolicy)
|
|
88
|
-
}
|
|
52
|
+
};
|
|
89
53
|
if (query.watchQueryDocument) {
|
|
90
|
-
return (0, import_compiledHooks.useCompiledLazyLoadQuery)(query,
|
|
91
|
-
variables
|
|
92
|
-
|
|
54
|
+
return (0, import_compiledHooks.useCompiledLazyLoadQuery)(query, {
|
|
55
|
+
variables,
|
|
56
|
+
...apolloOptions
|
|
57
|
+
});
|
|
93
58
|
} else {
|
|
94
59
|
const client = (0, import_useOverridenOrDefaultApolloClient.useOverridenOrDefaultApolloClient)();
|
|
95
60
|
return (0, import_client.useQuery)(
|
|
96
61
|
// Compiled documents without narrow observables should be treated like
|
|
97
62
|
// normal queries.
|
|
98
63
|
query.executionQueryDocument || query,
|
|
99
|
-
|
|
64
|
+
{
|
|
100
65
|
client,
|
|
101
|
-
variables
|
|
102
|
-
|
|
66
|
+
variables,
|
|
67
|
+
...apolloOptions
|
|
68
|
+
}
|
|
103
69
|
);
|
|
104
70
|
}
|
|
105
71
|
}
|
|
@@ -205,8 +171,8 @@ function useMutation(mutation) {
|
|
|
205
171
|
{ client }
|
|
206
172
|
);
|
|
207
173
|
return [
|
|
208
|
-
(options) =>
|
|
209
|
-
const apolloResult =
|
|
174
|
+
async (options) => {
|
|
175
|
+
const apolloResult = await apolloUpdater({
|
|
210
176
|
variables: options.variables || {},
|
|
211
177
|
context: options.context,
|
|
212
178
|
optimisticResponse: options.optimisticResponse,
|
|
@@ -222,7 +188,7 @@ function useMutation(mutation) {
|
|
|
222
188
|
return {
|
|
223
189
|
data: apolloResult.data
|
|
224
190
|
};
|
|
225
|
-
}
|
|
191
|
+
},
|
|
226
192
|
mutationLoading
|
|
227
193
|
];
|
|
228
194
|
}
|
package/lib/hooks.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/hooks.ts"],
|
|
4
4
|
"sourcesContent": ["import invariant from \"invariant\";\nimport {\n useSubscription as useApolloSubscription,\n useQuery as useApolloQuery,\n useMutation as useApolloMutation,\n SubscriptionHookOptions as ApolloSubscriptionHookOptions,\n ErrorPolicy as ApolloErrorPolicy,\n ApolloClient,\n ApolloCache,\n} from \"@apollo/client\";\n\nimport {\n FetchPolicy,\n GraphQLTaggedNode,\n KeyType,\n KeyTypeData,\n OperationType,\n} from \"./types\";\nimport {\n RefetchFn,\n PaginationFn,\n useCompiledLazyLoadQuery,\n useCompiledFragment,\n useCompiledRefetchableFragment,\n useCompiledPaginationFragment,\n} from \"./storeObservation/compiledHooks\";\nimport { convertFetchPolicy } from \"./convertFetchPolicy\";\nimport { useOverridenOrDefaultApolloClient } from \"./useOverridenOrDefaultApolloClient\";\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport { FragmentReference } from \"./storeObservation/compiledHooks/types\";\n\n/**\n * Executes a GraphQL query.\n *\n * This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple\n * round trips, one for loading and one for resolving.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-lazy-load-query}\n *\n * @param query The query operation to perform.\n * @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL\n * variables declared inside the query.\n * @param options Options passed on to the underlying implementation.\n * @param options.context The query context to pass along the apollo link chain. Should be avoided when possible as\n * it will not be compatible with Relay APIs.\n * @returns An object with either an error, the result data, or neither while loading.\n */\nexport function useLazyLoadQuery<TQuery extends OperationType>(\n query: GraphQLTaggedNode,\n variables: TQuery[\"variables\"],\n options?: { fetchPolicy?: FetchPolicy; context?: TQuery[\"context\"] },\n): { error?: Error; data?: TQuery[\"response\"] } {\n invariant(\n query?.__brand === undefined,\n \"useLazyLoadQuery: Document must be a valid runtime type.\",\n );\n const apolloOptions = options && {\n ...options,\n fetchPolicy: convertFetchPolicy(options.fetchPolicy),\n };\n if (query.watchQueryDocument) {\n return useCompiledLazyLoadQuery(query as CompiledArtefactModule, {\n variables,\n ...apolloOptions,\n });\n } else {\n const client = useOverridenOrDefaultApolloClient();\n return useApolloQuery(\n // Compiled documents without narrow observables should be treated like\n // normal queries.\n query.executionQueryDocument || query,\n {\n client,\n variables,\n ...apolloOptions,\n },\n );\n }\n}\n\n/**\n * A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment\n * should select all the fields that the component directly uses in its rendering or needs to pass to external\n * functions. It should *not* select data that its children need, unless those children are intended to remain their\n * pure React props as data inputs.\n *\n * For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to\n * spread in the child's fragment.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-fragment}\n *\n * @note For migration purposes, this hook supports the notion that the fragment reference can be undefined. This is\n * to support cases where useFragment is used in a tree that is conditionally using fragments.\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections.\n */\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): KeyTypeData<TKey>;\nexport function useFragment(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: undefined,\n): undefined;\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey | undefined,\n): KeyTypeData<TKey> | undefined;\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode | undefined,\n fragmentRef: TKey,\n): KeyTypeData<TKey> {\n invariant(\n fragmentInput?.__brand === undefined,\n \"useFragment: fragmentInput must be a valid runtime type.\",\n );\n // If fragmentInput is undefined, it means the fragment is not compiled and we should just return the fragmentRef.\n // This is an implementation detail that should never surface to the user.\n if (fragmentInput && fragmentInput.watchQueryDocument) {\n return useCompiledFragment(fragmentInput, fragmentRef as FragmentReference);\n } else {\n return fragmentRef as unknown;\n }\n}\n\n/**\n * Equivalent to `useFragment`, but allows refetching of its subtree of the overall query.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-refetchable-fragment}\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections and a function to perform the refetch.\n */\nexport function useRefetchableFragment<\n TQuery extends OperationType,\n TKey extends KeyType,\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): [data: KeyTypeData<TKey>, refetch: RefetchFn<TQuery[\"variables\"]>] {\n invariant(\n fragmentInput,\n \"useRefetchableFragment: Missing metadata; did you forget to use the @refetchable directive?\",\n );\n invariant(\n fragmentInput.__brand === undefined,\n \"useRefetchableFragment: fragmentInput must be a valid runtime type.\",\n );\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"useRefetchableFragment is only supported at this time when using compilation\",\n );\n return useCompiledRefetchableFragment(\n fragmentInput as CompiledArtefactModule,\n fragmentRef as FragmentReference,\n );\n}\n\n/**\n * Equivalent to `useFragment`, but allows pagination of its subtree of the overall query.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-pagination-fragment}\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections and functions to deal with pagination.\n */\nexport function usePaginationFragment<\n TQuery extends OperationType,\n TKey extends KeyType,\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): {\n data: KeyTypeData<TKey>;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn<TQuery[\"variables\"]>;\n} {\n invariant(\n fragmentInput,\n \"usePaginationFragment: Missing metadata; did you forget to use the @refetchable directive?\",\n );\n invariant(\n fragmentInput.__brand === undefined,\n \"usePaginationFragment: fragmentInput must be a valid runtime type.\",\n );\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"usePaginationFragment is only supported at this time when using compilation\",\n );\n return useCompiledPaginationFragment(\n fragmentInput as CompiledArtefactModule,\n fragmentRef as FragmentReference,\n );\n}\n\n// https://github.com/facebook/relay/blob/master/website/docs/api-reference/types/GraphQLSubscriptionConfig.md\ninterface GraphQLSubscriptionConfig<\n TSubscriptionPayload extends OperationType,\n> {\n subscription: GraphQLTaggedNode;\n variables: TSubscriptionPayload[\"variables\"];\n /**\n * Should be avoided when possible as it will not be compatible with Relay APIs.\n */\n context?: TSubscriptionPayload[\"context\"];\n /**\n * Should response be nullable?\n */\n onNext?: (response: TSubscriptionPayload[\"response\"]) => void;\n onError?: (error: Error) => void;\n}\n\n/**\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-subscription}\n *\n * @param config\n */\nexport function useSubscription<TSubscriptionPayload extends OperationType>(\n config: GraphQLSubscriptionConfig<TSubscriptionPayload>,\n): void {\n const document = config.subscription;\n invariant(\n document?.__brand === undefined,\n \"useSubscription: Document must be a valid runtime type.\",\n );\n invariant(\n !document.watchQueryDocument,\n \"useSubscription: Did not expect a watch query document\",\n );\n const client = useOverridenOrDefaultApolloClient();\n const { error } = useApolloSubscription(\n document.executionQueryDocument || document,\n {\n client,\n variables: config.variables,\n context: config.context,\n onSubscriptionData: ({ subscriptionData }) => {\n // Supposedly this never gets triggered for an error by design:\n // https://github.com/apollographql/react-apollo/issues/3177#issuecomment-506758144\n invariant(\n !subscriptionData.error,\n \"Did not expect to receive an error here\",\n );\n if (subscriptionData.data && config.onNext) {\n config.onNext(subscriptionData.data);\n }\n },\n errorPolicy: \"ignore\",\n } as ApolloSubscriptionHookOptions & {\n errorPolicy: ApolloErrorPolicy;\n },\n );\n if (error) {\n if (config.onError) {\n config.onError(error);\n } else {\n console.warn(\n `An unhandled GraphQL subscription error occurred: ${error.message}`,\n );\n }\n }\n}\n\ninterface IMutationCommitterOptions<TMutationPayload extends OperationType> {\n variables: TMutationPayload[\"variables\"];\n optimisticResponse?: Partial<TMutationPayload[\"response\"]> | null;\n onCompleted?: (response: TMutationPayload[\"response\"]) => void;\n /**\n * This version yields the ApolloCache instance, instead of the RelayStore,\n * and usage of it will not be portable to Relay directly. However, it is a\n * necessary evil for migration purposes.\n */\n updater?: (\n cache: ApolloCache<unknown>,\n data: TMutationPayload[\"response\"],\n ) => void;\n /**\n * @deprecated Should be avoided when possible as it will not be compatible with Relay APIs.\n */\n context?: TMutationPayload[\"context\"];\n}\n\ntype MutationCommiter<TMutationPayload extends OperationType> = (\n options: IMutationCommitterOptions<TMutationPayload>,\n) => Promise<{ errors?: Error[]; data?: TMutationPayload[\"response\"] }>;\n\n/**\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-mutation}\n *\n * @param mutation\n * @returns\n */\nexport function useMutation<TMutationPayload extends OperationType>(\n mutation: GraphQLTaggedNode,\n): [MutationCommiter<TMutationPayload>, boolean] {\n invariant(\n mutation?.__brand === undefined,\n \"useMutation: Document must be a valid runtime type.\",\n );\n invariant(\n !mutation.watchQueryDocument,\n \"useMutation: Did not expect a watch query document\",\n );\n const client = useOverridenOrDefaultApolloClient();\n const [apolloUpdater, { loading: mutationLoading }] = useApolloMutation(\n mutation.executionQueryDocument || mutation,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n { client: client as ApolloClient<any> },\n );\n\n return [\n async (options: IMutationCommitterOptions<TMutationPayload>) => {\n const apolloResult = await apolloUpdater({\n variables: options.variables || {},\n context: options.context,\n optimisticResponse: options.optimisticResponse,\n onCompleted: options.onCompleted,\n update: options.updater,\n });\n if (apolloResult.errors) {\n return {\n errors: Array.from(Object.values(apolloResult.errors)),\n data: apolloResult.data,\n };\n }\n return {\n data: apolloResult.data,\n };\n },\n mutationLoading,\n ];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,oBAQO;AASP,2BAOO;AACP,gCAAmC;AACnC,+CAAkD;AAoB3C,SAAS,iBACd,OACA,WACA,SAC8C;AAC9C,uBAAAA;AAAA,KACE,+BAAO,aAAY;AAAA,IACnB;AAAA,EACF;AACA,QAAM,gBAAgB,WAAW;AAAA,IAC/B,GAAG;AAAA,IACH,iBAAa,8CAAmB,QAAQ,WAAW;AAAA,EACrD;AACA,MAAI,MAAM,oBAAoB;AAC5B,eAAO,+CAAyB,OAAiC;AAAA,MAC/D;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AAAA,EACH,OAAO;AACL,UAAM,aAAS,4EAAkC;AACjD,eAAO,cAAAC;AAAA;AAAA;AAAA,MAGL,MAAM,0BAA0B;AAAA,MAChC;AAAA,QACE;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AACF;AAiCO,SAAS,YACd,eACA,aACmB;AACnB,uBAAAD;AAAA,KACE,+CAAe,aAAY;AAAA,IAC3B;AAAA,EACF;AAGA,MAAI,iBAAiB,cAAc,oBAAoB;AACrD,eAAO,0CAAoB,eAAe,WAAgC;AAAA,EAC5E,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAYO,SAAS,uBAId,eACA,aACoE;AACpE,uBAAAA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AACA,uBAAAA;AAAA,IACE,cAAc,YAAY;AAAA,IAC1B;AAAA,EACF;AACA,uBAAAA;AAAA,IACE,CAAC,CAAC,cAAc;AAAA,IAChB;AAAA,EACF;AACA,aAAO;AAAA,IACL;AAAA,IACA;A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AA,IACpD,SAAS,0BAA0B;AAAA;AAAA,IAEnC,EAAE,OAAoC;AAAA,EACxC;AAEA,SAAO;AAAA,IACL,OAAO,YAAyD;AAC9D,YAAM,eAAe,MAAM,cAAc;AAAA,QACvC,WAAW,QAAQ,aAAa,CAAC;AAAA,QACjC,SAAS,QAAQ;AAAA,QACjB,oBAAoB,QAAQ;AAAA,QAC5B,aAAa,QAAQ;AAAA,QACrB,QAAQ,QAAQ;AAAA,MAClB,CAAC;AACD,UAAI,aAAa,QAAQ;AACvB,eAAO;AAAA,UACL,QAAQ,MAAM,KAAK,OAAO,OAAO,aAAa,MAAM,CAAC;AAAA,UACrD,MAAM,aAAa;AAAA,QACrB;AAAA,MACF;AACA,aAAO;AAAA,QACL,MAAM,aAAa;AAAA,MACrB;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["invariant", "useApolloQuery", "useApolloSubscription", "useApolloMutation"]
|
|
7
7
|
}
|
package/lib/hooks.mjs
CHANGED
|
@@ -1,43 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
1
|
// src/hooks.ts
|
|
42
2
|
import invariant from "invariant";
|
|
43
3
|
import {
|
|
@@ -58,23 +18,26 @@ function useLazyLoadQuery(query, variables, options) {
|
|
|
58
18
|
(query == null ? void 0 : query.__brand) === void 0,
|
|
59
19
|
"useLazyLoadQuery: Document must be a valid runtime type."
|
|
60
20
|
);
|
|
61
|
-
const apolloOptions = options &&
|
|
21
|
+
const apolloOptions = options && {
|
|
22
|
+
...options,
|
|
62
23
|
fetchPolicy: convertFetchPolicy(options.fetchPolicy)
|
|
63
|
-
}
|
|
24
|
+
};
|
|
64
25
|
if (query.watchQueryDocument) {
|
|
65
|
-
return useCompiledLazyLoadQuery(query,
|
|
66
|
-
variables
|
|
67
|
-
|
|
26
|
+
return useCompiledLazyLoadQuery(query, {
|
|
27
|
+
variables,
|
|
28
|
+
...apolloOptions
|
|
29
|
+
});
|
|
68
30
|
} else {
|
|
69
31
|
const client = useOverridenOrDefaultApolloClient();
|
|
70
32
|
return useApolloQuery(
|
|
71
33
|
// Compiled documents without narrow observables should be treated like
|
|
72
34
|
// normal queries.
|
|
73
35
|
query.executionQueryDocument || query,
|
|
74
|
-
|
|
36
|
+
{
|
|
75
37
|
client,
|
|
76
|
-
variables
|
|
77
|
-
|
|
38
|
+
variables,
|
|
39
|
+
...apolloOptions
|
|
40
|
+
}
|
|
78
41
|
);
|
|
79
42
|
}
|
|
80
43
|
}
|
|
@@ -180,8 +143,8 @@ function useMutation(mutation) {
|
|
|
180
143
|
{ client }
|
|
181
144
|
);
|
|
182
145
|
return [
|
|
183
|
-
(options) =>
|
|
184
|
-
const apolloResult =
|
|
146
|
+
async (options) => {
|
|
147
|
+
const apolloResult = await apolloUpdater({
|
|
185
148
|
variables: options.variables || {},
|
|
186
149
|
context: options.context,
|
|
187
150
|
optimisticResponse: options.optimisticResponse,
|
|
@@ -197,7 +160,7 @@ function useMutation(mutation) {
|
|
|
197
160
|
return {
|
|
198
161
|
data: apolloResult.data
|
|
199
162
|
};
|
|
200
|
-
}
|
|
163
|
+
},
|
|
201
164
|
mutationLoading
|
|
202
165
|
];
|
|
203
166
|
}
|
package/lib/hooks.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/hooks.ts"],
|
|
4
4
|
"sourcesContent": ["import invariant from \"invariant\";\nimport {\n useSubscription as useApolloSubscription,\n useQuery as useApolloQuery,\n useMutation as useApolloMutation,\n SubscriptionHookOptions as ApolloSubscriptionHookOptions,\n ErrorPolicy as ApolloErrorPolicy,\n ApolloClient,\n ApolloCache,\n} from \"@apollo/client\";\n\nimport {\n FetchPolicy,\n GraphQLTaggedNode,\n KeyType,\n KeyTypeData,\n OperationType,\n} from \"./types\";\nimport {\n RefetchFn,\n PaginationFn,\n useCompiledLazyLoadQuery,\n useCompiledFragment,\n useCompiledRefetchableFragment,\n useCompiledPaginationFragment,\n} from \"./storeObservation/compiledHooks\";\nimport { convertFetchPolicy } from \"./convertFetchPolicy\";\nimport { useOverridenOrDefaultApolloClient } from \"./useOverridenOrDefaultApolloClient\";\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport { FragmentReference } from \"./storeObservation/compiledHooks/types\";\n\n/**\n * Executes a GraphQL query.\n *\n * This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple\n * round trips, one for loading and one for resolving.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-lazy-load-query}\n *\n * @param query The query operation to perform.\n * @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL\n * variables declared inside the query.\n * @param options Options passed on to the underlying implementation.\n * @param options.context The query context to pass along the apollo link chain. Should be avoided when possible as\n * it will not be compatible with Relay APIs.\n * @returns An object with either an error, the result data, or neither while loading.\n */\nexport function useLazyLoadQuery<TQuery extends OperationType>(\n query: GraphQLTaggedNode,\n variables: TQuery[\"variables\"],\n options?: { fetchPolicy?: FetchPolicy; context?: TQuery[\"context\"] },\n): { error?: Error; data?: TQuery[\"response\"] } {\n invariant(\n query?.__brand === undefined,\n \"useLazyLoadQuery: Document must be a valid runtime type.\",\n );\n const apolloOptions = options && {\n ...options,\n fetchPolicy: convertFetchPolicy(options.fetchPolicy),\n };\n if (query.watchQueryDocument) {\n return useCompiledLazyLoadQuery(query as CompiledArtefactModule, {\n variables,\n ...apolloOptions,\n });\n } else {\n const client = useOverridenOrDefaultApolloClient();\n return useApolloQuery(\n // Compiled documents without narrow observables should be treated like\n // normal queries.\n query.executionQueryDocument || query,\n {\n client,\n variables,\n ...apolloOptions,\n },\n );\n }\n}\n\n/**\n * A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment\n * should select all the fields that the component directly uses in its rendering or needs to pass to external\n * functions. It should *not* select data that its children need, unless those children are intended to remain their\n * pure React props as data inputs.\n *\n * For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to\n * spread in the child's fragment.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-fragment}\n *\n * @note For migration purposes, this hook supports the notion that the fragment reference can be undefined. This is\n * to support cases where useFragment is used in a tree that is conditionally using fragments.\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections.\n */\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): KeyTypeData<TKey>;\nexport function useFragment(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: undefined,\n): undefined;\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey | undefined,\n): KeyTypeData<TKey> | undefined;\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode | undefined,\n fragmentRef: TKey,\n): KeyTypeData<TKey> {\n invariant(\n fragmentInput?.__brand === undefined,\n \"useFragment: fragmentInput must be a valid runtime type.\",\n );\n // If fragmentInput is undefined, it means the fragment is not compiled and we should just return the fragmentRef.\n // This is an implementation detail that should never surface to the user.\n if (fragmentInput && fragmentInput.watchQueryDocument) {\n return useCompiledFragment(fragmentInput, fragmentRef as FragmentReference);\n } else {\n return fragmentRef as unknown;\n }\n}\n\n/**\n * Equivalent to `useFragment`, but allows refetching of its subtree of the overall query.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-refetchable-fragment}\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections and a function to perform the refetch.\n */\nexport function useRefetchableFragment<\n TQuery extends OperationType,\n TKey extends KeyType,\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): [data: KeyTypeData<TKey>, refetch: RefetchFn<TQuery[\"variables\"]>] {\n invariant(\n fragmentInput,\n \"useRefetchableFragment: Missing metadata; did you forget to use the @refetchable directive?\",\n );\n invariant(\n fragmentInput.__brand === undefined,\n \"useRefetchableFragment: fragmentInput must be a valid runtime type.\",\n );\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"useRefetchableFragment is only supported at this time when using compilation\",\n );\n return useCompiledRefetchableFragment(\n fragmentInput as CompiledArtefactModule,\n fragmentRef as FragmentReference,\n );\n}\n\n/**\n * Equivalent to `useFragment`, but allows pagination of its subtree of the overall query.\n *\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-pagination-fragment}\n *\n * @param fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections and functions to deal with pagination.\n */\nexport function usePaginationFragment<\n TQuery extends OperationType,\n TKey extends KeyType,\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey,\n): {\n data: KeyTypeData<TKey>;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn<TQuery[\"variables\"]>;\n} {\n invariant(\n fragmentInput,\n \"usePaginationFragment: Missing metadata; did you forget to use the @refetchable directive?\",\n );\n invariant(\n fragmentInput.__brand === undefined,\n \"usePaginationFragment: fragmentInput must be a valid runtime type.\",\n );\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"usePaginationFragment is only supported at this time when using compilation\",\n );\n return useCompiledPaginationFragment(\n fragmentInput as CompiledArtefactModule,\n fragmentRef as FragmentReference,\n );\n}\n\n// https://github.com/facebook/relay/blob/master/website/docs/api-reference/types/GraphQLSubscriptionConfig.md\ninterface GraphQLSubscriptionConfig<\n TSubscriptionPayload extends OperationType,\n> {\n subscription: GraphQLTaggedNode;\n variables: TSubscriptionPayload[\"variables\"];\n /**\n * Should be avoided when possible as it will not be compatible with Relay APIs.\n */\n context?: TSubscriptionPayload[\"context\"];\n /**\n * Should response be nullable?\n */\n onNext?: (response: TSubscriptionPayload[\"response\"]) => void;\n onError?: (error: Error) => void;\n}\n\n/**\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-subscription}\n *\n * @param config\n */\nexport function useSubscription<TSubscriptionPayload extends OperationType>(\n config: GraphQLSubscriptionConfig<TSubscriptionPayload>,\n): void {\n const document = config.subscription;\n invariant(\n document?.__brand === undefined,\n \"useSubscription: Document must be a valid runtime type.\",\n );\n invariant(\n !document.watchQueryDocument,\n \"useSubscription: Did not expect a watch query document\",\n );\n const client = useOverridenOrDefaultApolloClient();\n const { error } = useApolloSubscription(\n document.executionQueryDocument || document,\n {\n client,\n variables: config.variables,\n context: config.context,\n onSubscriptionData: ({ subscriptionData }) => {\n // Supposedly this never gets triggered for an error by design:\n // https://github.com/apollographql/react-apollo/issues/3177#issuecomment-506758144\n invariant(\n !subscriptionData.error,\n \"Did not expect to receive an error here\",\n );\n if (subscriptionData.data && config.onNext) {\n config.onNext(subscriptionData.data);\n }\n },\n errorPolicy: \"ignore\",\n } as ApolloSubscriptionHookOptions & {\n errorPolicy: ApolloErrorPolicy;\n },\n );\n if (error) {\n if (config.onError) {\n config.onError(error);\n } else {\n console.warn(\n `An unhandled GraphQL subscription error occurred: ${error.message}`,\n );\n }\n }\n}\n\ninterface IMutationCommitterOptions<TMutationPayload extends OperationType> {\n variables: TMutationPayload[\"variables\"];\n optimisticResponse?: Partial<TMutationPayload[\"response\"]> | null;\n onCompleted?: (response: TMutationPayload[\"response\"]) => void;\n /**\n * This version yields the ApolloCache instance, instead of the RelayStore,\n * and usage of it will not be portable to Relay directly. However, it is a\n * necessary evil for migration purposes.\n */\n updater?: (\n cache: ApolloCache<unknown>,\n data: TMutationPayload[\"response\"],\n ) => void;\n /**\n * @deprecated Should be avoided when possible as it will not be compatible with Relay APIs.\n */\n context?: TMutationPayload[\"context\"];\n}\n\ntype MutationCommiter<TMutationPayload extends OperationType> = (\n options: IMutationCommitterOptions<TMutationPayload>,\n) => Promise<{ errors?: Error[]; data?: TMutationPayload[\"response\"] }>;\n\n/**\n * @see {@link https://microsoft.github.io/graphitation/docs/apollo-react-relay-duct-tape/use-mutation}\n *\n * @param mutation\n * @returns\n */\nexport function useMutation<TMutationPayload extends OperationType>(\n mutation: GraphQLTaggedNode,\n): [MutationCommiter<TMutationPayload>, boolean] {\n invariant(\n mutation?.__brand === undefined,\n \"useMutation: Document must be a valid runtime type.\",\n );\n invariant(\n !mutation.watchQueryDocument,\n \"useMutation: Did not expect a watch query document\",\n );\n const client = useOverridenOrDefaultApolloClient();\n const [apolloUpdater, { loading: mutationLoading }] = useApolloMutation(\n mutation.executionQueryDocument || mutation,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n { client: client as ApolloClient<any> },\n );\n\n return [\n async (options: IMutationCommitterOptions<TMutationPayload>) => {\n const apolloResult = await apolloUpdater({\n variables: options.variables || {},\n context: options.context,\n optimisticResponse: options.optimisticResponse,\n onCompleted: options.onCompleted,\n update: options.updater,\n });\n if (apolloResult.errors) {\n return {\n errors: Array.from(Object.values(apolloResult.errors)),\n data: apolloResult.data,\n };\n }\n return {\n data: apolloResult.data,\n };\n },\n mutationLoading,\n ];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAAA,OAAO,eAAe;AACtB;AAAA,EACE,mBAAmB;AAAA,EACnB,YAAY;AAAA,EACZ,eAAe;AAAA,OAKV;AASP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,yCAAyC;AAoB3C,SAAS,iBACd,OACA,WACA,SAC8C;AAC9C;AAAA,KACE,+BAAO,aAAY;AAAA,IACnB;AAAA,EACF;AACA,QAAM,gBAAgB,WAAW;AAAA,IAC/B,GAAG;AAAA,IACH,aAAa,mBAAmB,QAAQ,WAAW;AAAA,EACrD;AACA,MAAI,MAAM,oBAAoB;A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ineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
8
|
var __export = (target, all) => {
|
|
26
9
|
for (var name in all)
|
|
27
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -70,10 +53,11 @@ function useCompiledFragment(documents, fragmentReference) {
|
|
|
70
53
|
fetchPolicy: "cache-only",
|
|
71
54
|
query: watchQueryDocument,
|
|
72
55
|
returnPartialData: false,
|
|
73
|
-
variables:
|
|
56
|
+
variables: {
|
|
57
|
+
...fragmentReference.__fragments,
|
|
74
58
|
id: fragmentReference.id,
|
|
75
59
|
__fragments: fragmentReference.__fragments
|
|
76
|
-
}
|
|
60
|
+
}
|
|
77
61
|
}),
|
|
78
62
|
[client, fragmentReference.id, fragmentReference.__fragments]
|
|
79
63
|
);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useEffect, useMemo } from \"react\";\nimport invariant from \"invariant\";\nimport { useForceUpdate } from \"./useForceUpdate\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { FragmentReference } from \"./types\";\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport { Cache } from \"@apollo/client/core\";\n\n/**\n * @param documents Compiled watch query document that is used to setup a narrow\n * observable for just the data selected by the original fragment.\n * @param fragmentReference A Node object that has a globally unique `id` field.\n */\n\nexport function useCompiledFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): object {\n invariant(\n fragmentReference,\n \"useFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n const { watchQueryDocument, metadata } = documents;\n invariant(\n watchQueryDocument,\n \"useFragment(): Expected a `watchQueryDocument` to have been \" +\n \"extracted. Did you forget to invoke the compiler?\",\n );\n\n const client = useOverridenOrDefaultApolloClient();\n const forceUpdate = useForceUpdate();\n\n const observableQuery = useMemo(\n () =>\n client.watchQuery({\n fetchPolicy: \"cache-only\",\n query: watchQueryDocument,\n returnPartialData: false,\n variables: {\n ...fragmentReference.__fragments,\n id: fragmentReference.id,\n __fragments: fragmentReference.__fragments,\n },\n }),\n [client, fragmentReference.id, fragmentReference.__fragments],\n );\n\n useEffect(() => {\n let skipFirst = true;\n const subscription = observableQuery.subscribe(\n () => {\n // Unclear why, but this yields twice with the same results, so skip one.\n if (skipFirst) {\n skipFirst = false;\n } else {\n forceUpdate();\n }\n },\n (error) => {\n console.log(error);\n },\n );\n return () => subscription.unsubscribe();\n }, [observableQuery]);\n\n const result = observableQuery.getCurrentResult();\n if (result.partial) {\n invariant(\n false,\n \"useFragment(): Missing data expected to be seeded by the execution query document: %s. Please check your type policies and possibleTypes configuration. If only subset of properties is missing you might need to configure merge functions for non-normalized types.\",\n JSON.stringify(\n // we need the cast because queryInfo and lastDiff are private but very useful for debugging\n (\n observableQuery as unknown as {\n queryInfo?: { lastDiff?: { diff?: Cache.DiffResult<unknown> } };\n }\n ).queryInfo?.lastDiff?.diff?.missing?.map((e) => e.path),\n ),\n );\n }\n let data = result.data;\n if (metadata?.rootSelection) {\n invariant(\n data,\n \"useFragment(): Expected Apollo to respond with previously seeded data of the execution query document: %s. Did you configure your type policies and possibleTypes correctly? Check apollo-react-relay-duct-tape README for more details.\",\n JSON.stringify({\n selection: metadata.rootSelection,\n mainFragment: metadata.mainFragment,\n }),\n );\n data = data[metadata.rootSelection];\n }\n invariant(\n data,\n \"useFragment(): Expected Apollo to respond with previously seeded data of the execution query document. Did you configure your type policies and possibleTypes correctly? Check apollo-react-relay-duct-tape README for more details.\",\n );\n return data;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AACnC,uBAAsB;AACtB,4BAA+B;AAC/B,+CAAkD;AAY3C,SAAS,oBACd,WACA,mBACQ;AAlBV;AAmBE,uBAAAA;AAAA,IACE;AAAA,IACA;AAAA,EAEF;AACA,QAAM,EAAE,oBAAoB,SAAS,IAAI;AACzC,uBAAAA;AAAA,IACE;AAAA,IACA;AAAA,EAEF;AAEA,QAAM,aAAS,4EAAkC;AACjD,QAAM,kBAAc,sCAAe;AAEnC,QAAM,sBAAkB;AAAA,IACtB,MACE,OAAO,WAAW;AAAA,MAChB,aAAa;AAAA,MACb,OAAO;AAAA,MACP,mBAAmB;AAAA,MACnB,WAAW;AAAA,QACT,GAAG,kBAAkB;AAAA,QACrB,IAAI,kBAAkB;AAAA,QACtB,aAAa,kBAAkB;AAAA,MACjC;AAAA,IACF,CAAC;AAAA,IACH,CAAC,QAAQ,kBAAkB,IAAI,kBAAkB,WAAW;AAAA,EAC9D;AAEA,8BAAU,MAAM;AACd,QAAI,YAAY;AAChB,UAAM,eAAe,gBAAgB;AAAA,MACnC,MAAM;AAEJ,YAAI,WAAW;AACb,sBAAY;AAAA,QACd,OAAO;AACL,sBAAY;AAAA,QACd;AAAA,MACF;AAAA,MACA,CAAC,UAAU;AACT,gBAAQ,IAAI,KAAK;AAAA,MACnB;AAAA,IACF;AACA,WAAO,MAAM,aAAa,YAAY;AAAA,EACxC,GAAG,CAAC,eAAe,CAAC;AAEpB,QAAM,SAAS,gBAAgB,iBAAiB;AAChD,MAAI,OAAO,SAAS;AAClB,yBAAAA;AAAA,MACE;AAAA,MACA;AAAA,MACA,KAAK;AAAA;AAAA,SAGD,uCAGA,cAHA,mBAGW,aAHX,mBAGqB,SAHrB,mBAG2B,YAH3B,mBAGoC,IAAI,CAAC,MAAM,EAAE;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,OAAO;AAClB,MAAI,qCAAU,eAAe;AAC3B,yBAAAA;AAAA,MACE;AAAA,MACA;AAAA,MACA,KAAK,UAAU;AAAA,QACb,WAAW,SAAS;AAAA,QACpB,cAAc,SAAS;AAAA,MACzB,CAAC;AAAA,IACH;AACA,WAAO,KAAK,SAAS,aAAa;AAAA,EACpC;AACA,uBAAAA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["invariant"]
|
|
7
7
|
}
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// src/storeObservation/compiledHooks/useCompiledFragment.ts
|
|
22
2
|
import { useEffect, useMemo } from "react";
|
|
23
3
|
import invariant from "invariant";
|
|
@@ -41,10 +21,11 @@ function useCompiledFragment(documents, fragmentReference) {
|
|
|
41
21
|
fetchPolicy: "cache-only",
|
|
42
22
|
query: watchQueryDocument,
|
|
43
23
|
returnPartialData: false,
|
|
44
|
-
variables:
|
|
24
|
+
variables: {
|
|
25
|
+
...fragmentReference.__fragments,
|
|
45
26
|
id: fragmentReference.id,
|
|
46
27
|
__fragments: fragmentReference.__fragments
|
|
47
|
-
}
|
|
28
|
+
}
|
|
48
29
|
}),
|
|
49
30
|
[client, fragmentReference.id, fragmentReference.__fragments]
|
|
50
31
|
);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useEffect, useMemo } from \"react\";\nimport invariant from \"invariant\";\nimport { useForceUpdate } from \"./useForceUpdate\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { FragmentReference } from \"./types\";\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport { Cache } from \"@apollo/client/core\";\n\n/**\n * @param documents Compiled watch query document that is used to setup a narrow\n * observable for just the data selected by the original fragment.\n * @param fragmentReference A Node object that has a globally unique `id` field.\n */\n\nexport function useCompiledFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): object {\n invariant(\n fragmentReference,\n \"useFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n const { watchQueryDocument, metadata } = documents;\n invariant(\n watchQueryDocument,\n \"useFragment(): Expected a `watchQueryDocument` to have been \" +\n \"extracted. Did you forget to invoke the compiler?\",\n );\n\n const client = useOverridenOrDefaultApolloClient();\n const forceUpdate = useForceUpdate();\n\n const observableQuery = useMemo(\n () =>\n client.watchQuery({\n fetchPolicy: \"cache-only\",\n query: watchQueryDocument,\n returnPartialData: false,\n variables: {\n ...fragmentReference.__fragments,\n id: fragmentReference.id,\n __fragments: fragmentReference.__fragments,\n },\n }),\n [client, fragmentReference.id, fragmentReference.__fragments],\n );\n\n useEffect(() => {\n let skipFirst = true;\n const subscription = observableQuery.subscribe(\n () => {\n // Unclear why, but this yields twice with the same results, so skip one.\n if (skipFirst) {\n skipFirst = false;\n } else {\n forceUpdate();\n }\n },\n (error) => {\n console.log(error);\n },\n );\n return () => subscription.unsubscribe();\n }, [observableQuery]);\n\n const result = observableQuery.getCurrentResult();\n if (result.partial) {\n invariant(\n false,\n \"useFragment(): Missing data expected to be seeded by the execution query document: %s. Please check your type policies and possibleTypes configuration. If only subset of properties is missing you might need to configure merge functions for non-normalized types.\",\n JSON.stringify(\n // we need the cast because queryInfo and lastDiff are private but very useful for debugging\n (\n observableQuery as unknown as {\n queryInfo?: { lastDiff?: { diff?: Cache.DiffResult<unknown> } };\n }\n ).queryInfo?.lastDiff?.diff?.missing?.map((e) => e.path),\n ),\n );\n }\n let data = result.data;\n if (metadata?.rootSelection) {\n invariant(\n data,\n \"useFragment(): Expected Apollo to respond with previously seeded data of the execution query document: %s. Did you configure your type policies and possibleTypes correctly? Check apollo-react-relay-duct-tape README for more details.\",\n JSON.stringify({\n selection: metadata.rootSelection,\n mainFragment: metadata.mainFragment,\n }),\n );\n data = data[metadata.rootSelection];\n }\n invariant(\n data,\n \"useFragment(): Expected Apollo to respond with previously seeded data of the execution query document. Did you configure your type policies and possibleTypes correctly? Check apollo-react-relay-duct-tape README for more details.\",\n );\n return data;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAAA,SAAS,WAAW,eAAe;AACnC,OAAO,eAAe;AACtB,SAAS,sBAAsB;AAC/B,SAAS,yCAAyC;AAY3C,SAAS,oBACd,WACA,mBACQ;AAlBV;AAmBE;AAAA,IACE;AAAA,IACA;AAAA,EAEF;AACA,QAAM,EAAE,oBAAoB,SAAS,IAAI;AACzC;AAAA,IACE;AAAA,IACA;AAAA,EAEF;AAEA,QAAM,SAAS,kCAAkC;AACjD,QAAM,cAAc,eAAe;AAEnC,QAAM,kBAAkB;AAAA,IACtB,MACE,OAAO,WAAW;AAAA,MAChB,aAAa;AAAA,MACb,OAAO;AAAA,MACP,mBAAmB;AAAA,MACnB,WAAW;AAAA,QACT,GAAG,kBAAkB;AAAA,QACrB,IAAI,kBAAkB;AAAA,QACtB,aAAa,kBAAkB;AAAA,MACjC;AAAA,IACF,CAAC;AAAA,IACH,CAAC,QAAQ,kBAAkB,IAAI,kBAAkB,WAAW;AAAA,EAC9D;AAEA,YAAU,MAAM;AACd,QAAI,YAAY;AAChB,UAAM,eAAe,gBAAgB;AAAA,MACnC,MAAM;AAEJ,YAAI,WAAW;AACb,sBAAY;AAAA,QACd,OAAO;AACL,sBAAY;AAAA,QACd;AAAA,MACF;AAAA,MACA,CAAC,UAAU;AACT,gBAAQ,IAAI,KAAK;AAAA,MACnB;AAAA,IACF;AACA,WAAO,MAAM,aAAa,YAAY;AAAA,EACxC,GAAG,CAAC,eAAe,CAAC;AAEpB,QAAM,SAAS,gBAAgB,iBAAiB;AAChD,MAAI,OAAO,SAAS;AAClB;AAAA,MACE;AAAA,MACA;AAAA,MACA,KAAK;AAAA;AAAA,SAGD,uCAGA,cAHA,mBAGW,aAHX,mBAGqB,SAHrB,mBAG2B,YAH3B,mBAGoC,IAAI,CAAC,MAAM,EAAE;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,OAAO;AAClB,MAAI,qCAAU,eAAe;AAC3B;AAAA,MACE;AAAA,MACA;AAAA,MACA,KAAK,UAAU;AAAA,QACb,WAAW,SAAS;AAAA,QACpB,cAAc,SAAS;AAAA,MACzB,CAAC;AAAA,IACH;AACA,WAAO,KAAK,SAAS,aAAa;AAAA,EACpC;AACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
8
|
var __export = (target, all) => {
|
|
26
9
|
for (var name in all)
|
|
27
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -82,18 +65,20 @@ function useLoadMore({
|
|
|
82
65
|
cursorValue,
|
|
83
66
|
"usePaginationFragment(): Expected a cursor value to exist"
|
|
84
67
|
);
|
|
85
|
-
const previousVariables =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
68
|
+
const previousVariables = {
|
|
69
|
+
...(0, import_lodash.merge)(
|
|
70
|
+
{},
|
|
71
|
+
(_a = metadata.connection) == null ? void 0 : _a.filterVariableDefaults,
|
|
72
|
+
latestVariablesUsedByStandaloneRefetch,
|
|
73
|
+
fragmentReference.__fragments
|
|
74
|
+
),
|
|
91
75
|
id: fragmentReference.id
|
|
92
|
-
}
|
|
93
|
-
const newVariables =
|
|
76
|
+
};
|
|
77
|
+
const newVariables = {
|
|
78
|
+
...previousVariables,
|
|
94
79
|
[countVariable]: countValue,
|
|
95
80
|
[cursorVariable]: cursorValue
|
|
96
|
-
}
|
|
81
|
+
};
|
|
97
82
|
const refetchOptions = {
|
|
98
83
|
fetchPolicy: "no-cache",
|
|
99
84
|
UNSTABLE_onCompletedWithData: (error, data) => {
|
|
@@ -135,10 +120,11 @@ function useLoadMore({
|
|
|
135
120
|
existingData,
|
|
136
121
|
updater
|
|
137
122
|
);
|
|
138
|
-
cache.writeFragment(
|
|
123
|
+
cache.writeFragment({
|
|
124
|
+
...cacheSelector,
|
|
139
125
|
variables: newVariables,
|
|
140
126
|
data: newCacheData
|
|
141
|
-
})
|
|
127
|
+
});
|
|
142
128
|
}
|
|
143
129
|
(_a2 = options == null ? void 0 : options.onCompleted) == null ? void 0 : _a2.call(options, error);
|
|
144
130
|
}
|
|
@@ -228,18 +214,20 @@ function useCompiledPaginationFragment(documents, fragmentReference) {
|
|
|
228
214
|
connectionSelectionPath: connectionMetadata.selectionPath
|
|
229
215
|
};
|
|
230
216
|
const pageInfo = getPageInfo(data, connectionMetadata.selectionPath);
|
|
231
|
-
const [loadNext, isLoadingNext] = useLoadMore(
|
|
217
|
+
const [loadNext, isLoadingNext] = useLoadMore({
|
|
218
|
+
...commonPaginationParams,
|
|
232
219
|
countVariable: connectionMetadata.forwardCountVariable,
|
|
233
220
|
cursorVariable: connectionMetadata.forwardCursorVariable,
|
|
234
221
|
cursorValue: pageInfo == null ? void 0 : pageInfo.endCursor,
|
|
235
222
|
updater: (existing, incoming) => [...existing, ...incoming]
|
|
236
|
-
})
|
|
237
|
-
const [loadPrevious, isLoadingPrevious] = useLoadMore(
|
|
223
|
+
});
|
|
224
|
+
const [loadPrevious, isLoadingPrevious] = useLoadMore({
|
|
225
|
+
...commonPaginationParams,
|
|
238
226
|
countVariable: connectionMetadata.backwardCountVariable,
|
|
239
227
|
cursorVariable: connectionMetadata.backwardCursorVariable,
|
|
240
228
|
cursorValue: pageInfo == null ? void 0 : pageInfo.startCursor,
|
|
241
229
|
updater: (existing, incoming) => [...incoming, ...existing]
|
|
242
|
-
})
|
|
230
|
+
});
|
|
243
231
|
return {
|
|
244
232
|
data,
|
|
245
233
|
refetch: storeVariablesAndRefetch,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useState, useCallback, useRef } from \"react\";\nimport { ApolloCache, DataProxy } from \"@apollo/client\";\nimport invariant from \"invariant\";\nimport { useCompiledRefetchableFragment } from \"./useCompiledRefetchableFragment\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { FragmentReference } from \"./types\";\nimport type {\n RefetchFn,\n Disposable,\n PrivateRefetchOptions,\n RefetchOptions,\n} from \"./useCompiledRefetchableFragment\";\nimport type {\n CompiledArtefactModule,\n Metadata,\n} from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport type { DocumentNode } from \"graphql\";\nimport { Variables } from \"../../types\";\nimport { merge } from \"lodash\";\n\nexport type PaginationFn = (\n count: number,\n options?: RefetchOptions,\n) => Disposable;\n\ninterface PaginationParams {\n fragmentReference: FragmentReference;\n refetch: RefetchFn;\n latestVariablesUsedByStandaloneRefetch: Partial<Variables>;\n metadata: Metadata;\n executionQueryDocument: DocumentNode;\n cache: ApolloCache<unknown>;\n countVariable: string | undefined;\n cursorVariable: string | undefined;\n connectionSelectionPath: string[];\n cursorValue: string | undefined;\n updater: <T>(existing: T[], incoming: T[]) => T[];\n}\n\nfunction useLoadMore({\n fragmentReference,\n refetch,\n latestVariablesUsedByStandaloneRefetch,\n metadata,\n executionQueryDocument,\n cache,\n countVariable,\n cursorVariable,\n connectionSelectionPath,\n cursorValue,\n updater,\n}: PaginationParams): [loadPage: PaginationFn, isLoadingMore: boolean] {\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n const loadPage = useCallback<PaginationFn>(\n (countValue, options) => {\n invariant(\n countVariable,\n \"usePaginationFragment(): Expected a count variable to exist\",\n );\n invariant(\n cursorVariable,\n \"usePaginationFragment(): Expected a cursor variable to exist\",\n );\n invariant(\n cursorValue,\n \"usePaginationFragment(): Expected a cursor value to exist\",\n );\n const previousVariables = {\n ...merge(\n {},\n metadata.connection?.filterVariableDefaults,\n latestVariablesUsedByStandaloneRefetch,\n fragmentReference.__fragments,\n ),\n id: fragmentReference.id,\n };\n const newVariables = {\n ...previousVariables,\n [countVariable]: countValue,\n [cursorVariable]: cursorValue,\n };\n const refetchOptions: PrivateRefetchOptions = {\n fetchPolicy: \"no-cache\",\n UNSTABLE_onCompletedWithData: (error, data) => {\n // NOTE: We can do this now already, because `refetch` wraps the\n // onCompleted callback in a batchedUpdates callback.\n setIsLoadingMore(false);\n\n if (!error) {\n invariant(\n data,\n \"usePaginationFragment(): Expected to have response data\",\n );\n const newData = metadata.rootSelection\n ? data[metadata.rootSelection]\n : data;\n const mainFragment = metadata.mainFragment;\n invariant(\n mainFragment,\n \"usePaginationFragment(): Expected mainFragment metadata\",\n );\n const cacheSelector: DataProxy.Fragment<unknown, object> = {\n // TODO: If we're dropping default Apollo Cache keys, we can probably just do the below\n id: fragmentReference.id as string,\n // id: cache.identify({\n // __typename: mainFragment.typeCondition,\n // id: fragmentReference.id as StoreValue,\n // }),\n variables: previousVariables,\n fragmentName: mainFragment.name,\n // Create new document with operation filtered out.\n fragment: {\n kind: \"Document\",\n definitions: executionQueryDocument.definitions.filter(\n (def) => def.kind === \"FragmentDefinition\",\n ),\n },\n };\n /**\n * Note: Even though we already have the latest data from the\n * useCompiledFragment hook, we can't really use that as it may contain\n * __fragments fields and we don't want to write those to the cache. If\n * we figure out a way from a field-policy's merge function to not write\n * to the cache, then that would be preferable.\n */\n const existingData = cache.readFragment(cacheSelector);\n invariant(existingData, \"Expected existing data\");\n const newCacheData = mergeEdges(\n connectionSelectionPath,\n newData,\n existingData,\n updater,\n );\n cache.writeFragment({\n ...cacheSelector,\n variables: newVariables,\n data: newCacheData,\n });\n }\n\n options?.onCompleted?.(error);\n },\n };\n // TODO: Measure if invoking `refetch` leads to React updates and if it\n // makes sense to wrap it and the following setIsLoadingMore(true)\n // call in a batchedUpdates callback.\n const disposable = refetch(\n newVariables,\n refetchOptions as RefetchOptions,\n );\n setIsLoadingMore(true);\n return disposable;\n },\n [\n fragmentReference.id,\n fragmentReference.__fragments,\n refetch,\n latestVariablesUsedByStandaloneRefetch,\n metadata,\n executionQueryDocument,\n cache,\n countVariable,\n cursorVariable,\n connectionSelectionPath,\n cursorValue,\n ],\n );\n return [loadPage, isLoadingMore];\n}\n\nfunction getValueAtSelectionPath(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any>,\n selectionPath: string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let object: Record<string, any> = data;\n selectionPath.forEach((field) => {\n object = object[field];\n invariant(object, \"Expected path to connection in response to exist\");\n });\n return object;\n}\n\nfunction getPageInfo(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any>,\n selectionPath: string[],\n): {\n startCursor?: string;\n endCursor?: string;\n hasPreviousPage?: boolean;\n hasNextPage?: boolean;\n} {\n const object = getValueAtSelectionPath(data, selectionPath);\n const pageInfo = object.pageInfo;\n invariant(pageInfo, \"Expected to find the connection's page info object\");\n return pageInfo;\n}\n\nfunction mergeEdges(\n connectionPath: string[],\n destination: object,\n source: object,\n updater: <T>(existing: T[], incoming: T[]) => T[],\n) {\n const edgesPath = [...connectionPath, \"edges\"];\n const existingEdges = getValueAtSelectionPath(source, edgesPath);\n const newEdges = getValueAtSelectionPath(destination, edgesPath);\n const allEdges = updater(existingEdges, newEdges);\n\n const connection = getValueAtSelectionPath(destination, connectionPath);\n connection[\"edges\"] = allEdges;\n\n return destination;\n}\n\nexport function useCompiledPaginationFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: any;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn;\n} {\n const { executionQueryDocument, metadata } = documents;\n invariant(\n metadata && metadata.mainFragment,\n \"usePaginationFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n invariant(\n executionQueryDocument,\n \"usePaginationFragment(): Expected fragment `%s` to be refetchable when \" +\n \"using `usePaginationFragment`. Did you forget to add a @refetchable \" +\n \"directive to the fragment?\",\n metadata.mainFragment.name,\n );\n const connectionMetadata = metadata.connection;\n invariant(\n connectionMetadata,\n \"usePaginationFragment: Expected fragment `%s` to include a \" +\n \"connection when using `usePaginationFragment`. Did you forget to add a @connection \" +\n \"directive to the connection field in the fragment?\",\n metadata.mainFragment.name,\n );\n const [data, refetch] = useCompiledRefetchableFragment(\n documents,\n fragmentReference,\n );\n\n // Consumers might want to not only use loadNext/loadPrevious with pagination fragment but also standalone refetch,\n // for example to change the variables that decide on connection filtering. To make sure that loadNext/loadPrevious\n // respects the variables used by standalone refetch, we store them in a ref and pass them to useLoadMore.\n const latestVariablesUsedByStandaloneRefetch = useRef({});\n const storeVariablesAndRefetch = useCallback<RefetchFn>(\n (variables: Partial<Variables>, options?: RefetchOptions) => {\n latestVariablesUsedByStandaloneRefetch.current = variables;\n return refetch(variables, options);\n },\n [refetch],\n );\n\n const commonPaginationParams = {\n fragmentReference,\n refetch,\n latestVariablesUsedByStandaloneRefetch:\n latestVariablesUsedByStandaloneRefetch.current,\n metadata,\n executionQueryDocument,\n cache: useOverridenOrDefaultApolloClient().cache,\n connectionSelectionPath: connectionMetadata.selectionPath,\n };\n const pageInfo = getPageInfo(data, connectionMetadata.selectionPath);\n const [loadNext, isLoadingNext] = useLoadMore({\n ...commonPaginationParams,\n countVariable: connectionMetadata.forwardCountVariable,\n cursorVariable: connectionMetadata.forwardCursorVariable,\n cursorValue: pageInfo?.endCursor,\n updater: (existing, incoming) => [...existing, ...incoming],\n });\n const [loadPrevious, isLoadingPrevious] = useLoadMore({\n ...commonPaginationParams,\n countVariable: connectionMetadata.backwardCountVariable,\n cursorVariable: connectionMetadata.backwardCursorVariable,\n cursorValue: pageInfo?.startCursor,\n updater: (existing, incoming) => [...incoming, ...existing],\n });\n return {\n data,\n refetch: storeVariablesAndRefetch,\n hasNext: !!pageInfo?.hasNextPage,\n hasPrevious: !!pageInfo?.hasPreviousPage,\n isLoadingNext,\n isLoadingPrevious,\n loadNext,\n loadPrevious,\n };\n}\n"],
|
|
5
|
-
"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pD,GAAG;AAAA,IACH,eAAe,mBAAmB;AAAA,IAClC,gBAAgB,mBAAmB;AAAA,IACnC,aAAa,qCAAU;AAAA,IACvB,SAAS,CAAC,UAAU,aAAa,CAAC,GAAG,UAAU,GAAG,QAAQ;AAAA,EAC5D,CAAC;AACD,SAAO;AAAA,IACL;AAAA,IACA,SAAS;AAAA,IACT,SAAS,CAAC,EAAC,qCAAU;AAAA,IACrB,aAAa,CAAC,EAAC,qCAAU;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["invariant", "_a"]
|
|
7
7
|
}
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts
|
|
22
2
|
import { useState, useCallback, useRef } from "react";
|
|
23
3
|
import invariant from "invariant";
|
|
@@ -53,18 +33,20 @@ function useLoadMore({
|
|
|
53
33
|
cursorValue,
|
|
54
34
|
"usePaginationFragment(): Expected a cursor value to exist"
|
|
55
35
|
);
|
|
56
|
-
const previousVariables =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
36
|
+
const previousVariables = {
|
|
37
|
+
...merge(
|
|
38
|
+
{},
|
|
39
|
+
(_a = metadata.connection) == null ? void 0 : _a.filterVariableDefaults,
|
|
40
|
+
latestVariablesUsedByStandaloneRefetch,
|
|
41
|
+
fragmentReference.__fragments
|
|
42
|
+
),
|
|
62
43
|
id: fragmentReference.id
|
|
63
|
-
}
|
|
64
|
-
const newVariables =
|
|
44
|
+
};
|
|
45
|
+
const newVariables = {
|
|
46
|
+
...previousVariables,
|
|
65
47
|
[countVariable]: countValue,
|
|
66
48
|
[cursorVariable]: cursorValue
|
|
67
|
-
}
|
|
49
|
+
};
|
|
68
50
|
const refetchOptions = {
|
|
69
51
|
fetchPolicy: "no-cache",
|
|
70
52
|
UNSTABLE_onCompletedWithData: (error, data) => {
|
|
@@ -106,10 +88,11 @@ function useLoadMore({
|
|
|
106
88
|
existingData,
|
|
107
89
|
updater
|
|
108
90
|
);
|
|
109
|
-
cache.writeFragment(
|
|
91
|
+
cache.writeFragment({
|
|
92
|
+
...cacheSelector,
|
|
110
93
|
variables: newVariables,
|
|
111
94
|
data: newCacheData
|
|
112
|
-
})
|
|
95
|
+
});
|
|
113
96
|
}
|
|
114
97
|
(_a2 = options == null ? void 0 : options.onCompleted) == null ? void 0 : _a2.call(options, error);
|
|
115
98
|
}
|
|
@@ -199,18 +182,20 @@ function useCompiledPaginationFragment(documents, fragmentReference) {
|
|
|
199
182
|
connectionSelectionPath: connectionMetadata.selectionPath
|
|
200
183
|
};
|
|
201
184
|
const pageInfo = getPageInfo(data, connectionMetadata.selectionPath);
|
|
202
|
-
const [loadNext, isLoadingNext] = useLoadMore(
|
|
185
|
+
const [loadNext, isLoadingNext] = useLoadMore({
|
|
186
|
+
...commonPaginationParams,
|
|
203
187
|
countVariable: connectionMetadata.forwardCountVariable,
|
|
204
188
|
cursorVariable: connectionMetadata.forwardCursorVariable,
|
|
205
189
|
cursorValue: pageInfo == null ? void 0 : pageInfo.endCursor,
|
|
206
190
|
updater: (existing, incoming) => [...existing, ...incoming]
|
|
207
|
-
})
|
|
208
|
-
const [loadPrevious, isLoadingPrevious] = useLoadMore(
|
|
191
|
+
});
|
|
192
|
+
const [loadPrevious, isLoadingPrevious] = useLoadMore({
|
|
193
|
+
...commonPaginationParams,
|
|
209
194
|
countVariable: connectionMetadata.backwardCountVariable,
|
|
210
195
|
cursorVariable: connectionMetadata.backwardCursorVariable,
|
|
211
196
|
cursorValue: pageInfo == null ? void 0 : pageInfo.startCursor,
|
|
212
197
|
updater: (existing, incoming) => [...incoming, ...existing]
|
|
213
|
-
})
|
|
198
|
+
});
|
|
214
199
|
return {
|
|
215
200
|
data,
|
|
216
201
|
refetch: storeVariablesAndRefetch,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledPaginationFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useState, useCallback, useRef } from \"react\";\nimport { ApolloCache, DataProxy } from \"@apollo/client\";\nimport invariant from \"invariant\";\nimport { useCompiledRefetchableFragment } from \"./useCompiledRefetchableFragment\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { FragmentReference } from \"./types\";\nimport type {\n RefetchFn,\n Disposable,\n PrivateRefetchOptions,\n RefetchOptions,\n} from \"./useCompiledRefetchableFragment\";\nimport type {\n CompiledArtefactModule,\n Metadata,\n} from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport type { DocumentNode } from \"graphql\";\nimport { Variables } from \"../../types\";\nimport { merge } from \"lodash\";\n\nexport type PaginationFn = (\n count: number,\n options?: RefetchOptions,\n) => Disposable;\n\ninterface PaginationParams {\n fragmentReference: FragmentReference;\n refetch: RefetchFn;\n latestVariablesUsedByStandaloneRefetch: Partial<Variables>;\n metadata: Metadata;\n executionQueryDocument: DocumentNode;\n cache: ApolloCache<unknown>;\n countVariable: string | undefined;\n cursorVariable: string | undefined;\n connectionSelectionPath: string[];\n cursorValue: string | undefined;\n updater: <T>(existing: T[], incoming: T[]) => T[];\n}\n\nfunction useLoadMore({\n fragmentReference,\n refetch,\n latestVariablesUsedByStandaloneRefetch,\n metadata,\n executionQueryDocument,\n cache,\n countVariable,\n cursorVariable,\n connectionSelectionPath,\n cursorValue,\n updater,\n}: PaginationParams): [loadPage: PaginationFn, isLoadingMore: boolean] {\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n const loadPage = useCallback<PaginationFn>(\n (countValue, options) => {\n invariant(\n countVariable,\n \"usePaginationFragment(): Expected a count variable to exist\",\n );\n invariant(\n cursorVariable,\n \"usePaginationFragment(): Expected a cursor variable to exist\",\n );\n invariant(\n cursorValue,\n \"usePaginationFragment(): Expected a cursor value to exist\",\n );\n const previousVariables = {\n ...merge(\n {},\n metadata.connection?.filterVariableDefaults,\n latestVariablesUsedByStandaloneRefetch,\n fragmentReference.__fragments,\n ),\n id: fragmentReference.id,\n };\n const newVariables = {\n ...previousVariables,\n [countVariable]: countValue,\n [cursorVariable]: cursorValue,\n };\n const refetchOptions: PrivateRefetchOptions = {\n fetchPolicy: \"no-cache\",\n UNSTABLE_onCompletedWithData: (error, data) => {\n // NOTE: We can do this now already, because `refetch` wraps the\n // onCompleted callback in a batchedUpdates callback.\n setIsLoadingMore(false);\n\n if (!error) {\n invariant(\n data,\n \"usePaginationFragment(): Expected to have response data\",\n );\n const newData = metadata.rootSelection\n ? data[metadata.rootSelection]\n : data;\n const mainFragment = metadata.mainFragment;\n invariant(\n mainFragment,\n \"usePaginationFragment(): Expected mainFragment metadata\",\n );\n const cacheSelector: DataProxy.Fragment<unknown, object> = {\n // TODO: If we're dropping default Apollo Cache keys, we can probably just do the below\n id: fragmentReference.id as string,\n // id: cache.identify({\n // __typename: mainFragment.typeCondition,\n // id: fragmentReference.id as StoreValue,\n // }),\n variables: previousVariables,\n fragmentName: mainFragment.name,\n // Create new document with operation filtered out.\n fragment: {\n kind: \"Document\",\n definitions: executionQueryDocument.definitions.filter(\n (def) => def.kind === \"FragmentDefinition\",\n ),\n },\n };\n /**\n * Note: Even though we already have the latest data from the\n * useCompiledFragment hook, we can't really use that as it may contain\n * __fragments fields and we don't want to write those to the cache. If\n * we figure out a way from a field-policy's merge function to not write\n * to the cache, then that would be preferable.\n */\n const existingData = cache.readFragment(cacheSelector);\n invariant(existingData, \"Expected existing data\");\n const newCacheData = mergeEdges(\n connectionSelectionPath,\n newData,\n existingData,\n updater,\n );\n cache.writeFragment({\n ...cacheSelector,\n variables: newVariables,\n data: newCacheData,\n });\n }\n\n options?.onCompleted?.(error);\n },\n };\n // TODO: Measure if invoking `refetch` leads to React updates and if it\n // makes sense to wrap it and the following setIsLoadingMore(true)\n // call in a batchedUpdates callback.\n const disposable = refetch(\n newVariables,\n refetchOptions as RefetchOptions,\n );\n setIsLoadingMore(true);\n return disposable;\n },\n [\n fragmentReference.id,\n fragmentReference.__fragments,\n refetch,\n latestVariablesUsedByStandaloneRefetch,\n metadata,\n executionQueryDocument,\n cache,\n countVariable,\n cursorVariable,\n connectionSelectionPath,\n cursorValue,\n ],\n );\n return [loadPage, isLoadingMore];\n}\n\nfunction getValueAtSelectionPath(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any>,\n selectionPath: string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let object: Record<string, any> = data;\n selectionPath.forEach((field) => {\n object = object[field];\n invariant(object, \"Expected path to connection in response to exist\");\n });\n return object;\n}\n\nfunction getPageInfo(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any>,\n selectionPath: string[],\n): {\n startCursor?: string;\n endCursor?: string;\n hasPreviousPage?: boolean;\n hasNextPage?: boolean;\n} {\n const object = getValueAtSelectionPath(data, selectionPath);\n const pageInfo = object.pageInfo;\n invariant(pageInfo, \"Expected to find the connection's page info object\");\n return pageInfo;\n}\n\nfunction mergeEdges(\n connectionPath: string[],\n destination: object,\n source: object,\n updater: <T>(existing: T[], incoming: T[]) => T[],\n) {\n const edgesPath = [...connectionPath, \"edges\"];\n const existingEdges = getValueAtSelectionPath(source, edgesPath);\n const newEdges = getValueAtSelectionPath(destination, edgesPath);\n const allEdges = updater(existingEdges, newEdges);\n\n const connection = getValueAtSelectionPath(destination, connectionPath);\n connection[\"edges\"] = allEdges;\n\n return destination;\n}\n\nexport function useCompiledPaginationFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: any;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn;\n} {\n const { executionQueryDocument, metadata } = documents;\n invariant(\n metadata && metadata.mainFragment,\n \"usePaginationFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n invariant(\n executionQueryDocument,\n \"usePaginationFragment(): Expected fragment `%s` to be refetchable when \" +\n \"using `usePaginationFragment`. Did you forget to add a @refetchable \" +\n \"directive to the fragment?\",\n metadata.mainFragment.name,\n );\n const connectionMetadata = metadata.connection;\n invariant(\n connectionMetadata,\n \"usePaginationFragment: Expected fragment `%s` to include a \" +\n \"connection when using `usePaginationFragment`. Did you forget to add a @connection \" +\n \"directive to the connection field in the fragment?\",\n metadata.mainFragment.name,\n );\n const [data, refetch] = useCompiledRefetchableFragment(\n documents,\n fragmentReference,\n );\n\n // Consumers might want to not only use loadNext/loadPrevious with pagination fragment but also standalone refetch,\n // for example to change the variables that decide on connection filtering. To make sure that loadNext/loadPrevious\n // respects the variables used by standalone refetch, we store them in a ref and pass them to useLoadMore.\n const latestVariablesUsedByStandaloneRefetch = useRef({});\n const storeVariablesAndRefetch = useCallback<RefetchFn>(\n (variables: Partial<Variables>, options?: RefetchOptions) => {\n latestVariablesUsedByStandaloneRefetch.current = variables;\n return refetch(variables, options);\n },\n [refetch],\n );\n\n const commonPaginationParams = {\n fragmentReference,\n refetch,\n latestVariablesUsedByStandaloneRefetch:\n latestVariablesUsedByStandaloneRefetch.current,\n metadata,\n executionQueryDocument,\n cache: useOverridenOrDefaultApolloClient().cache,\n connectionSelectionPath: connectionMetadata.selectionPath,\n };\n const pageInfo = getPageInfo(data, connectionMetadata.selectionPath);\n const [loadNext, isLoadingNext] = useLoadMore({\n ...commonPaginationParams,\n countVariable: connectionMetadata.forwardCountVariable,\n cursorVariable: connectionMetadata.forwardCursorVariable,\n cursorValue: pageInfo?.endCursor,\n updater: (existing, incoming) => [...existing, ...incoming],\n });\n const [loadPrevious, isLoadingPrevious] = useLoadMore({\n ...commonPaginationParams,\n countVariable: connectionMetadata.backwardCountVariable,\n cursorVariable: connectionMetadata.backwardCursorVariable,\n cursorValue: pageInfo?.startCursor,\n updater: (existing, incoming) => [...incoming, ...existing],\n });\n return {\n data,\n refetch: storeVariablesAndRefetch,\n hasNext: !!pageInfo?.hasNextPage,\n hasPrevious: !!pageInfo?.hasPreviousPage,\n isLoadingNext,\n isLoadingPrevious,\n loadNext,\n loadPrevious,\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAAA,SAAS,UAAU,aAAa,cAAc;AAE9C,OAAO,eAAe;AACtB,SAAS,sCAAsC;AAC/C,SAAS,yCAAyC;AAelD,SAAS,aAAa;AAqBtB,SAAS,YAAY;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAu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@@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
8
|
var __export = (target, all) => {
|
|
38
9
|
for (var name in all)
|
|
39
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -101,9 +72,11 @@ function useCompiledRefetchableFragment(documents, fragmentReference) {
|
|
|
101
72
|
const refetch = (0, import_react.useCallback)(
|
|
102
73
|
(variablesSubset, options) => {
|
|
103
74
|
var _a;
|
|
104
|
-
const variables =
|
|
75
|
+
const variables = {
|
|
76
|
+
...fragmentReference.__fragments,
|
|
77
|
+
...variablesSubset,
|
|
105
78
|
id: fragmentReference.id
|
|
106
|
-
}
|
|
79
|
+
};
|
|
107
80
|
const observable = client.watchQuery({
|
|
108
81
|
fetchPolicy: (_a = (0, import_convertFetchPolicy.convertFetchPolicy)(options == null ? void 0 : options.fetchPolicy)) != null ? _a : "network-only",
|
|
109
82
|
query: executionQueryDocument,
|
|
@@ -122,8 +95,11 @@ function useCompiledRefetchableFragment(documents, fragmentReference) {
|
|
|
122
95
|
(_a2 = options == null ? void 0 : options.onCompleted) == null ? void 0 : _a2.call(options, error || null);
|
|
123
96
|
}
|
|
124
97
|
if (!error) {
|
|
125
|
-
const
|
|
126
|
-
const nextVariables =
|
|
98
|
+
const { id: _, ...variablesToPropagate } = variables;
|
|
99
|
+
const nextVariables = {
|
|
100
|
+
...fragmentReference.__fragments,
|
|
101
|
+
...variablesToPropagate
|
|
102
|
+
};
|
|
127
103
|
if (!(0, import_lodash.isEqual)(
|
|
128
104
|
fragmentReferenceWithOwnVariables.__fragments,
|
|
129
105
|
nextVariables
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from \"react\";\nimport { unstable_batchedUpdates } from \"react-dom\";\nimport invariant from \"invariant\";\nimport { useCompiledFragment } from \"./useCompiledFragment\";\nimport { isEqual } from \"lodash\";\nimport { convertFetchPolicy } from \"../../convertFetchPolicy\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport type { FragmentReference } from \"./types\";\nimport type { FetchPolicy } from \"../../types\";\n\nexport interface Disposable {\n dispose(): void;\n}\n\nexport type RefetchFn<Variables extends object = object> = (\n variables: Partial<Variables>,\n options?: RefetchOptions,\n) => Disposable;\n\nexport interface RefetchOptions {\n onCompleted?: (error: Error | null) => void;\n fetchPolicy?: FetchPolicy;\n}\n\n/**\n * These do not exist in the Relay API and should not be exported from the package.\n */\nexport interface PrivateRefetchOptions\n extends Omit<RefetchOptions, \"fetchPolicy\"> {\n /**\n * Returns the fetched data.\n */\n UNSTABLE_onCompletedWithData?: (\n error: Error | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any> | null,\n ) => void;\n\n fetchPolicy?: FetchPolicy | \"no-cache\";\n}\n\nexport function useCompiledRefetchableFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): [data: object, refetch: RefetchFn] {\n const { executionQueryDocument, metadata } = documents;\n invariant(\n metadata && metadata.mainFragment,\n \"useRefetchableFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n invariant(\n executionQueryDocument,\n \"useRefetchableFragment(): Expected fragment `%s` to be refetchable when \" +\n \"using `useRefetchableFragment`. Did you forget to add a @refetchable \" +\n \"directive to the fragment?\",\n metadata.mainFragment.name,\n );\n\n const client = useOverridenOrDefaultApolloClient();\n\n // We use state for this, so that...\n const [\n fragmentReferenceWithOwnVariables,\n setFragmentReferenceWithOwnVariables,\n ] = useState(fragmentReference);\n // ...this gets invoked again with updated variables.\n const data = useCompiledFragment(\n documents,\n fragmentReferenceWithOwnVariables,\n );\n\n const disposable = useRef<Disposable>();\n useEffect(\n () => () => {\n if (disposable.current) {\n disposable.current.dispose();\n disposable.current = undefined;\n }\n },\n [], // On unmount\n );\n\n const refetch = useCallback<RefetchFn>(\n (variablesSubset, options?: PrivateRefetchOptions) => {\n const variables = {\n ...fragmentReference.__fragments,\n ...variablesSubset,\n id: fragmentReference.id,\n };\n const observable = client.watchQuery({\n fetchPolicy: convertFetchPolicy(options?.fetchPolicy) ?? \"network-only\",\n query: executionQueryDocument,\n variables,\n });\n let subscription: ZenObservable.Subscription | undefined =\n observable.subscribe(\n ({ data, error }) => {\n // Be sure not to keep a retain cycle, so cleanup the reference first thing.\n subscription?.unsubscribe();\n subscription = undefined;\n disposable.current = undefined;\n\n unstable_batchedUpdates(() => {\n if (options?.UNSTABLE_onCompletedWithData) {\n options.UNSTABLE_onCompletedWithData(error || null, data);\n } else {\n options?.onCompleted?.(error || null);\n }\n if (!error) {\n const { id: _, ...variablesToPropagate } = variables;\n const nextVariables = {\n ...fragmentReference.__fragments,\n ...variablesToPropagate,\n };\n // No need to trigger an update to propagate new variables if they don't actually change.\n if (\n !isEqual(\n fragmentReferenceWithOwnVariables.__fragments,\n nextVariables,\n )\n ) {\n const nextFragmentReference: FragmentReference = {\n __fragments: nextVariables,\n };\n // Don't add an empty key if this is a fragment on the Query type.\n if (fragmentReference.id !== undefined) {\n nextFragmentReference.id = fragmentReference.id;\n }\n setFragmentReferenceWithOwnVariables(nextFragmentReference);\n }\n }\n });\n },\n (error) => {\n // Be sure not to keep a retain cycle\n subscription?.unsubscribe();\n subscription = undefined;\n\n if (options?.UNSTABLE_onCompletedWithData) {\n options.UNSTABLE_onCompletedWithData(error, null);\n } else {\n options?.onCompleted?.(error);\n }\n },\n );\n disposable.current = { dispose: () => subscription?.unsubscribe() };\n return disposable.current;\n },\n [\n client,\n executionQueryDocument,\n fragmentReference.id,\n fragmentReference.__fragments,\n fragmentReferenceWithOwnVariables.__fragments,\n ],\n );\n\n return [data, refetch];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;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AT,gBAAAA,IAAA,cAAuB,SAAS;AAAA,YAClC;AACA,gBAAI,CAAC,OAAO;AACV,oBAAM,EAAE,IAAI,GAAG,GAAG,qBAAqB,IAAI;AAC3C,oBAAM,gBAAgB;AAAA,gBACpB,GAAG,kBAAkB;AAAA,gBACrB,GAAG;AAAA,cACL;AAEA,kBACE,KAAC;AAAA,gBACC,kCAAkC;AAAA,gBAClC;AAAA,cACF,GACA;AACA,sBAAM,wBAA2C;AAAA,kBAC/C,aAAa;AAAA,gBACf;AAEA,oBAAI,kBAAkB,OAAO,QAAW;AACtC,wCAAsB,KAAK,kBAAkB;AAAA,gBAC/C;AACA,qDAAqC,qBAAqB;AAAA,cAC5D;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,CAAC,UAAU;AAxIrB,cAAAA;AA0IY,uDAAc;AACd,yBAAe;AAEf,cAAI,mCAAS,8BAA8B;AACzC,oBAAQ,6BAA6B,OAAO,IAAI;AAAA,UAClD,OAAO;AACL,aAAAA,MAAA,mCAAS,gBAAT,gBAAAA,IAAA,cAAuB;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AACF,iBAAW,UAAU,EAAE,SAAS,MAAM,6CAAc,cAAc;AAClE,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,kBAAkB;AAAA,MAClB,kCAAkC;AAAA,IACpC;AAAA,EACF;AAEA,SAAO,CAAC,MAAM,OAAO;AACvB;",
|
|
6
6
|
"names": ["invariant", "data", "_a"]
|
|
7
7
|
}
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
// src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts
|
|
34
2
|
import { useState, useCallback, useRef, useEffect } from "react";
|
|
35
3
|
import { unstable_batchedUpdates } from "react-dom";
|
|
@@ -72,9 +40,11 @@ function useCompiledRefetchableFragment(documents, fragmentReference) {
|
|
|
72
40
|
const refetch = useCallback(
|
|
73
41
|
(variablesSubset, options) => {
|
|
74
42
|
var _a;
|
|
75
|
-
const variables =
|
|
43
|
+
const variables = {
|
|
44
|
+
...fragmentReference.__fragments,
|
|
45
|
+
...variablesSubset,
|
|
76
46
|
id: fragmentReference.id
|
|
77
|
-
}
|
|
47
|
+
};
|
|
78
48
|
const observable = client.watchQuery({
|
|
79
49
|
fetchPolicy: (_a = convertFetchPolicy(options == null ? void 0 : options.fetchPolicy)) != null ? _a : "network-only",
|
|
80
50
|
query: executionQueryDocument,
|
|
@@ -93,8 +63,11 @@ function useCompiledRefetchableFragment(documents, fragmentReference) {
|
|
|
93
63
|
(_a2 = options == null ? void 0 : options.onCompleted) == null ? void 0 : _a2.call(options, error || null);
|
|
94
64
|
}
|
|
95
65
|
if (!error) {
|
|
96
|
-
const
|
|
97
|
-
const nextVariables =
|
|
66
|
+
const { id: _, ...variablesToPropagate } = variables;
|
|
67
|
+
const nextVariables = {
|
|
68
|
+
...fragmentReference.__fragments,
|
|
69
|
+
...variablesToPropagate
|
|
70
|
+
};
|
|
98
71
|
if (!isEqual(
|
|
99
72
|
fragmentReferenceWithOwnVariables.__fragments,
|
|
100
73
|
nextVariables
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/storeObservation/compiledHooks/useCompiledRefetchableFragment.ts"],
|
|
4
4
|
"sourcesContent": ["import { useState, useCallback, useRef, useEffect } from \"react\";\nimport { unstable_batchedUpdates } from \"react-dom\";\nimport invariant from \"invariant\";\nimport { useCompiledFragment } from \"./useCompiledFragment\";\nimport { isEqual } from \"lodash\";\nimport { convertFetchPolicy } from \"../../convertFetchPolicy\";\nimport { useOverridenOrDefaultApolloClient } from \"../../useOverridenOrDefaultApolloClient\";\n\nimport type { CompiledArtefactModule } from \"@graphitation/apollo-react-relay-duct-tape-compiler\";\nimport type { FragmentReference } from \"./types\";\nimport type { FetchPolicy } from \"../../types\";\n\nexport interface Disposable {\n dispose(): void;\n}\n\nexport type RefetchFn<Variables extends object = object> = (\n variables: Partial<Variables>,\n options?: RefetchOptions,\n) => Disposable;\n\nexport interface RefetchOptions {\n onCompleted?: (error: Error | null) => void;\n fetchPolicy?: FetchPolicy;\n}\n\n/**\n * These do not exist in the Relay API and should not be exported from the package.\n */\nexport interface PrivateRefetchOptions\n extends Omit<RefetchOptions, \"fetchPolicy\"> {\n /**\n * Returns the fetched data.\n */\n UNSTABLE_onCompletedWithData?: (\n error: Error | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: Record<string, any> | null,\n ) => void;\n\n fetchPolicy?: FetchPolicy | \"no-cache\";\n}\n\nexport function useCompiledRefetchableFragment(\n documents: CompiledArtefactModule,\n fragmentReference: FragmentReference,\n): [data: object, refetch: RefetchFn] {\n const { executionQueryDocument, metadata } = documents;\n invariant(\n metadata && metadata.mainFragment,\n \"useRefetchableFragment(): Expected metadata to have been extracted from \" +\n \"the fragment. Did you forget to invoke the compiler?\",\n );\n invariant(\n executionQueryDocument,\n \"useRefetchableFragment(): Expected fragment `%s` to be refetchable when \" +\n \"using `useRefetchableFragment`. Did you forget to add a @refetchable \" +\n \"directive to the fragment?\",\n metadata.mainFragment.name,\n );\n\n const client = useOverridenOrDefaultApolloClient();\n\n // We use state for this, so that...\n const [\n fragmentReferenceWithOwnVariables,\n setFragmentReferenceWithOwnVariables,\n ] = useState(fragmentReference);\n // ...this gets invoked again with updated variables.\n const data = useCompiledFragment(\n documents,\n fragmentReferenceWithOwnVariables,\n );\n\n const disposable = useRef<Disposable>();\n useEffect(\n () => () => {\n if (disposable.current) {\n disposable.current.dispose();\n disposable.current = undefined;\n }\n },\n [], // On unmount\n );\n\n const refetch = useCallback<RefetchFn>(\n (variablesSubset, options?: PrivateRefetchOptions) => {\n const variables = {\n ...fragmentReference.__fragments,\n ...variablesSubset,\n id: fragmentReference.id,\n };\n const observable = client.watchQuery({\n fetchPolicy: convertFetchPolicy(options?.fetchPolicy) ?? \"network-only\",\n query: executionQueryDocument,\n variables,\n });\n let subscription: ZenObservable.Subscription | undefined =\n observable.subscribe(\n ({ data, error }) => {\n // Be sure not to keep a retain cycle, so cleanup the reference first thing.\n subscription?.unsubscribe();\n subscription = undefined;\n disposable.current = undefined;\n\n unstable_batchedUpdates(() => {\n if (options?.UNSTABLE_onCompletedWithData) {\n options.UNSTABLE_onCompletedWithData(error || null, data);\n } else {\n options?.onCompleted?.(error || null);\n }\n if (!error) {\n const { id: _, ...variablesToPropagate } = variables;\n const nextVariables = {\n ...fragmentReference.__fragments,\n ...variablesToPropagate,\n };\n // No need to trigger an update to propagate new variables if they don't actually change.\n if (\n !isEqual(\n fragmentReferenceWithOwnVariables.__fragments,\n nextVariables,\n )\n ) {\n const nextFragmentReference: FragmentReference = {\n __fragments: nextVariables,\n };\n // Don't add an empty key if this is a fragment on the Query type.\n if (fragmentReference.id !== undefined) {\n nextFragmentReference.id = fragmentReference.id;\n }\n setFragmentReferenceWithOwnVariables(nextFragmentReference);\n }\n }\n });\n },\n (error) => {\n // Be sure not to keep a retain cycle\n subscription?.unsubscribe();\n subscription = undefined;\n\n if (options?.UNSTABLE_onCompletedWithData) {\n options.UNSTABLE_onCompletedWithData(error, null);\n } else {\n options?.onCompleted?.(error);\n }\n },\n );\n disposable.current = { dispose: () => subscription?.unsubscribe() };\n return disposable.current;\n },\n [\n client,\n executionQueryDocument,\n fragmentReference.id,\n fragmentReference.__fragments,\n fragmentReferenceWithOwnVariables.__fragments,\n ],\n );\n\n return [data, refetch];\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAAA,SAAS,UAAU,aAAa,QAAQ,iBAAiB;AACzD,SAAS,+BAA+B;AACxC,OAAO,eAAe;AACtB,SAAS,2BAA2B;AACpC,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,yCAAyC;AAqC3C,SAAS,+BACd,WACA,mBACoC;AACpC,QAAM,EAAE,wBAAwB,SAAS,IAAI;AAC7C;AAAA,IACE,YAAY,SAAS;AAAA,IACrB;AAAA,EAEF;AACA;AAAA,IACE;AAAA,IACA;AAAA,IAGA,SAAS,aAAa;AAAA,EACxB;AAEA,QAAM,SAAS,kCAAkC;AAGjD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EAC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qB;AAAA,cAC5D;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,QACA,CAAC,UAAU;AAxIrB,cAAAA;AA0IY,uDAAc;AACd,yBAAe;AAEf,cAAI,mCAAS,8BAA8B;AACzC,oBAAQ,6BAA6B,OAAO,IAAI;AAAA,UAClD,OAAO;AACL,aAAAA,MAAA,mCAAS,gBAAT,gBAAAA,IAAA,cAAuB;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AACF,iBAAW,UAAU,EAAE,SAAS,MAAM,6CAAc,cAAc;AAClE,aAAO,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,kBAAkB;AAAA,MAClB,kCAAkC;AAAA,IACpC;AAAA,EACF;AAEA,SAAO,CAAC,MAAM,OAAO;AACvB;",
|
|
6
6
|
"names": ["data", "_a"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphitation/apollo-react-relay-duct-tape",
|
|
3
3
|
"description": "A compatibility wrapper that provides the react-relay API on top of Apollo Client.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.4.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/microsoft/graphitation.git",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@apollo/client": ">= ^3.3.0 < 3.7.0",
|
|
24
|
-
"@graphitation/apollo-mock-client": "^0.
|
|
25
|
-
"@graphitation/graphql-js-operation-payload-generator": "^0.
|
|
26
|
-
"@graphitation/graphql-js-tag": "^0.
|
|
24
|
+
"@graphitation/apollo-mock-client": "^0.12.0",
|
|
25
|
+
"@graphitation/graphql-js-operation-payload-generator": "^0.13.0",
|
|
26
|
+
"@graphitation/graphql-js-tag": "^0.10.0",
|
|
27
27
|
"@types/jest": "^26.0.22",
|
|
28
28
|
"@types/lodash": "^4.14.176",
|
|
29
29
|
"@types/react": "^18.2.29",
|
|
30
30
|
"graphql": "^15.0.0",
|
|
31
31
|
"monorepo-scripts": "*",
|
|
32
32
|
"react": "^18.2.0",
|
|
33
|
-
"@graphitation/apollo-react-relay-duct-tape-compiler": "^1.
|
|
33
|
+
"@graphitation/apollo-react-relay-duct-tape-compiler": "^1.7.0",
|
|
34
34
|
"ts-expect": "^1.3.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|