bundle.cjs.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. exports.__esModule = true;
  2. exports.addTypenameToDocument = addTypenameToDocument;
  3. exports.argumentsObjectFromField = argumentsObjectFromField;
  4. exports.assign = assign;
  5. exports.buildQueryFromSelectionSet = buildQueryFromSelectionSet;
  6. exports.checkDocument = checkDocument;
  7. exports.cloneDeep = cloneDeep;
  8. exports.createFragmentMap = createFragmentMap;
  9. exports.getDefaultValues = getDefaultValues;
  10. exports.getDirectiveInfoFromField = getDirectiveInfoFromField;
  11. exports.getDirectiveNames = getDirectiveNames;
  12. exports.getDirectivesFromDocument = getDirectivesFromDocument;
  13. exports.getEnv = getEnv;
  14. exports.getFragmentDefinition = getFragmentDefinition;
  15. exports.getFragmentDefinitions = getFragmentDefinitions;
  16. exports.getFragmentQueryDocument = getFragmentQueryDocument;
  17. exports.getInclusionDirectives = getInclusionDirectives;
  18. exports.getMainDefinition = getMainDefinition;
  19. exports.getMutationDefinition = getMutationDefinition;
  20. exports.getOperationDefinition = getOperationDefinition;
  21. exports.getOperationDefinitionOrDie = getOperationDefinitionOrDie;
  22. exports.getOperationName = getOperationName;
  23. exports.getQueryDefinition = getQueryDefinition;
  24. exports.getStoreKeyName = getStoreKeyName;
  25. exports.graphQLResultHasError = graphQLResultHasError;
  26. exports.hasClientExports = hasClientExports;
  27. exports.hasDirectives = hasDirectives;
  28. exports.isDevelopment = isDevelopment;
  29. exports.isEnv = isEnv;
  30. exports.isField = isField;
  31. exports.isIdValue = isIdValue;
  32. exports.isInlineFragment = isInlineFragment;
  33. exports.isJsonValue = isJsonValue;
  34. exports.isNumberValue = isNumberValue;
  35. exports.isProduction = isProduction;
  36. exports.isScalarValue = isScalarValue;
  37. exports.isTest = isTest;
  38. exports.maybeDeepFreeze = maybeDeepFreeze;
  39. exports.mergeDeep = mergeDeep;
  40. exports.mergeDeepArray = mergeDeepArray;
  41. exports.removeArgumentsFromDocument = removeArgumentsFromDocument;
  42. exports.removeClientSetsFromDocument = removeClientSetsFromDocument;
  43. exports.removeConnectionDirectiveFromDocument = removeConnectionDirectiveFromDocument;
  44. exports.removeDirectivesFromDocument = removeDirectivesFromDocument;
  45. exports.removeFragmentSpreadFromDocument = removeFragmentSpreadFromDocument;
  46. exports.resultKeyNameFromField = resultKeyNameFromField;
  47. exports.shouldInclude = shouldInclude;
  48. exports.storeKeyNameFromField = storeKeyNameFromField;
  49. exports.stripSymbols = stripSymbols;
  50. exports.toIdValue = toIdValue;
  51. exports.tryFunctionOrLogError = tryFunctionOrLogError;
  52. exports.valueFromNode = valueFromNode;
  53. exports.valueToObjectRepresentation = valueToObjectRepresentation;
  54. exports.variablesInOperation = variablesInOperation;
  55. exports.warnOnceInDevelopment = warnOnceInDevelopment;
  56. exports.canUseWeakMap = exports.isEqual = void 0;
  57. var _visitor = require("graphql/language/visitor");
  58. var _tsInvariant = require("ts-invariant");
  59. var _tslib = require("tslib");
  60. var _fastJsonStableStringify = _interopRequireDefault(require("fast-json-stable-stringify"));
  61. var _equality = require("@wry/equality");
  62. exports.isEqual = _equality.equal;
  63. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  64. function isScalarValue(value) {
  65. return ['StringValue', 'BooleanValue', 'EnumValue'].indexOf(value.kind) > -1;
  66. }
  67. function isNumberValue(value) {
  68. return ['IntValue', 'FloatValue'].indexOf(value.kind) > -1;
  69. }
  70. function isStringValue(value) {
  71. return value.kind === 'StringValue';
  72. }
  73. function isBooleanValue(value) {
  74. return value.kind === 'BooleanValue';
  75. }
  76. function isIntValue(value) {
  77. return value.kind === 'IntValue';
  78. }
  79. function isFloatValue(value) {
  80. return value.kind === 'FloatValue';
  81. }
  82. function isVariable(value) {
  83. return value.kind === 'Variable';
  84. }
  85. function isObjectValue(value) {
  86. return value.kind === 'ObjectValue';
  87. }
  88. function isListValue(value) {
  89. return value.kind === 'ListValue';
  90. }
  91. function isEnumValue(value) {
  92. return value.kind === 'EnumValue';
  93. }
  94. function isNullValue(value) {
  95. return value.kind === 'NullValue';
  96. }
  97. function valueToObjectRepresentation(argObj, name, value, variables) {
  98. if (isIntValue(value) || isFloatValue(value)) {
  99. argObj[name.value] = Number(value.value);
  100. } else if (isBooleanValue(value) || isStringValue(value)) {
  101. argObj[name.value] = value.value;
  102. } else if (isObjectValue(value)) {
  103. var nestedArgObj_1 = {};
  104. value.fields.map(function (obj) {
  105. return valueToObjectRepresentation(nestedArgObj_1, obj.name, obj.value, variables);
  106. });
  107. argObj[name.value] = nestedArgObj_1;
  108. } else if (isVariable(value)) {
  109. var variableValue = (variables || {})[value.name.value];
  110. argObj[name.value] = variableValue;
  111. } else if (isListValue(value)) {
  112. argObj[name.value] = value.values.map(function (listValue) {
  113. var nestedArgArrayObj = {};
  114. valueToObjectRepresentation(nestedArgArrayObj, name, listValue, variables);
  115. return nestedArgArrayObj[name.value];
  116. });
  117. } else if (isEnumValue(value)) {
  118. argObj[name.value] = value.value;
  119. } else if (isNullValue(value)) {
  120. argObj[name.value] = null;
  121. } else {
  122. throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(17) : new _tsInvariant.InvariantError("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\"" + 'is not supported. Use variables instead of inline arguments to ' + 'overcome this limitation.');
  123. }
  124. }
  125. function storeKeyNameFromField(field, variables) {
  126. var directivesObj = null;
  127. if (field.directives) {
  128. directivesObj = {};
  129. field.directives.forEach(function (directive) {
  130. directivesObj[directive.name.value] = {};
  131. if (directive.arguments) {
  132. directive.arguments.forEach(function (_a) {
  133. var name = _a.name,
  134. value = _a.value;
  135. return valueToObjectRepresentation(directivesObj[directive.name.value], name, value, variables);
  136. });
  137. }
  138. });
  139. }
  140. var argObj = null;
  141. if (field.arguments && field.arguments.length) {
  142. argObj = {};
  143. field.arguments.forEach(function (_a) {
  144. var name = _a.name,
  145. value = _a.value;
  146. return valueToObjectRepresentation(argObj, name, value, variables);
  147. });
  148. }
  149. return getStoreKeyName(field.name.value, argObj, directivesObj);
  150. }
  151. var KNOWN_DIRECTIVES = ['connection', 'include', 'skip', 'client', 'rest', 'export'];
  152. function getStoreKeyName(fieldName, args, directives) {
  153. if (directives && directives['connection'] && directives['connection']['key']) {
  154. if (directives['connection']['filter'] && directives['connection']['filter'].length > 0) {
  155. var filterKeys = directives['connection']['filter'] ? directives['connection']['filter'] : [];
  156. filterKeys.sort();
  157. var queryArgs_1 = args;
  158. var filteredArgs_1 = {};
  159. filterKeys.forEach(function (key) {
  160. filteredArgs_1[key] = queryArgs_1[key];
  161. });
  162. return directives['connection']['key'] + "(" + JSON.stringify(filteredArgs_1) + ")";
  163. } else {
  164. return directives['connection']['key'];
  165. }
  166. }
  167. var completeFieldName = fieldName;
  168. if (args) {
  169. var stringifiedArgs = (0, _fastJsonStableStringify.default)(args);
  170. completeFieldName += "(" + stringifiedArgs + ")";
  171. }
  172. if (directives) {
  173. Object.keys(directives).forEach(function (key) {
  174. if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;
  175. if (directives[key] && Object.keys(directives[key]).length) {
  176. completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
  177. } else {
  178. completeFieldName += "@" + key;
  179. }
  180. });
  181. }
  182. return completeFieldName;
  183. }
  184. function argumentsObjectFromField(field, variables) {
  185. if (field.arguments && field.arguments.length) {
  186. var argObj_1 = {};
  187. field.arguments.forEach(function (_a) {
  188. var name = _a.name,
  189. value = _a.value;
  190. return valueToObjectRepresentation(argObj_1, name, value, variables);
  191. });
  192. return argObj_1;
  193. }
  194. return null;
  195. }
  196. function resultKeyNameFromField(field) {
  197. return field.alias ? field.alias.value : field.name.value;
  198. }
  199. function isField(selection) {
  200. return selection.kind === 'Field';
  201. }
  202. function isInlineFragment(selection) {
  203. return selection.kind === 'InlineFragment';
  204. }
  205. function isIdValue(idObject) {
  206. return idObject && idObject.type === 'id' && typeof idObject.generated === 'boolean';
  207. }
  208. function toIdValue(idConfig, generated) {
  209. if (generated === void 0) {
  210. generated = false;
  211. }
  212. return (0, _tslib.__assign)({
  213. type: 'id',
  214. generated: generated
  215. }, typeof idConfig === 'string' ? {
  216. id: idConfig,
  217. typename: undefined
  218. } : idConfig);
  219. }
  220. function isJsonValue(jsonObject) {
  221. return jsonObject != null && typeof jsonObject === 'object' && jsonObject.type === 'json';
  222. }
  223. function defaultValueFromVariable(node) {
  224. throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(18) : new _tsInvariant.InvariantError("Variable nodes are not supported by valueFromNode");
  225. }
  226. function valueFromNode(node, onVariable) {
  227. if (onVariable === void 0) {
  228. onVariable = defaultValueFromVariable;
  229. }
  230. switch (node.kind) {
  231. case 'Variable':
  232. return onVariable(node);
  233. case 'NullValue':
  234. return null;
  235. case 'IntValue':
  236. return parseInt(node.value, 10);
  237. case 'FloatValue':
  238. return parseFloat(node.value);
  239. case 'ListValue':
  240. return node.values.map(function (v) {
  241. return valueFromNode(v, onVariable);
  242. });
  243. case 'ObjectValue':
  244. {
  245. var value = {};
  246. for (var _i = 0, _a = node.fields; _i < _a.length; _i++) {
  247. var field = _a[_i];
  248. value[field.name.value] = valueFromNode(field.value, onVariable);
  249. }
  250. return value;
  251. }
  252. default:
  253. return node.value;
  254. }
  255. }
  256. function getDirectiveInfoFromField(field, variables) {
  257. if (field.directives && field.directives.length) {
  258. var directiveObj_1 = {};
  259. field.directives.forEach(function (directive) {
  260. directiveObj_1[directive.name.value] = argumentsObjectFromField(directive, variables);
  261. });
  262. return directiveObj_1;
  263. }
  264. return null;
  265. }
  266. function shouldInclude(selection, variables) {
  267. if (variables === void 0) {
  268. variables = {};
  269. }
  270. return getInclusionDirectives(selection.directives).every(function (_a) {
  271. var directive = _a.directive,
  272. ifArgument = _a.ifArgument;
  273. var evaledValue = false;
  274. if (ifArgument.value.kind === 'Variable') {
  275. evaledValue = variables[ifArgument.value.name.value];
  276. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(evaledValue !== void 0, 13) : (0, _tsInvariant.invariant)(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive.");
  277. } else {
  278. evaledValue = ifArgument.value.value;
  279. }
  280. return directive.name.value === 'skip' ? !evaledValue : evaledValue;
  281. });
  282. }
  283. function getDirectiveNames(doc) {
  284. var names = [];
  285. (0, _visitor.visit)(doc, {
  286. Directive: function (node) {
  287. names.push(node.name.value);
  288. }
  289. });
  290. return names;
  291. }
  292. function hasDirectives(names, doc) {
  293. return getDirectiveNames(doc).some(function (name) {
  294. return names.indexOf(name) > -1;
  295. });
  296. }
  297. function hasClientExports(document) {
  298. return document && hasDirectives(['client'], document) && hasDirectives(['export'], document);
  299. }
  300. function isInclusionDirective(_a) {
  301. var value = _a.name.value;
  302. return value === 'skip' || value === 'include';
  303. }
  304. function getInclusionDirectives(directives) {
  305. return directives ? directives.filter(isInclusionDirective).map(function (directive) {
  306. var directiveArguments = directive.arguments;
  307. var directiveName = directive.name.value;
  308. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, 14) : (0, _tsInvariant.invariant)(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive.");
  309. var ifArgument = directiveArguments[0];
  310. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', 15) : (0, _tsInvariant.invariant)(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive.");
  311. var ifValue = ifArgument.value;
  312. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 16) : (0, _tsInvariant.invariant)(ifValue && (ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
  313. return {
  314. directive: directive,
  315. ifArgument: ifArgument
  316. };
  317. }) : [];
  318. }
  319. function getFragmentQueryDocument(document, fragmentName) {
  320. var actualFragmentName = fragmentName;
  321. var fragments = [];
  322. document.definitions.forEach(function (definition) {
  323. if (definition.kind === 'OperationDefinition') {
  324. throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(11) : new _tsInvariant.InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " + 'No operations are allowed when using a fragment as a query. Only fragments are allowed.');
  325. }
  326. if (definition.kind === 'FragmentDefinition') {
  327. fragments.push(definition);
  328. }
  329. });
  330. if (typeof actualFragmentName === 'undefined') {
  331. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragments.length === 1, 12) : (0, _tsInvariant.invariant)(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment.");
  332. actualFragmentName = fragments[0].name.value;
  333. }
  334. var query = (0, _tslib.__assign)((0, _tslib.__assign)({}, document), {
  335. definitions: (0, _tslib.__spreadArrays)([{
  336. kind: 'OperationDefinition',
  337. operation: 'query',
  338. selectionSet: {
  339. kind: 'SelectionSet',
  340. selections: [{
  341. kind: 'FragmentSpread',
  342. name: {
  343. kind: 'Name',
  344. value: actualFragmentName
  345. }
  346. }]
  347. }
  348. }], document.definitions)
  349. });
  350. return query;
  351. }
  352. function assign(target) {
  353. var sources = [];
  354. for (var _i = 1; _i < arguments.length; _i++) {
  355. sources[_i - 1] = arguments[_i];
  356. }
  357. sources.forEach(function (source) {
  358. if (typeof source === 'undefined' || source === null) {
  359. return;
  360. }
  361. Object.keys(source).forEach(function (key) {
  362. target[key] = source[key];
  363. });
  364. });
  365. return target;
  366. }
  367. function getMutationDefinition(doc) {
  368. checkDocument(doc);
  369. var mutationDef = doc.definitions.filter(function (definition) {
  370. return definition.kind === 'OperationDefinition' && definition.operation === 'mutation';
  371. })[0];
  372. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(mutationDef, 1) : (0, _tsInvariant.invariant)(mutationDef, 'Must contain a mutation definition.');
  373. return mutationDef;
  374. }
  375. function checkDocument(doc) {
  376. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', 2) : (0, _tsInvariant.invariant)(doc && doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
  377. var operations = doc.definitions.filter(function (d) {
  378. return d.kind !== 'FragmentDefinition';
  379. }).map(function (definition) {
  380. if (definition.kind !== 'OperationDefinition') {
  381. throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(3) : new _tsInvariant.InvariantError("Schema type definitions not allowed in queries. Found: \"" + definition.kind + "\"");
  382. }
  383. return definition;
  384. });
  385. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(operations.length <= 1, 4) : (0, _tsInvariant.invariant)(operations.length <= 1, "Ambiguous GraphQL document: contains " + operations.length + " operations");
  386. return doc;
  387. }
  388. function getOperationDefinition(doc) {
  389. checkDocument(doc);
  390. return doc.definitions.filter(function (definition) {
  391. return definition.kind === 'OperationDefinition';
  392. })[0];
  393. }
  394. function getOperationDefinitionOrDie(document) {
  395. var def = getOperationDefinition(document);
  396. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(def, 5) : (0, _tsInvariant.invariant)(def, "GraphQL document is missing an operation");
  397. return def;
  398. }
  399. function getOperationName(doc) {
  400. return doc.definitions.filter(function (definition) {
  401. return definition.kind === 'OperationDefinition' && definition.name;
  402. }).map(function (x) {
  403. return x.name.value;
  404. })[0] || null;
  405. }
  406. function getFragmentDefinitions(doc) {
  407. return doc.definitions.filter(function (definition) {
  408. return definition.kind === 'FragmentDefinition';
  409. });
  410. }
  411. function getQueryDefinition(doc) {
  412. var queryDef = getOperationDefinition(doc);
  413. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 6) : (0, _tsInvariant.invariant)(queryDef && queryDef.operation === 'query', 'Must contain a query definition.');
  414. return queryDef;
  415. }
  416. function getFragmentDefinition(doc) {
  417. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.kind === 'Document', 7) : (0, _tsInvariant.invariant)(doc.kind === 'Document', "Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
  418. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 8) : (0, _tsInvariant.invariant)(doc.definitions.length <= 1, 'Fragment must have exactly one definition.');
  419. var fragmentDef = doc.definitions[0];
  420. process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 9) : (0, _tsInvariant.invariant)(fragmentDef.kind === 'FragmentDefinition', 'Must be a fragment definition.');
  421. return fragmentDef;
  422. }
  423. function getMainDefinition(queryDoc) {
  424. checkDocument(queryDoc);
  425. var fragmentDefinition;
  426. for (var _i = 0, _a = queryDoc.definitions; _i < _a.length; _i++) {
  427. var definition = _a[_i];
  428. if (definition.kind === 'OperationDefinition') {
  429. var operation = definition.operation;
  430. if (operation === 'query' || operation === 'mutation' || operation === 'subscription') {
  431. return definition;
  432. }
  433. }
  434. if (definition.kind === 'FragmentDefinition' && !fragmentDefinition) {
  435. fragmentDefinition = definition;
  436. }
  437. }
  438. if (fragmentDefinition) {
  439. return fragmentDefinition;
  440. }
  441. throw process.env.NODE_ENV === "production" ? new _tsInvariant.InvariantError(10) : new _tsInvariant.InvariantError('Expected a parsed GraphQL query with a query, mutation, subscription, or a fragment.');
  442. }
  443. function createFragmentMap(fragments) {
  444. if (fragments === void 0) {
  445. fragments = [];
  446. }
  447. var symTable = {};
  448. fragments.forEach(function (fragment) {
  449. symTable[fragment.name.value] = fragment;
  450. });
  451. return symTable;
  452. }
  453. function getDefaultValues(definition) {
  454. if (definition && definition.variableDefinitions && definition.variableDefinitions.length) {
  455. var defaultValues = definition.variableDefinitions.filter(function (_a) {
  456. var defaultValue = _a.defaultValue;
  457. return defaultValue;
  458. }).map(function (_a) {
  459. var variable = _a.variable,
  460. defaultValue = _a.defaultValue;
  461. var defaultValueObj = {};
  462. valueToObjectRepresentation(defaultValueObj, variable.name, defaultValue);
  463. return defaultValueObj;
  464. });
  465. return assign.apply(void 0, (0, _tslib.__spreadArrays)([{}], defaultValues));
  466. }
  467. return {};
  468. }
  469. function variablesInOperation(operation) {
  470. var names = new Set();
  471. if (operation.variableDefinitions) {
  472. for (var _i = 0, _a = operation.variableDefinitions; _i < _a.length; _i++) {
  473. var definition = _a[_i];
  474. names.add(definition.variable.name.value);
  475. }
  476. }
  477. return names;
  478. }
  479. function filterInPlace(array, test, context) {
  480. var target = 0;
  481. array.forEach(function (elem, i) {
  482. if (test.call(this, elem, i, array)) {
  483. array[target++] = elem;
  484. }
  485. }, context);
  486. array.length = target;
  487. return array;
  488. }
  489. var TYPENAME_FIELD = {
  490. kind: 'Field',
  491. name: {
  492. kind: 'Name',
  493. value: '__typename'
  494. }
  495. };
  496. function isEmpty(op, fragments) {
  497. return op.selectionSet.selections.every(function (selection) {
  498. return selection.kind === 'FragmentSpread' && isEmpty(fragments[selection.name.value], fragments);
  499. });
  500. }
  501. function nullIfDocIsEmpty(doc) {
  502. return isEmpty(getOperationDefinition(doc) || getFragmentDefinition(doc), createFragmentMap(getFragmentDefinitions(doc))) ? null : doc;
  503. }
  504. function getDirectiveMatcher(directives) {
  505. return function directiveMatcher(directive) {
  506. return directives.some(function (dir) {
  507. return dir.name && dir.name === directive.name.value || dir.test && dir.test(directive);
  508. });
  509. };
  510. }
  511. function removeDirectivesFromDocument(directives, doc) {
  512. var variablesInUse = Object.create(null);
  513. var variablesToRemove = [];
  514. var fragmentSpreadsInUse = Object.create(null);
  515. var fragmentSpreadsToRemove = [];
  516. var modifiedDoc = nullIfDocIsEmpty((0, _visitor.visit)(doc, {
  517. Variable: {
  518. enter: function (node, _key, parent) {
  519. if (parent.kind !== 'VariableDefinition') {
  520. variablesInUse[node.name.value] = true;
  521. }
  522. }
  523. },
  524. Field: {
  525. enter: function (node) {
  526. if (directives && node.directives) {
  527. var shouldRemoveField = directives.some(function (directive) {
  528. return directive.remove;
  529. });
  530. if (shouldRemoveField && node.directives && node.directives.some(getDirectiveMatcher(directives))) {
  531. if (node.arguments) {
  532. node.arguments.forEach(function (arg) {
  533. if (arg.value.kind === 'Variable') {
  534. variablesToRemove.push({
  535. name: arg.value.name.value
  536. });
  537. }
  538. });
  539. }
  540. if (node.selectionSet) {
  541. getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
  542. fragmentSpreadsToRemove.push({
  543. name: frag.name.value
  544. });
  545. });
  546. }
  547. return null;
  548. }
  549. }
  550. }
  551. },
  552. FragmentSpread: {
  553. enter: function (node) {
  554. fragmentSpreadsInUse[node.name.value] = true;
  555. }
  556. },
  557. Directive: {
  558. enter: function (node) {
  559. if (getDirectiveMatcher(directives)(node)) {
  560. return null;
  561. }
  562. }
  563. }
  564. }));
  565. if (modifiedDoc && filterInPlace(variablesToRemove, function (v) {
  566. return !variablesInUse[v.name];
  567. }).length) {
  568. modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
  569. }
  570. if (modifiedDoc && filterInPlace(fragmentSpreadsToRemove, function (fs) {
  571. return !fragmentSpreadsInUse[fs.name];
  572. }).length) {
  573. modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
  574. }
  575. return modifiedDoc;
  576. }
  577. function addTypenameToDocument(doc) {
  578. return (0, _visitor.visit)(checkDocument(doc), {
  579. SelectionSet: {
  580. enter: function (node, _key, parent) {
  581. if (parent && parent.kind === 'OperationDefinition') {
  582. return;
  583. }
  584. var selections = node.selections;
  585. if (!selections) {
  586. return;
  587. }
  588. var skip = selections.some(function (selection) {
  589. return isField(selection) && (selection.name.value === '__typename' || selection.name.value.lastIndexOf('__', 0) === 0);
  590. });
  591. if (skip) {
  592. return;
  593. }
  594. var field = parent;
  595. if (isField(field) && field.directives && field.directives.some(function (d) {
  596. return d.name.value === 'export';
  597. })) {
  598. return;
  599. }
  600. return (0, _tslib.__assign)((0, _tslib.__assign)({}, node), {
  601. selections: (0, _tslib.__spreadArrays)(selections, [TYPENAME_FIELD])
  602. });
  603. }
  604. }
  605. });
  606. }
  607. var connectionRemoveConfig = {
  608. test: function (directive) {
  609. var willRemove = directive.name.value === 'connection';
  610. if (willRemove) {
  611. if (!directive.arguments || !directive.arguments.some(function (arg) {
  612. return arg.name.value === 'key';
  613. })) {
  614. process.env.NODE_ENV === "production" || _tsInvariant.invariant.warn('Removing an @connection directive even though it does not have a key. ' + 'You may want to use the key parameter to specify a store key.');
  615. }
  616. }
  617. return willRemove;
  618. }
  619. };
  620. function removeConnectionDirectiveFromDocument(doc) {
  621. return removeDirectivesFromDocument([connectionRemoveConfig], checkDocument(doc));
  622. }
  623. function hasDirectivesInSelectionSet(directives, selectionSet, nestedCheck) {
  624. if (nestedCheck === void 0) {
  625. nestedCheck = true;
  626. }
  627. return selectionSet && selectionSet.selections && selectionSet.selections.some(function (selection) {
  628. return hasDirectivesInSelection(directives, selection, nestedCheck);
  629. });
  630. }
  631. function hasDirectivesInSelection(directives, selection, nestedCheck) {
  632. if (nestedCheck === void 0) {
  633. nestedCheck = true;
  634. }
  635. if (!isField(selection)) {
  636. return true;
  637. }
  638. if (!selection.directives) {
  639. return false;
  640. }
  641. return selection.directives.some(getDirectiveMatcher(directives)) || nestedCheck && hasDirectivesInSelectionSet(directives, selection.selectionSet, nestedCheck);
  642. }
  643. function getDirectivesFromDocument(directives, doc) {
  644. checkDocument(doc);
  645. var parentPath;
  646. return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
  647. SelectionSet: {
  648. enter: function (node, _key, _parent, path) {
  649. var currentPath = path.join('-');
  650. if (!parentPath || currentPath === parentPath || !currentPath.startsWith(parentPath)) {
  651. if (node.selections) {
  652. var selectionsWithDirectives = node.selections.filter(function (selection) {
  653. return hasDirectivesInSelection(directives, selection);
  654. });
  655. if (hasDirectivesInSelectionSet(directives, node, false)) {
  656. parentPath = currentPath;
  657. }
  658. return (0, _tslib.__assign)((0, _tslib.__assign)({}, node), {
  659. selections: selectionsWithDirectives
  660. });
  661. } else {
  662. return null;
  663. }
  664. }
  665. }
  666. }
  667. }));
  668. }
  669. function getArgumentMatcher(config) {
  670. return function argumentMatcher(argument) {
  671. return config.some(function (aConfig) {
  672. return argument.value && argument.value.kind === 'Variable' && argument.value.name && (aConfig.name === argument.value.name.value || aConfig.test && aConfig.test(argument));
  673. });
  674. };
  675. }
  676. function removeArgumentsFromDocument(config, doc) {
  677. var argMatcher = getArgumentMatcher(config);
  678. return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
  679. OperationDefinition: {
  680. enter: function (node) {
  681. return (0, _tslib.__assign)((0, _tslib.__assign)({}, node), {
  682. variableDefinitions: node.variableDefinitions.filter(function (varDef) {
  683. return !config.some(function (arg) {
  684. return arg.name === varDef.variable.name.value;
  685. });
  686. })
  687. });
  688. }
  689. },
  690. Field: {
  691. enter: function (node) {
  692. var shouldRemoveField = config.some(function (argConfig) {
  693. return argConfig.remove;
  694. });
  695. if (shouldRemoveField) {
  696. var argMatchCount_1 = 0;
  697. node.arguments.forEach(function (arg) {
  698. if (argMatcher(arg)) {
  699. argMatchCount_1 += 1;
  700. }
  701. });
  702. if (argMatchCount_1 === 1) {
  703. return null;
  704. }
  705. }
  706. }
  707. },
  708. Argument: {
  709. enter: function (node) {
  710. if (argMatcher(node)) {
  711. return null;
  712. }
  713. }
  714. }
  715. }));
  716. }
  717. function removeFragmentSpreadFromDocument(config, doc) {
  718. function enter(node) {
  719. if (config.some(function (def) {
  720. return def.name === node.name.value;
  721. })) {
  722. return null;
  723. }
  724. }
  725. return nullIfDocIsEmpty((0, _visitor.visit)(doc, {
  726. FragmentSpread: {
  727. enter: enter
  728. },
  729. FragmentDefinition: {
  730. enter: enter
  731. }
  732. }));
  733. }
  734. function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
  735. var allFragments = [];
  736. selectionSet.selections.forEach(function (selection) {
  737. if ((isField(selection) || isInlineFragment(selection)) && selection.selectionSet) {
  738. getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) {
  739. return allFragments.push(frag);
  740. });
  741. } else if (selection.kind === 'FragmentSpread') {
  742. allFragments.push(selection);
  743. }
  744. });
  745. return allFragments;
  746. }
  747. function buildQueryFromSelectionSet(document) {
  748. var definition = getMainDefinition(document);
  749. var definitionOperation = definition.operation;
  750. if (definitionOperation === 'query') {
  751. return document;
  752. }
  753. var modifiedDoc = (0, _visitor.visit)(document, {
  754. OperationDefinition: {
  755. enter: function (node) {
  756. return (0, _tslib.__assign)((0, _tslib.__assign)({}, node), {
  757. operation: 'query'
  758. });
  759. }
  760. }
  761. });
  762. return modifiedDoc;
  763. }
  764. function removeClientSetsFromDocument(document) {
  765. checkDocument(document);
  766. var modifiedDoc = removeDirectivesFromDocument([{
  767. test: function (directive) {
  768. return directive.name.value === 'client';
  769. },
  770. remove: true
  771. }], document);
  772. if (modifiedDoc) {
  773. modifiedDoc = (0, _visitor.visit)(modifiedDoc, {
  774. FragmentDefinition: {
  775. enter: function (node) {
  776. if (node.selectionSet) {
  777. var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
  778. return isField(selection) && selection.name.value === '__typename';
  779. });
  780. if (isTypenameOnly) {
  781. return null;
  782. }
  783. }
  784. }
  785. }
  786. });
  787. }
  788. return modifiedDoc;
  789. }
  790. var canUseWeakMap = typeof WeakMap === 'function' && !(typeof navigator === 'object' && navigator.product === 'ReactNative');
  791. exports.canUseWeakMap = canUseWeakMap;
  792. var toString = Object.prototype.toString;
  793. function cloneDeep(value) {
  794. return cloneDeepHelper(value, new Map());
  795. }
  796. function cloneDeepHelper(val, seen) {
  797. switch (toString.call(val)) {
  798. case "[object Array]":
  799. {
  800. if (seen.has(val)) return seen.get(val);
  801. var copy_1 = val.slice(0);
  802. seen.set(val, copy_1);
  803. copy_1.forEach(function (child, i) {
  804. copy_1[i] = cloneDeepHelper(child, seen);
  805. });
  806. return copy_1;
  807. }
  808. case "[object Object]":
  809. {
  810. if (seen.has(val)) return seen.get(val);
  811. var copy_2 = Object.create(Object.getPrototypeOf(val));
  812. seen.set(val, copy_2);
  813. Object.keys(val).forEach(function (key) {
  814. copy_2[key] = cloneDeepHelper(val[key], seen);
  815. });
  816. return copy_2;
  817. }
  818. default:
  819. return val;
  820. }
  821. }
  822. function getEnv() {
  823. if (typeof process !== 'undefined' && process.env.NODE_ENV) {
  824. return process.env.NODE_ENV;
  825. }
  826. return 'development';
  827. }
  828. function isEnv(env) {
  829. return getEnv() === env;
  830. }
  831. function isProduction() {
  832. return isEnv('production') === true;
  833. }
  834. function isDevelopment() {
  835. return isEnv('development') === true;
  836. }
  837. function isTest() {
  838. return isEnv('test') === true;
  839. }
  840. function tryFunctionOrLogError(f) {
  841. try {
  842. return f();
  843. } catch (e) {
  844. if (console.error) {
  845. console.error(e);
  846. }
  847. }
  848. }
  849. function graphQLResultHasError(result) {
  850. return result.errors && result.errors.length;
  851. }
  852. function deepFreeze(o) {
  853. Object.freeze(o);
  854. Object.getOwnPropertyNames(o).forEach(function (prop) {
  855. if (o[prop] !== null && (typeof o[prop] === 'object' || typeof o[prop] === 'function') && !Object.isFrozen(o[prop])) {
  856. deepFreeze(o[prop]);
  857. }
  858. });
  859. return o;
  860. }
  861. function maybeDeepFreeze(obj) {
  862. if (isDevelopment() || isTest()) {
  863. var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
  864. if (!symbolIsPolyfilled) {
  865. return deepFreeze(obj);
  866. }
  867. }
  868. return obj;
  869. }
  870. var hasOwnProperty = Object.prototype.hasOwnProperty;
  871. function mergeDeep() {
  872. var sources = [];
  873. for (var _i = 0; _i < arguments.length; _i++) {
  874. sources[_i] = arguments[_i];
  875. }
  876. return mergeDeepArray(sources);
  877. }
  878. function mergeDeepArray(sources) {
  879. var target = sources[0] || {};
  880. var count = sources.length;
  881. if (count > 1) {
  882. var pastCopies = [];
  883. target = shallowCopyForMerge(target, pastCopies);
  884. for (var i = 1; i < count; ++i) {
  885. target = mergeHelper(target, sources[i], pastCopies);
  886. }
  887. }
  888. return target;
  889. }
  890. function isObject(obj) {
  891. return obj !== null && typeof obj === 'object';
  892. }
  893. function mergeHelper(target, source, pastCopies) {
  894. if (isObject(source) && isObject(target)) {
  895. if (Object.isExtensible && !Object.isExtensible(target)) {
  896. target = shallowCopyForMerge(target, pastCopies);
  897. }
  898. Object.keys(source).forEach(function (sourceKey) {
  899. var sourceValue = source[sourceKey];
  900. if (hasOwnProperty.call(target, sourceKey)) {
  901. var targetValue = target[sourceKey];
  902. if (sourceValue !== targetValue) {
  903. target[sourceKey] = mergeHelper(shallowCopyForMerge(targetValue, pastCopies), sourceValue, pastCopies);
  904. }
  905. } else {
  906. target[sourceKey] = sourceValue;
  907. }
  908. });
  909. return target;
  910. }
  911. return source;
  912. }
  913. function shallowCopyForMerge(value, pastCopies) {
  914. if (value !== null && typeof value === 'object' && pastCopies.indexOf(value) < 0) {
  915. if (Array.isArray(value)) {
  916. value = value.slice(0);
  917. } else {
  918. value = (0, _tslib.__assign)({
  919. __proto__: Object.getPrototypeOf(value)
  920. }, value);
  921. }
  922. pastCopies.push(value);
  923. }
  924. return value;
  925. }
  926. var haveWarned = Object.create({});
  927. function warnOnceInDevelopment(msg, type) {
  928. if (type === void 0) {
  929. type = 'warn';
  930. }
  931. if (!isProduction() && !haveWarned[msg]) {
  932. if (!isTest()) {
  933. haveWarned[msg] = true;
  934. }
  935. if (type === 'error') {
  936. console.error(msg);
  937. } else {
  938. console.warn(msg);
  939. }
  940. }
  941. }
  942. function stripSymbols(data) {
  943. return JSON.parse(JSON.stringify(data));
  944. }