@apollo/client 3.7.7 → 3.7.9
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/README.md +1 -1
- package/apollo-client.cjs +169 -162
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +20 -21
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +20 -21
- package/cache/inmemory/helpers.d.ts +2 -2
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js +2 -2
- package/cache/inmemory/helpers.js.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/core/types.d.ts +5 -6
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/package.json +12 -12
- package/testing/core/mocking/mockLink.d.ts +2 -2
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/common/arrays.d.ts +1 -0
- package/utilities/common/arrays.d.ts.map +1 -1
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +167 -90
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +2 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/utilities.cjs +170 -102
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +170 -102
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/transform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAYL,KAAK,GAEN,MAAM,SAAS,CAAC;AAKjB,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AAY;wBAA3D,CAA2D,CAC9D,CAAC;wBACF,IAAI,cAAc,EAAE;4BAClB,OAAO,IAAI,CAAC;yBACb;qBACF;gBACH,CAAC;aACF;SACF,CAAC,CAAC;KACJ;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { invariant } from '../globals';\n\nimport {\n DocumentNode,\n SelectionNode,\n SelectionSetNode,\n OperationDefinitionNode,\n FieldNode,\n DirectiveNode,\n FragmentDefinitionNode,\n ArgumentNode,\n FragmentSpreadNode,\n VariableDefinitionNode,\n VariableNode,\n visit,\n ASTNode,\n} from 'graphql';\n\n// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)\ntype Kind = any;\n\nimport {\n checkDocument,\n getOperationDefinition,\n getFragmentDefinition,\n getFragmentDefinitions,\n getMainDefinition,\n} from './getFromAST';\nimport { filterInPlace } from '../common/filterInPlace';\nimport { isField, isInlineFragment } from './storeUtils';\nimport {\n createFragmentMap,\n FragmentMap,\n} from './fragments';\n\nexport type RemoveNodeConfig<N> = {\n name?: string;\n test?: (node: N) => boolean;\n remove?: boolean;\n};\n\nexport type GetNodeConfig<N> = {\n name?: string;\n test?: (node: N) => boolean;\n};\n\nexport type RemoveDirectiveConfig = RemoveNodeConfig<DirectiveNode>;\nexport type GetDirectiveConfig = GetNodeConfig<DirectiveNode>;\nexport type RemoveArgumentsConfig = RemoveNodeConfig<ArgumentNode>;\nexport type GetFragmentSpreadConfig = GetNodeConfig<FragmentSpreadNode>;\nexport type RemoveFragmentSpreadConfig = RemoveNodeConfig<FragmentSpreadNode>;\nexport type RemoveFragmentDefinitionConfig = RemoveNodeConfig<\n FragmentDefinitionNode\n>;\nexport type RemoveVariableDefinitionConfig = RemoveNodeConfig<\n VariableDefinitionNode\n>;\n\nconst TYPENAME_FIELD: FieldNode = {\n kind: 'Field' as Kind,\n name: {\n kind: 'Name' as Kind,\n value: '__typename',\n },\n};\n\nfunction isEmpty(\n op: OperationDefinitionNode | FragmentDefinitionNode,\n fragmentMap: FragmentMap,\n): boolean {\n return !op || op.selectionSet.selections.every(\n selection => selection.kind === 'FragmentSpread' &&\n isEmpty(fragmentMap[selection.name.value], fragmentMap)\n );\n}\n\nfunction nullIfDocIsEmpty(doc: DocumentNode) {\n return isEmpty(\n getOperationDefinition(doc) || getFragmentDefinition(doc),\n createFragmentMap(getFragmentDefinitions(doc)),\n )\n ? null\n : doc;\n}\n\nfunction getDirectiveMatcher(\n directives: (RemoveDirectiveConfig | GetDirectiveConfig)[],\n) {\n return function directiveMatcher(directive: DirectiveNode) {\n return directives.some(\n dir =>\n (dir.name && dir.name === directive.name.value) ||\n (dir.test && dir.test(directive)),\n );\n };\n}\n\nexport function removeDirectivesFromDocument(\n directives: RemoveDirectiveConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n const variablesInUse: Record<string, boolean> = Object.create(null);\n let variablesToRemove: RemoveArgumentsConfig[] = [];\n\n const fragmentSpreadsInUse: Record<string, boolean> = Object.create(null);\n let fragmentSpreadsToRemove: RemoveFragmentSpreadConfig[] = [];\n\n let modifiedDoc = nullIfDocIsEmpty(\n visit(doc, {\n Variable: {\n enter(node, _key, parent) {\n // Store each variable that's referenced as part of an argument\n // (excluding operation definition variables), so we know which\n // variables are being used. If we later want to remove a variable\n // we'll first check to see if it's being used, before continuing with\n // the removal.\n if (\n (parent as VariableDefinitionNode).kind !== 'VariableDefinition'\n ) {\n variablesInUse[node.name.value] = true;\n }\n },\n },\n\n Field: {\n enter(node) {\n if (directives && node.directives) {\n // If `remove` is set to true for a directive, and a directive match\n // is found for a field, remove the field as well.\n const shouldRemoveField = directives.some(\n directive => directive.remove,\n );\n\n if (\n shouldRemoveField &&\n node.directives &&\n node.directives.some(getDirectiveMatcher(directives))\n ) {\n if (node.arguments) {\n // Store field argument variables so they can be removed\n // from the operation definition.\n node.arguments.forEach(arg => {\n if (arg.value.kind === 'Variable') {\n variablesToRemove.push({\n name: (arg.value as VariableNode).name.value,\n });\n }\n });\n }\n\n if (node.selectionSet) {\n // Store fragment spread names so they can be removed from the\n // document.\n getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(\n frag => {\n fragmentSpreadsToRemove.push({\n name: frag.name.value,\n });\n },\n );\n }\n\n // Remove the field.\n return null;\n }\n }\n },\n },\n\n FragmentSpread: {\n enter(node) {\n // Keep track of referenced fragment spreads. This is used to\n // determine if top level fragment definitions should be removed.\n fragmentSpreadsInUse[node.name.value] = true;\n },\n },\n\n Directive: {\n enter(node) {\n // If a matching directive is found, remove it.\n if (getDirectiveMatcher(directives)(node)) {\n return null;\n }\n },\n },\n }),\n );\n\n // If we've removed fields with arguments, make sure the associated\n // variables are also removed from the rest of the document, as long as they\n // aren't being used elsewhere.\n if (\n modifiedDoc &&\n filterInPlace(variablesToRemove, v => !!v.name && !variablesInUse[v.name]).length\n ) {\n modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);\n }\n\n // If we've removed selection sets with fragment spreads, make sure the\n // associated fragment definitions are also removed from the rest of the\n // document, as long as they aren't being used elsewhere.\n if (\n modifiedDoc &&\n filterInPlace(fragmentSpreadsToRemove, fs => !!fs.name && !fragmentSpreadsInUse[fs.name])\n .length\n ) {\n modifiedDoc = removeFragmentSpreadFromDocument(\n fragmentSpreadsToRemove,\n modifiedDoc,\n );\n }\n\n return modifiedDoc;\n}\n\nexport const addTypenameToDocument = Object.assign(function <\n TNode extends ASTNode\n>(\n doc: TNode\n): TNode {\n return visit(doc, {\n SelectionSet: {\n enter(node, _key, parent) {\n // Don't add __typename to OperationDefinitions.\n if (\n parent &&\n (parent as OperationDefinitionNode).kind === 'OperationDefinition'\n ) {\n return;\n }\n\n // No changes if no selections.\n const { selections } = node;\n if (!selections) {\n return;\n }\n\n // If selections already have a __typename, or are part of an\n // introspection query, do nothing.\n const skip = selections.some(selection => {\n return (\n isField(selection) &&\n (selection.name.value === '__typename' ||\n selection.name.value.lastIndexOf('__', 0) === 0)\n );\n });\n if (skip) {\n return;\n }\n\n // If this SelectionSet is @export-ed as an input variable, it should\n // not have a __typename field (see issue #4691).\n const field = parent as FieldNode;\n if (\n isField(field) &&\n field.directives &&\n field.directives.some(d => d.name.value === 'export')\n ) {\n return;\n }\n\n // Create and return a new SelectionSet with a __typename Field.\n return {\n ...node,\n selections: [...selections, TYPENAME_FIELD],\n };\n },\n },\n });\n}, {\n added(field: FieldNode): boolean {\n return field === TYPENAME_FIELD;\n },\n});\n\nconst connectionRemoveConfig = {\n test: (directive: DirectiveNode) => {\n const willRemove = directive.name.value === 'connection';\n if (willRemove) {\n if (\n !directive.arguments ||\n !directive.arguments.some(arg => arg.name.value === 'key')\n ) {\n invariant.warn(\n 'Removing an @connection directive even though it does not have a key. ' +\n 'You may want to use the key parameter to specify a store key.',\n );\n }\n }\n\n return willRemove;\n },\n};\n\nexport function removeConnectionDirectiveFromDocument(doc: DocumentNode) {\n return removeDirectivesFromDocument(\n [connectionRemoveConfig],\n checkDocument(doc),\n );\n}\n\nfunction hasDirectivesInSelectionSet(\n directives: GetDirectiveConfig[],\n selectionSet: SelectionSetNode | undefined,\n nestedCheck = true,\n): boolean {\n return (\n !!selectionSet &&\n selectionSet.selections &&\n selectionSet.selections.some(selection =>\n hasDirectivesInSelection(directives, selection, nestedCheck),\n )\n );\n}\n\nfunction hasDirectivesInSelection(\n directives: GetDirectiveConfig[],\n selection: SelectionNode,\n nestedCheck = true,\n): boolean {\n if (!isField(selection)) {\n return true;\n }\n\n if (!selection.directives) {\n return false;\n }\n\n return (\n selection.directives.some(getDirectiveMatcher(directives)) ||\n (nestedCheck &&\n hasDirectivesInSelectionSet(\n directives,\n selection.selectionSet,\n nestedCheck,\n ))\n );\n}\n\nfunction getArgumentMatcher(config: RemoveArgumentsConfig[]) {\n return function argumentMatcher(argument: ArgumentNode) {\n return config.some(\n (aConfig: RemoveArgumentsConfig) =>\n argument.value &&\n argument.value.kind === 'Variable' &&\n argument.value.name &&\n (aConfig.name === argument.value.name.value ||\n (aConfig.test && aConfig.test(argument))),\n );\n };\n}\n\nexport function removeArgumentsFromDocument(\n config: RemoveArgumentsConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n const argMatcher = getArgumentMatcher(config);\n\n return nullIfDocIsEmpty(\n visit(doc, {\n OperationDefinition: {\n enter(node) {\n return {\n ...node,\n // Remove matching top level variables definitions.\n variableDefinitions: node.variableDefinitions ? node.variableDefinitions.filter(\n varDef =>\n !config.some(arg => arg.name === varDef.variable.name.value),\n ) : [],\n };\n },\n },\n\n Field: {\n enter(node) {\n // If `remove` is set to true for an argument, and an argument match\n // is found for a field, remove the field as well.\n const shouldRemoveField = config.some(argConfig => argConfig.remove);\n\n if (shouldRemoveField) {\n let argMatchCount = 0;\n if (node.arguments) {\n node.arguments.forEach(arg => {\n if (argMatcher(arg)) {\n argMatchCount += 1;\n }\n });\n }\n\n if (argMatchCount === 1) {\n return null;\n }\n }\n },\n },\n\n Argument: {\n enter(node) {\n // Remove all matching arguments.\n if (argMatcher(node)) {\n return null;\n }\n },\n },\n }),\n );\n}\n\nexport function removeFragmentSpreadFromDocument(\n config: RemoveFragmentSpreadConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n function enter(\n node: FragmentSpreadNode | FragmentDefinitionNode,\n ): null | void {\n if (config.some(def => def.name === node.name.value)) {\n return null;\n }\n }\n\n return nullIfDocIsEmpty(\n visit(doc, {\n FragmentSpread: { enter },\n FragmentDefinition: { enter },\n }),\n );\n}\n\nfunction getAllFragmentSpreadsFromSelectionSet(\n selectionSet: SelectionSetNode,\n): FragmentSpreadNode[] {\n const allFragments: FragmentSpreadNode[] = [];\n\n selectionSet.selections.forEach(selection => {\n if (\n (isField(selection) || isInlineFragment(selection)) &&\n selection.selectionSet\n ) {\n getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(\n frag => allFragments.push(frag),\n );\n } else if (selection.kind === 'FragmentSpread') {\n allFragments.push(selection);\n }\n });\n\n return allFragments;\n}\n\n// If the incoming document is a query, return it as is. Otherwise, build a\n// new document containing a query operation based on the selection set\n// of the previous main operation.\nexport function buildQueryFromSelectionSet(\n document: DocumentNode,\n): DocumentNode {\n const definition = getMainDefinition(document);\n const definitionOperation = (<OperationDefinitionNode>definition).operation;\n\n if (definitionOperation === 'query') {\n // Already a query, so return the existing document.\n return document;\n }\n\n // Build a new query using the selection set of the main operation.\n const modifiedDoc = visit(document, {\n OperationDefinition: {\n enter(node) {\n return {\n ...node,\n operation: 'query',\n };\n },\n },\n });\n return modifiedDoc;\n}\n\n// Remove fields / selection sets that include an @client directive.\nexport function removeClientSetsFromDocument(\n document: DocumentNode,\n): DocumentNode | null {\n checkDocument(document);\n\n let modifiedDoc = removeDirectivesFromDocument(\n [\n {\n test: (directive: DirectiveNode) => directive.name.value === 'client',\n remove: true,\n },\n ],\n document,\n );\n\n // After a fragment definition has had its @client related document\n // sets removed, if the only field it has left is a __typename field,\n // remove the entire fragment operation to prevent it from being fired\n // on the server.\n if (modifiedDoc) {\n modifiedDoc = visit(modifiedDoc, {\n FragmentDefinition: {\n enter(node) {\n if (node.selectionSet) {\n const isTypenameOnly = node.selectionSet.selections.every(\n selection =>\n isField(selection) && selection.name.value === '__typename',\n );\n if (isTypenameOnly) {\n return null;\n }\n }\n },\n },\n });\n }\n\n return modifiedDoc;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/utilities/graphql/transform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAWL,KAAK,EAEL,IAAI,GAGL,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;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AI,CAAC,KAAK,EAA5B,CAA4B,CAAC,EAAE;YACpD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAED,OAAO,gBAAgB,CACrB,KAAK,CAAC,GAAG,EAAE;QACT,cAAc,EAAE,EAAE,KAAK,OAAA,EAAE;QACzB,kBAAkB,EAAE,EAAE,KAAK,OAAA,EAAE;KAC9B,CAAC,CACH,CAAC;AACJ,CAAC;AAKD,MAAM,UAAU,0BAA0B,CACxC,QAAsB;IAEtB,IAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAM,mBAAmB,GAA6B,UAAW,CAAC,SAAS,CAAC;IAE5E,IAAI,mBAAmB,KAAK,OAAO,EAAE;QAEnC,OAAO,QAAQ,CAAC;KACjB;IAGD,IAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,EAAE;QAClC,mBAAmB,EAAE;YACnB,KAAK,YAAC,IAAI;gBACR,6BACK,IAAI,KACP,SAAS,EAAE,OAAO,IAClB;YACJ,CAAC;SACF;KACF,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC;AAGD,MAAM,UAAU,4BAA4B,CAC1C,QAAsB;IAEtB,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExB,IAAI,WAAW,GAAG,4BAA4B,CAC5C;QACE;YACE,IAAI,EAAE,UAAC,SAAwB,IAAK,OAAA,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAjC,CAAiC;YACrE,MAAM,EAAE,IAAI;SACb;KACF,EACD,QAAQ,CACT,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { invariant } from '../globals';\n\nimport {\n DocumentNode,\n SelectionNode,\n SelectionSetNode,\n OperationDefinitionNode,\n FieldNode,\n DirectiveNode,\n FragmentDefinitionNode,\n ArgumentNode,\n FragmentSpreadNode,\n VariableDefinitionNode,\n visit,\n ASTNode,\n Kind,\n ASTVisitor,\n InlineFragmentNode,\n} from 'graphql';\n\nimport {\n checkDocument,\n getOperationDefinition,\n getFragmentDefinition,\n getFragmentDefinitions,\n getMainDefinition,\n} from './getFromAST';\nimport { isField } from './storeUtils';\nimport {\n createFragmentMap,\n FragmentMap,\n} from './fragments';\nimport { isArray } from '../common/arrays';\n\nexport type RemoveNodeConfig<N> = {\n name?: string;\n test?: (node: N) => boolean;\n remove?: boolean;\n};\n\nexport type GetNodeConfig<N> = {\n name?: string;\n test?: (node: N) => boolean;\n};\n\nexport type RemoveDirectiveConfig = RemoveNodeConfig<DirectiveNode>;\nexport type GetDirectiveConfig = GetNodeConfig<DirectiveNode>;\nexport type RemoveArgumentsConfig = RemoveNodeConfig<ArgumentNode>;\nexport type GetFragmentSpreadConfig = GetNodeConfig<FragmentSpreadNode>;\nexport type RemoveFragmentSpreadConfig = RemoveNodeConfig<FragmentSpreadNode>;\nexport type RemoveFragmentDefinitionConfig = RemoveNodeConfig<\n FragmentDefinitionNode\n>;\nexport type RemoveVariableDefinitionConfig = RemoveNodeConfig<\n VariableDefinitionNode\n>;\n\nconst TYPENAME_FIELD: FieldNode = {\n kind: Kind.FIELD,\n name: {\n kind: Kind.NAME,\n value: '__typename',\n },\n};\n\nfunction isEmpty(\n op: OperationDefinitionNode | FragmentDefinitionNode,\n fragmentMap: FragmentMap,\n): boolean {\n return !op || op.selectionSet.selections.every(\n selection => selection.kind === Kind.FRAGMENT_SPREAD &&\n isEmpty(fragmentMap[selection.name.value], fragmentMap)\n );\n}\n\nfunction nullIfDocIsEmpty(doc: DocumentNode) {\n return isEmpty(\n getOperationDefinition(doc) || getFragmentDefinition(doc),\n createFragmentMap(getFragmentDefinitions(doc)),\n )\n ? null\n : doc;\n}\n\nfunction getDirectiveMatcher(\n directives: (RemoveDirectiveConfig | GetDirectiveConfig)[],\n) {\n const nameSet = new Set<string>();\n const tests: Array<(directive: DirectiveNode) => boolean> = [];\n directives.forEach(directive => {\n if (directive.name) {\n nameSet.add(directive.name);\n } else if (directive.test) {\n tests.push(directive.test);\n }\n });\n\n return (directive: DirectiveNode) => (\n nameSet.has(directive.name.value) ||\n tests.some(test => test(directive))\n );\n}\n\n// Helper interface and function used by removeDirectivesFromDocument to keep\n// track of variable references and fragments spreads found within a given\n// operation or fragment definition.\ninterface InternalInUseInfo {\n variables: Set<string>;\n fragmentSpreads: Set<string>;\n // Set to true when we deliberately remove a fragment definition, so we can\n // make sure also to remove dangling ...spreads that refer to it.\n removed?: boolean;\n // Populated by the populateTransitiveVars helper function below.\n transitiveVars?: Set<string>;\n}\nfunction makeInUseGetterFunction<TKey>(defaultKey: TKey) {\n const map = new Map<TKey, InternalInUseInfo>();\n\n return function inUseGetterFunction(\n key: TKey = defaultKey\n ): InternalInUseInfo {\n let inUse = map.get(key);\n if (!inUse) {\n map.set(key, inUse = {\n // Variable and fragment spread names used directly within this\n // operation or fragment definition, as identified by key. These sets\n // will be populated during the first traversal of the document in\n // removeDirectivesFromDocument below.\n variables: new Set,\n fragmentSpreads: new Set,\n });\n }\n return inUse;\n };\n}\n\nexport function removeDirectivesFromDocument(\n directives: RemoveDirectiveConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n // Passing empty strings to makeInUseGetterFunction means we handle anonymous\n // operations as if their names were \"\". Anonymous fragment definitions are\n // not supposed to be possible, but the same default naming strategy seems\n // appropriate for that case as well.\n const getInUseByOperationName = makeInUseGetterFunction<string>(\"\");\n const getInUseByFragmentName = makeInUseGetterFunction<string>(\"\");\n const getInUse = (\n ancestors: readonly (ASTNode | readonly ASTNode[])[],\n ): InternalInUseInfo | null => {\n for (\n let p = 0, ancestor: ASTNode | readonly ASTNode[];\n p < ancestors.length && (ancestor = ancestors[p]);\n ++p\n ) {\n if (isArray(ancestor)) continue;\n if (ancestor.kind === Kind.OPERATION_DEFINITION) {\n // If an operation is anonymous, we use the empty string as its key.\n return getInUseByOperationName(ancestor.name && ancestor.name.value);\n }\n if (ancestor.kind === Kind.FRAGMENT_DEFINITION) {\n return getInUseByFragmentName(ancestor.name.value);\n }\n }\n invariant.error(`Could not find operation or fragment`);\n return null;\n };\n\n let operationCount = 0;\n for (let i = doc.definitions.length - 1; i >= 0; --i) {\n if (doc.definitions[i].kind === Kind.OPERATION_DEFINITION) {\n ++operationCount;\n }\n }\n\n const directiveMatcher = getDirectiveMatcher(directives);\n const hasRemoveDirective = directives.some(directive => directive.remove);\n const shouldRemoveField = (\n nodeDirectives: FieldNode[\"directives\"]\n ) => (\n hasRemoveDirective &&\n nodeDirectives &&\n nodeDirectives.some(directiveMatcher)\n );\n\n const originalFragmentDefsByPath = new Map<string, FragmentDefinitionNode>();\n\n // Any time the first traversal of the document below makes a change like\n // removing a fragment (by returning null), this variable should be set to\n // true. Once it becomes true, it should never be set to false again. If this\n // variable remains false throughout the traversal, then we can return the\n // original doc immediately without any modifications.\n let firstVisitMadeChanges = false;\n\n const fieldOrInlineFragmentVisitor: ASTVisitor = {\n enter(node: FieldNode | InlineFragmentNode) {\n if (shouldRemoveField(node.directives)) {\n firstVisitMadeChanges = true;\n return null;\n }\n },\n };\n\n const docWithoutDirectiveSubtrees = visit(doc, {\n // These two AST node types share the same implementation, defined above.\n Field: fieldOrInlineFragmentVisitor,\n InlineFragment: fieldOrInlineFragmentVisitor,\n\n VariableDefinition: {\n enter() {\n // VariableDefinition nodes do not count as variables in use, though\n // they do contain Variable nodes that might be visited below. To avoid\n // counting variable declarations as usages, we skip visiting the\n // contents of this VariableDefinition node by returning false.\n return false;\n },\n },\n\n Variable: {\n enter(node, _key, _parent, _path, ancestors) {\n const inUse = getInUse(ancestors);\n if (inUse) {\n inUse.variables.add(node.name.value);\n }\n },\n },\n\n FragmentSpread: {\n enter(node, _key, _parent, _path, ancestors) {\n if (shouldRemoveField(node.directives)) {\n firstVisitMadeChanges = true;\n return null;\n }\n const inUse = getInUse(ancestors);\n if (inUse) {\n inUse.fragmentSpreads.add(node.name.value);\n }\n // We might like to remove this FragmentSpread by returning null here if\n // the corresponding FragmentDefinition node is also going to be removed\n // by the logic below, but we can't control the relative order of those\n // events, so we have to postpone the removal of dangling FragmentSpread\n // nodes until after the current visit of the document has finished.\n },\n },\n\n FragmentDefinition: {\n enter(node, _key, _parent, path) {\n originalFragmentDefsByPath.set(JSON.stringify(path), node);\n },\n leave(node, _key, _parent, path) {\n const originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));\n if (node === originalNode) {\n // If the FragmentNode received by this leave function is identical to\n // the one received by the corresponding enter function (above), then\n // the visitor must not have made any changes within this\n // FragmentDefinition node. This fragment definition may still be\n // removed if there are no ...spread references to it, but it won't be\n // removed just because it has only a __typename field.\n return node;\n }\n\n if (\n // This logic applies only if the document contains one or more\n // operations, since removing all fragments from a document containing\n // only fragments makes the document useless.\n operationCount > 0 &&\n node.selectionSet.selections.every(selection => (\n selection.kind === Kind.FIELD &&\n selection.name.value === '__typename'\n ))\n ) {\n // This is a somewhat opinionated choice: if a FragmentDefinition ends\n // up having no fields other than __typename, we remove the whole\n // fragment definition, and later prune ...spread references to it.\n getInUseByFragmentName(node.name.value).removed = true;\n firstVisitMadeChanges = true;\n return null;\n }\n },\n },\n\n Directive: {\n leave(node) {\n // If a matching directive is found, remove the directive itself. Note\n // that this does not remove the target (field, argument, etc) of the\n // directive, but only the directive itself.\n if (directiveMatcher(node)) {\n firstVisitMadeChanges = true;\n return null;\n }\n },\n },\n });\n\n if (!firstVisitMadeChanges) {\n // If our first pass did not change anything about the document, then there\n // is no cleanup we need to do, and we can return the original doc.\n return doc;\n }\n\n // Utility for making sure inUse.transitiveVars is recursively populated.\n // Because this logic assumes inUse.fragmentSpreads has been completely\n // populated and inUse.removed has been set if appropriate,\n // populateTransitiveVars must be called after that information has been\n // collected by the first traversal of the document.\n const populateTransitiveVars = (\n inUse: InternalInUseInfo,\n ) => {\n if (!inUse.transitiveVars) {\n inUse.transitiveVars = new Set(inUse.variables);\n if (!inUse.removed) {\n inUse.fragmentSpreads.forEach(childFragmentName => {\n populateTransitiveVars(\n getInUseByFragmentName(childFragmentName)\n ).transitiveVars!.forEach(varName => {\n inUse.transitiveVars!.add(varName);\n });\n });\n }\n }\n return inUse;\n };\n\n // Since we've been keeping track of fragment spreads used by particular\n // operations and fragment definitions, we now need to compute the set of all\n // spreads used (transitively) by any operations in the document.\n const allFragmentNamesUsed = new Set<string>();\n docWithoutDirectiveSubtrees.definitions.forEach(def => {\n if (def.kind === Kind.OPERATION_DEFINITION) {\n populateTransitiveVars(\n getInUseByOperationName(def.name && def.name.value)\n ).fragmentSpreads.forEach(childFragmentName => {\n allFragmentNamesUsed.add(childFragmentName);\n });\n } else if (\n def.kind === Kind.FRAGMENT_DEFINITION &&\n // If there are no operations in the document, then all fragment\n // definitions count as usages of their own fragment names. This heuristic\n // prevents accidentally removing all fragment definitions from the\n // document just because it contains no operations that use the fragments.\n operationCount === 0 &&\n !getInUseByFragmentName(def.name.value).removed\n ) {\n allFragmentNamesUsed.add(def.name.value);\n }\n });\n // Now that we have added all fragment spreads used by operations to the\n // allFragmentNamesUsed set, we can complete the set by transitively adding\n // all fragment spreads used by those fragments, and so on.\n allFragmentNamesUsed.forEach(fragmentName => {\n // Once all the childFragmentName strings added here have been seen already,\n // the top-level allFragmentNamesUsed.forEach loop will terminate.\n populateTransitiveVars(\n getInUseByFragmentName(fragmentName)\n ).fragmentSpreads.forEach(childFragmentName => {\n allFragmentNamesUsed.add(childFragmentName);\n });\n });\n\n const fragmentWillBeRemoved = (\n fragmentName: string,\n ) => !!(\n // A fragment definition will be removed if there are no spreads that refer\n // to it, or the fragment was explicitly removed because it had no fields\n // other than __typename.\n !allFragmentNamesUsed.has(fragmentName) ||\n getInUseByFragmentName(fragmentName).removed\n );\n\n const enterVisitor: ASTVisitor = {\n enter(node: FragmentSpreadNode | FragmentDefinitionNode) {\n if (fragmentWillBeRemoved(node.name.value)) {\n return null;\n }\n },\n };\n\n return nullIfDocIsEmpty(visit(docWithoutDirectiveSubtrees, {\n // If the fragment is going to be removed, then leaving any dangling\n // FragmentSpread nodes with the same name would be a mistake.\n FragmentSpread: enterVisitor,\n\n // This is where the fragment definition is actually removed.\n FragmentDefinition: enterVisitor,\n\n OperationDefinition: {\n leave(node) {\n // Upon leaving each operation in the depth-first AST traversal, prune\n // any variables that are declared by the operation but unused within.\n if (node.variableDefinitions) {\n const usedVariableNames = populateTransitiveVars(\n // If an operation is anonymous, we use the empty string as its key.\n getInUseByOperationName(node.name && node.name.value)\n ).transitiveVars!;\n\n // According to the GraphQL spec, all variables declared by an\n // operation must either be used by that operation or used by some\n // fragment included transitively into that operation:\n // https://spec.graphql.org/draft/#sec-All-Variables-Used\n //\n // To stay on the right side of this validation rule, if/when we\n // remove the last $var references from an operation or its fragments,\n // we must also remove the corresponding $var declaration from the\n // enclosing operation. This pruning applies only to operations and\n // not fragment definitions, at the moment. Fragments may be able to\n // declare variables eventually, but today they can only consume them.\n if (usedVariableNames.size < node.variableDefinitions.length) {\n return {\n ...node,\n variableDefinitions: node.variableDefinitions.filter(\n varDef => usedVariableNames.has(varDef.variable.name.value),\n ),\n };\n }\n }\n },\n },\n }));\n}\n\nexport const addTypenameToDocument = Object.assign(function <\n TNode extends ASTNode\n>(\n doc: TNode\n): TNode {\n return visit(doc, {\n SelectionSet: {\n enter(node, _key, parent) {\n // Don't add __typename to OperationDefinitions.\n if (\n parent &&\n (parent as OperationDefinitionNode).kind === Kind.OPERATION_DEFINITION\n ) {\n return;\n }\n\n // No changes if no selections.\n const { selections } = node;\n if (!selections) {\n return;\n }\n\n // If selections already have a __typename, or are part of an\n // introspection query, do nothing.\n const skip = selections.some(selection => {\n return (\n isField(selection) &&\n (selection.name.value === '__typename' ||\n selection.name.value.lastIndexOf('__', 0) === 0)\n );\n });\n if (skip) {\n return;\n }\n\n // If this SelectionSet is @export-ed as an input variable, it should\n // not have a __typename field (see issue #4691).\n const field = parent as FieldNode;\n if (\n isField(field) &&\n field.directives &&\n field.directives.some(d => d.name.value === 'export')\n ) {\n return;\n }\n\n // Create and return a new SelectionSet with a __typename Field.\n return {\n ...node,\n selections: [...selections, TYPENAME_FIELD],\n };\n },\n },\n });\n}, {\n added(field: FieldNode): boolean {\n return field === TYPENAME_FIELD;\n },\n});\n\nconst connectionRemoveConfig = {\n test: (directive: DirectiveNode) => {\n const willRemove = directive.name.value === 'connection';\n if (willRemove) {\n if (\n !directive.arguments ||\n !directive.arguments.some(arg => arg.name.value === 'key')\n ) {\n invariant.warn(\n 'Removing an @connection directive even though it does not have a key. ' +\n 'You may want to use the key parameter to specify a store key.',\n );\n }\n }\n\n return willRemove;\n },\n};\n\nexport function removeConnectionDirectiveFromDocument(doc: DocumentNode) {\n return removeDirectivesFromDocument(\n [connectionRemoveConfig],\n checkDocument(doc),\n );\n}\n\nfunction hasDirectivesInSelectionSet(\n directives: GetDirectiveConfig[],\n selectionSet: SelectionSetNode | undefined,\n nestedCheck = true,\n): boolean {\n return (\n !!selectionSet &&\n selectionSet.selections &&\n selectionSet.selections.some(selection =>\n hasDirectivesInSelection(directives, selection, nestedCheck),\n )\n );\n}\n\nfunction hasDirectivesInSelection(\n directives: GetDirectiveConfig[],\n selection: SelectionNode,\n nestedCheck = true,\n): boolean {\n if (!isField(selection)) {\n return true;\n }\n\n if (!selection.directives) {\n return false;\n }\n\n return (\n selection.directives.some(getDirectiveMatcher(directives)) ||\n (nestedCheck &&\n hasDirectivesInSelectionSet(\n directives,\n selection.selectionSet,\n nestedCheck,\n ))\n );\n}\n\nfunction getArgumentMatcher(config: RemoveArgumentsConfig[]) {\n return function argumentMatcher(argument: ArgumentNode) {\n return config.some(\n (aConfig: RemoveArgumentsConfig) =>\n argument.value &&\n argument.value.kind === Kind.VARIABLE &&\n argument.value.name &&\n (aConfig.name === argument.value.name.value ||\n (aConfig.test && aConfig.test(argument))),\n );\n };\n}\n\nexport function removeArgumentsFromDocument(\n config: RemoveArgumentsConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n const argMatcher = getArgumentMatcher(config);\n\n return nullIfDocIsEmpty(\n visit(doc, {\n OperationDefinition: {\n enter(node) {\n return {\n ...node,\n // Remove matching top level variables definitions.\n variableDefinitions: node.variableDefinitions ? node.variableDefinitions.filter(\n varDef =>\n !config.some(arg => arg.name === varDef.variable.name.value),\n ) : [],\n };\n },\n },\n\n Field: {\n enter(node) {\n // If `remove` is set to true for an argument, and an argument match\n // is found for a field, remove the field as well.\n const shouldRemoveField = config.some(argConfig => argConfig.remove);\n\n if (shouldRemoveField) {\n let argMatchCount = 0;\n if (node.arguments) {\n node.arguments.forEach(arg => {\n if (argMatcher(arg)) {\n argMatchCount += 1;\n }\n });\n }\n\n if (argMatchCount === 1) {\n return null;\n }\n }\n },\n },\n\n Argument: {\n enter(node) {\n // Remove all matching arguments.\n if (argMatcher(node)) {\n return null;\n }\n },\n },\n }),\n );\n}\n\nexport function removeFragmentSpreadFromDocument(\n config: RemoveFragmentSpreadConfig[],\n doc: DocumentNode,\n): DocumentNode | null {\n function enter(\n node: FragmentSpreadNode | FragmentDefinitionNode,\n ): null | void {\n if (config.some(def => def.name === node.name.value)) {\n return null;\n }\n }\n\n return nullIfDocIsEmpty(\n visit(doc, {\n FragmentSpread: { enter },\n FragmentDefinition: { enter },\n }),\n );\n}\n\n// If the incoming document is a query, return it as is. Otherwise, build a\n// new document containing a query operation based on the selection set\n// of the previous main operation.\nexport function buildQueryFromSelectionSet(\n document: DocumentNode,\n): DocumentNode {\n const definition = getMainDefinition(document);\n const definitionOperation = (<OperationDefinitionNode>definition).operation;\n\n if (definitionOperation === 'query') {\n // Already a query, so return the existing document.\n return document;\n }\n\n // Build a new query using the selection set of the main operation.\n const modifiedDoc = visit(document, {\n OperationDefinition: {\n enter(node) {\n return {\n ...node,\n operation: 'query',\n };\n },\n },\n });\n return modifiedDoc;\n}\n\n// Remove fields / selection sets that include an @client directive.\nexport function removeClientSetsFromDocument(\n document: DocumentNode,\n): DocumentNode | null {\n checkDocument(document);\n\n let modifiedDoc = removeDirectivesFromDocument(\n [\n {\n test: (directive: DirectiveNode) => directive.name.value === 'client',\n remove: true,\n },\n ],\n document,\n );\n\n return modifiedDoc;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Concast.d.ts","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA0B,UAAU,EAAE,MAAM,cAAc,CAAC;AAIxF,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAOxC,KAAK,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA+BtD,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAI3C,OAAO,CAAC,SAAS,CAA0B;IAM3C,OAAO,CAAC,GAAG,CAAC,CAAgC;gBAIhC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Concast.d.ts","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA0B,UAAU,EAAE,MAAM,cAAc,CAAC;AAIxF,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAOxC,KAAK,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA+BtD,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAI3C,OAAO,CAAC,SAAS,CAA0B;IAM3C,OAAO,CAAC,GAAG,CAAC,CAAgC;gBAIhC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAiC1E,OAAO,CAAC,OAAO,CAA0B;IAEzC,OAAO,CAAC,KAAK;IAeb,OAAO,CAAC,kBAAkB;IAkBnB,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IASjC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAgB3C,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,MAAM,CAAwB;IACtC,SAAgB,OAAO,aAGpB;IAIH,OAAO,CAAC,MAAM,CAAC,CAA+B;IAI9C,OAAO,CAAC,QAAQ,CAyDd;IAEF,OAAO,CAAC,mBAAmB,CAAiC;IAE5D,OAAO,CAAC,MAAM;IAmBd,UAAU,CAAC,QAAQ,EAAE,kBAAkB;IAWhC,MAAM,WAAY,GAAG,UAI3B;CACF;AAED,KAAK,kBAAkB,GAAG,CACxB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,EACrC,GAAG,CAAC,EAAE,GAAG,KACN,GAAG,CAAC"}
|
|
@@ -38,9 +38,9 @@ var Concast = (function (_super) {
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
complete: function () {
|
|
41
|
-
var sub =
|
|
41
|
+
var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
|
42
42
|
if (sub !== null) {
|
|
43
|
-
var value =
|
|
43
|
+
var value = sources.shift();
|
|
44
44
|
if (!value) {
|
|
45
45
|
if (sub)
|
|
46
46
|
setTimeout(function () { return s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W,QAA4B;QACrC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAC,MAAM,EAAE,GAAG;YACvC,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,GAAG,IAAI,CAAC;gBACd,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAQH,cAAC;AAAD,CAAC,AAhND,CAAgC,UAAU,GAgNzC;;AASD,qBAAqB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { Observable, Observer, ObservableSubscription, Subscriber } from \"./Observable\";\nimport { iterateObserversSafely } from \"./iteration\";\nimport { fixObservableSubclass } from \"./subclassing\";\n\ntype MaybeAsync<T> = T | PromiseLike<T>;\n\nfunction isPromiseLike<T>(value: MaybeAsync<T>): value is PromiseLike<T> {\n return value && typeof (value as any).then === \"function\";\n}\n\n// Any individual Source<T> can be an Observable<T> or a promise for one.\ntype Source<T> = MaybeAsync<Observable<T>>;\n\nexport type ConcastSourcesIterable<T> = Iterable<Source<T>>;\nexport type ConcastSourcesArray<T> = Array<Source<T>>;\n\n// A Concast<T> observable concatenates the given sources into a single\n// non-overlapping sequence of Ts, automatically unwrapping any promises,\n// and broadcasts the T elements of that sequence to any number of\n// subscribers, all without creating a bunch of intermediary Observable\n// wrapper objects.\n//\n// Even though any number of observers can subscribe to the Concast, each\n// source observable is guaranteed to receive at most one subscribe call,\n// and the results are multicast to all observers.\n//\n// In addition to broadcasting every next/error message to this.observers,\n// the Concast stores the most recent message using this.latest, so any\n// new observers can immediately receive the latest message, even if it\n// was originally delivered in the past. This behavior means we can assume\n// every active observer in this.observers has received the same most\n// recent message.\n//\n// With the exception of this.latest replay, a Concast is a \"hot\"\n// observable in the sense that it does not replay past results from the\n// beginning of time for each new observer.\n//\n// Could we have used some existing RxJS class instead? Concast<T> is\n// similar to a BehaviorSubject<T>, because it is multicast and redelivers\n// the latest next/error message to new subscribers. Unlike Subject<T>,\n// Concast<T> does not expose an Observer<T> interface (this.handlers is\n// intentionally private), since Concast<T> gets its inputs from the\n// concatenated sources. If we ever switch to RxJS, there may be some\n// value in reusing their code, but for now we use zen-observable, which\n// does not contain any Subject implementations.\nexport class Concast<T> extends Observable<T> {\n // Active observers receiving broadcast messages. Thanks to this.latest,\n // we can assume all observers in this Set have received the same most\n // recent message, though possibly at different times in the past.\n private observers = new Set<Observer<T>>();\n\n // This property starts off undefined to indicate the initial\n // subscription has not yet begun, then points to each source\n // subscription in turn, and finally becomes null after the sources have\n // been exhausted. After that, it stays null.\n private sub?: ObservableSubscription | null;\n\n // Not only can the individual elements of the iterable be promises, but\n // also the iterable itself can be wrapped in a promise.\n constructor(sources: MaybeAsync<ConcastSourcesIterable<T>> | Subscriber<T>) {\n super(observer => {\n this.addObserver(observer);\n return () => this.removeObserver(observer);\n });\n\n // Suppress rejection warnings for this.promise, since it's perfectly\n // acceptable to pay no attention to this.promise if you're consuming\n // the results through the normal observable API.\n this.promise.catch(_ => {});\n\n // If someone accidentally tries to create a Concast using a subscriber\n // function, recover by creating an Observable from that subscriber and\n // using it as the source.\n if (typeof sources === \"function\") {\n sources = [new Observable(sources)];\n }\n\n if (isPromiseLike(sources)) {\n sources.then(\n iterable => this.start(iterable),\n this.handlers.error,\n );\n } else {\n this.start(sources);\n }\n }\n\n // A consumable array of source observables, incrementally consumed\n // each time this.handlers.complete is called.\n private sources: Source<T>[];\n\n private start(sources: ConcastSourcesIterable<T>) {\n if (this.sub !== void 0) return;\n\n // In practice, sources is most often simply an Array of observables.\n // TODO Consider using sources[Symbol.iterator]() to take advantage\n // of the laziness of non-Array iterables.\n this.sources = Array.from(sources);\n\n // Calling this.handlers.complete() kicks off consumption of the first\n // source observable. It's tempting to do this step lazily in\n // addObserver, but this.promise can be accessed without calling\n // addObserver, so consumption needs to begin eagerly.\n this.handlers.complete();\n }\n\n private deliverLastMessage(observer: Observer<T>) {\n if (this.latest) {\n const nextOrError = this.latest[0];\n const method = observer[nextOrError];\n if (method) {\n method.call(observer, this.latest[1]);\n }\n // If the subscription is already closed, and the last message was\n // a 'next' message, simulate delivery of the final 'complete'\n // message again.\n if (this.sub === null &&\n nextOrError === \"next\" &&\n observer.complete) {\n observer.complete();\n }\n }\n }\n\n public addObserver(observer: Observer<T>) {\n if (!this.observers.has(observer)) {\n // Immediately deliver the most recent message, so we can always\n // be sure all observers have the latest information.\n this.deliverLastMessage(observer);\n this.observers.add(observer);\n }\n }\n\n public removeObserver(observer: Observer<T>) {\n if (\n this.observers.delete(observer) &&\n this.observers.size < 1\n ) {\n // In case there are still any listeners in this.nextResultListeners, and\n // no error or completion has been broadcast yet, make sure those\n // observers have a chance to run and then remove themselves from\n // this.observers.\n this.handlers.complete();\n }\n }\n\n // Any Concast object can be trivially converted to a Promise, without\n // having to create a new wrapper Observable. This promise provides an\n // easy way to observe the final state of the Concast.\n private resolve: (result?: T | PromiseLike<T>) => void;\n private reject: (reason: any) => void;\n public readonly promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n\n // Name and argument of the most recently invoked observer method, used\n // to deliver latest results immediately to new observers.\n private latest?: [\"next\", T] | [\"error\", any];\n\n // Bound handler functions that can be reused for every internal\n // subscription.\n private handlers = {\n next: (result: T) => {\n if (this.sub !== null) {\n this.latest = [\"next\", result];\n this.notify(\"next\", result);\n iterateObserversSafely(this.observers, \"next\", result);\n }\n },\n\n error: (error: any) => {\n const { sub } = this;\n if (sub !== null) {\n // Delay unsubscribing from the underlying subscription slightly,\n // so that immediately subscribing another observer can keep the\n // subscription active.\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n this.latest = [\"error\", error];\n this.reject(error);\n this.notify(\"error\", error);\n iterateObserversSafely(this.observers, \"error\", error);\n }\n },\n\n complete: () => {\n const { sub } = this;\n if (sub !== null) {\n const value = this.sources.shift();\n if (!value) {\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n if (this.latest &&\n this.latest[0] === \"next\") {\n this.resolve(this.latest[1]);\n } else {\n this.resolve();\n }\n this.notify(\"complete\");\n // We do not store this.latest = [\"complete\"], because doing so\n // discards useful information about the previous next (or\n // error) message. Instead, if new observers subscribe after\n // this Concast has completed, they will receive the final\n // 'next' message (unless there was an error) immediately\n // followed by a 'complete' message (see addObserver).\n iterateObserversSafely(this.observers, \"complete\");\n } else if (isPromiseLike(value)) {\n value.then(obs => this.sub = obs.subscribe(this.handlers));\n } else {\n this.sub = value.subscribe(this.handlers);\n }\n }\n },\n };\n\n private nextResultListeners = new Set<NextResultListener>();\n\n private notify(\n method: Parameters<NextResultListener>[0],\n arg?: Parameters<NextResultListener>[1],\n ) {\n const { nextResultListeners } = this;\n if (nextResultListeners.size) {\n // Replacing this.nextResultListeners first ensures it does not grow while\n // we are iterating over it, potentially leading to infinite loops.\n this.nextResultListeners = new Set;\n nextResultListeners.forEach(listener => listener(method, arg));\n }\n }\n\n // We need a way to run callbacks just *before* the next result (or error or\n // completion) is delivered by this Concast, so we can be sure any code that\n // runs as a result of delivering that result/error observes the effects of\n // running the callback(s). It was tempting to reuse the Observer type instead\n // of introducing NextResultListener, but that messes with the sizing and\n // maintenance of this.observers, and ends up being more code overall.\n beforeNext(callback: NextResultListener) {\n let called = false;\n this.nextResultListeners.add((method, arg) => {\n if (!called) {\n called = true;\n callback(method, arg);\n }\n });\n }\n\n // A public way to abort observation and broadcast.\n public cancel = (reason: any) => {\n this.reject(reason);\n this.sources = [];\n this.handlers.complete();\n }\n}\n\ntype NextResultListener = (\n method: \"next\" | \"error\" | \"complete\",\n arg?: any,\n) => any;\n\n// Necessary because the Concast constructor has a different signature\n// than the Observable constructor.\nfixObservableSubclass(Concast);\n"]}
|
|
1
|
+
{"version":3,"file":"Concast.js","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAgD,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAA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AAG,IAAI,CAAC;gBACd,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAQH,cAAC;AAAD,CAAC,AAxND,CAAgC,UAAU,GAwNzC;;AASD,qBAAqB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { Observable, Observer, ObservableSubscription, Subscriber } from \"./Observable\";\nimport { iterateObserversSafely } from \"./iteration\";\nimport { fixObservableSubclass } from \"./subclassing\";\n\ntype MaybeAsync<T> = T | PromiseLike<T>;\n\nfunction isPromiseLike<T>(value: MaybeAsync<T>): value is PromiseLike<T> {\n return value && typeof (value as any).then === \"function\";\n}\n\n// Any individual Source<T> can be an Observable<T> or a promise for one.\ntype Source<T> = MaybeAsync<Observable<T>>;\n\nexport type ConcastSourcesIterable<T> = Iterable<Source<T>>;\nexport type ConcastSourcesArray<T> = Array<Source<T>>;\n\n// A Concast<T> observable concatenates the given sources into a single\n// non-overlapping sequence of Ts, automatically unwrapping any promises,\n// and broadcasts the T elements of that sequence to any number of\n// subscribers, all without creating a bunch of intermediary Observable\n// wrapper objects.\n//\n// Even though any number of observers can subscribe to the Concast, each\n// source observable is guaranteed to receive at most one subscribe call,\n// and the results are multicast to all observers.\n//\n// In addition to broadcasting every next/error message to this.observers,\n// the Concast stores the most recent message using this.latest, so any\n// new observers can immediately receive the latest message, even if it\n// was originally delivered in the past. This behavior means we can assume\n// every active observer in this.observers has received the same most\n// recent message.\n//\n// With the exception of this.latest replay, a Concast is a \"hot\"\n// observable in the sense that it does not replay past results from the\n// beginning of time for each new observer.\n//\n// Could we have used some existing RxJS class instead? Concast<T> is\n// similar to a BehaviorSubject<T>, because it is multicast and redelivers\n// the latest next/error message to new subscribers. Unlike Subject<T>,\n// Concast<T> does not expose an Observer<T> interface (this.handlers is\n// intentionally private), since Concast<T> gets its inputs from the\n// concatenated sources. If we ever switch to RxJS, there may be some\n// value in reusing their code, but for now we use zen-observable, which\n// does not contain any Subject implementations.\nexport class Concast<T> extends Observable<T> {\n // Active observers receiving broadcast messages. Thanks to this.latest,\n // we can assume all observers in this Set have received the same most\n // recent message, though possibly at different times in the past.\n private observers = new Set<Observer<T>>();\n\n // This property starts off undefined to indicate the initial\n // subscription has not yet begun, then points to each source\n // subscription in turn, and finally becomes null after the sources have\n // been exhausted. After that, it stays null.\n private sub?: ObservableSubscription | null;\n\n // Not only can the individual elements of the iterable be promises, but\n // also the iterable itself can be wrapped in a promise.\n constructor(sources: MaybeAsync<ConcastSourcesIterable<T>> | Subscriber<T>) {\n super(observer => {\n this.addObserver(observer);\n return () => this.removeObserver(observer);\n });\n\n // Suppress rejection warnings for this.promise, since it's perfectly\n // acceptable to pay no attention to this.promise if you're consuming\n // the results through the normal observable API.\n this.promise.catch(_ => {});\n\n // If someone accidentally tries to create a Concast using a subscriber\n // function, recover by creating an Observable from that subscriber and\n // using it as the source.\n if (typeof sources === \"function\") {\n sources = [new Observable(sources)];\n }\n\n if (isPromiseLike(sources)) {\n sources.then(\n iterable => this.start(iterable),\n this.handlers.error,\n );\n } else {\n this.start(sources);\n }\n }\n\n // A consumable array of source observables, incrementally consumed each time\n // this.handlers.complete is called. This private field is not initialized\n // until the concast.start method is called, which can happen asynchronously\n // if a Promise is passed to the Concast constructor, so undefined is a\n // possible value for this.sources before concast.start is called.\n private sources: Source<T>[] | undefined;\n\n private start(sources: ConcastSourcesIterable<T>) {\n if (this.sub !== void 0) return;\n\n // In practice, sources is most often simply an Array of observables.\n // TODO Consider using sources[Symbol.iterator]() to take advantage\n // of the laziness of non-Array iterables.\n this.sources = Array.from(sources);\n\n // Calling this.handlers.complete() kicks off consumption of the first\n // source observable. It's tempting to do this step lazily in\n // addObserver, but this.promise can be accessed without calling\n // addObserver, so consumption needs to begin eagerly.\n this.handlers.complete();\n }\n\n private deliverLastMessage(observer: Observer<T>) {\n if (this.latest) {\n const nextOrError = this.latest[0];\n const method = observer[nextOrError];\n if (method) {\n method.call(observer, this.latest[1]);\n }\n // If the subscription is already closed, and the last message was\n // a 'next' message, simulate delivery of the final 'complete'\n // message again.\n if (this.sub === null &&\n nextOrError === \"next\" &&\n observer.complete) {\n observer.complete();\n }\n }\n }\n\n public addObserver(observer: Observer<T>) {\n if (!this.observers.has(observer)) {\n // Immediately deliver the most recent message, so we can always\n // be sure all observers have the latest information.\n this.deliverLastMessage(observer);\n this.observers.add(observer);\n }\n }\n\n public removeObserver(observer: Observer<T>) {\n if (\n this.observers.delete(observer) &&\n this.observers.size < 1\n ) {\n // In case there are still any listeners in this.nextResultListeners, and\n // no error or completion has been broadcast yet, make sure those\n // observers have a chance to run and then remove themselves from\n // this.observers.\n this.handlers.complete();\n }\n }\n\n // Any Concast object can be trivially converted to a Promise, without\n // having to create a new wrapper Observable. This promise provides an\n // easy way to observe the final state of the Concast.\n private resolve: (result?: T | PromiseLike<T>) => void;\n private reject: (reason: any) => void;\n public readonly promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n\n // Name and argument of the most recently invoked observer method, used\n // to deliver latest results immediately to new observers.\n private latest?: [\"next\", T] | [\"error\", any];\n\n // Bound handler functions that can be reused for every internal\n // subscription.\n private handlers = {\n next: (result: T) => {\n if (this.sub !== null) {\n this.latest = [\"next\", result];\n this.notify(\"next\", result);\n iterateObserversSafely(this.observers, \"next\", result);\n }\n },\n\n error: (error: any) => {\n const { sub } = this;\n if (sub !== null) {\n // Delay unsubscribing from the underlying subscription slightly,\n // so that immediately subscribing another observer can keep the\n // subscription active.\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n this.latest = [\"error\", error];\n this.reject(error);\n this.notify(\"error\", error);\n iterateObserversSafely(this.observers, \"error\", error);\n }\n },\n\n complete: () => {\n const { sub, sources = [] } = this;\n if (sub !== null) {\n // If complete is called before concast.start, this.sources may be\n // undefined, so we use a default value of [] for sources. That works\n // here because it falls into the if (!value) {...} block, which\n // appropriately terminates the Concast, even if this.sources might\n // eventually have been initialized to a non-empty array.\n const value = sources.shift();\n if (!value) {\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n if (this.latest &&\n this.latest[0] === \"next\") {\n this.resolve(this.latest[1]);\n } else {\n this.resolve();\n }\n this.notify(\"complete\");\n // We do not store this.latest = [\"complete\"], because doing so\n // discards useful information about the previous next (or\n // error) message. Instead, if new observers subscribe after\n // this Concast has completed, they will receive the final\n // 'next' message (unless there was an error) immediately\n // followed by a 'complete' message (see addObserver).\n iterateObserversSafely(this.observers, \"complete\");\n } else if (isPromiseLike(value)) {\n value.then(obs => this.sub = obs.subscribe(this.handlers));\n } else {\n this.sub = value.subscribe(this.handlers);\n }\n }\n },\n };\n\n private nextResultListeners = new Set<NextResultListener>();\n\n private notify(\n method: Parameters<NextResultListener>[0],\n arg?: Parameters<NextResultListener>[1],\n ) {\n const { nextResultListeners } = this;\n if (nextResultListeners.size) {\n // Replacing this.nextResultListeners first ensures it does not grow while\n // we are iterating over it, potentially leading to infinite loops.\n this.nextResultListeners = new Set;\n nextResultListeners.forEach(listener => listener(method, arg));\n }\n }\n\n // We need a way to run callbacks just *before* the next result (or error or\n // completion) is delivered by this Concast, so we can be sure any code that\n // runs as a result of delivering that result/error observes the effects of\n // running the callback(s). It was tempting to reuse the Observer type instead\n // of introducing NextResultListener, but that messes with the sizing and\n // maintenance of this.observers, and ends up being more code overall.\n beforeNext(callback: NextResultListener) {\n let called = false;\n this.nextResultListeners.add((method, arg) => {\n if (!called) {\n called = true;\n callback(method, arg);\n }\n });\n }\n\n // A public way to abort observation and broadcast.\n public cancel = (reason: any) => {\n this.reject(reason);\n this.sources = [];\n this.handlers.complete();\n }\n}\n\ntype NextResultListener = (\n method: \"next\" | \"error\" | \"complete\",\n arg?: any,\n) => any;\n\n// Necessary because the Concast constructor has a different signature\n// than the Observable constructor.\nfixObservableSubclass(Concast);\n"]}
|
package/utilities/utilities.cjs
CHANGED
|
@@ -423,26 +423,20 @@ function getDefaultValues(definition) {
|
|
|
423
423
|
return defaultValues;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (test.call(this, elem, i, array)) {
|
|
430
|
-
array[target++] = elem;
|
|
431
|
-
}
|
|
432
|
-
}, context);
|
|
433
|
-
array.length = target;
|
|
434
|
-
return array;
|
|
426
|
+
var isArray = Array.isArray;
|
|
427
|
+
function isNonEmptyArray(value) {
|
|
428
|
+
return Array.isArray(value) && value.length > 0;
|
|
435
429
|
}
|
|
436
430
|
|
|
437
431
|
var TYPENAME_FIELD = {
|
|
438
|
-
kind:
|
|
432
|
+
kind: graphql.Kind.FIELD,
|
|
439
433
|
name: {
|
|
440
|
-
kind:
|
|
434
|
+
kind: graphql.Kind.NAME,
|
|
441
435
|
value: '__typename',
|
|
442
436
|
},
|
|
443
437
|
};
|
|
444
438
|
function isEmpty(op, fragmentMap) {
|
|
445
|
-
return !op || op.selectionSet.selections.every(function (selection) { return selection.kind ===
|
|
439
|
+
return !op || op.selectionSet.selections.every(function (selection) { return selection.kind === graphql.Kind.FRAGMENT_SPREAD &&
|
|
446
440
|
isEmpty(fragmentMap[selection.name.value], fragmentMap); });
|
|
447
441
|
}
|
|
448
442
|
function nullIfDocIsEmpty(doc) {
|
|
@@ -451,84 +445,190 @@ function nullIfDocIsEmpty(doc) {
|
|
|
451
445
|
: doc;
|
|
452
446
|
}
|
|
453
447
|
function getDirectiveMatcher(directives) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
448
|
+
var nameSet = new Set();
|
|
449
|
+
var tests = [];
|
|
450
|
+
directives.forEach(function (directive) {
|
|
451
|
+
if (directive.name) {
|
|
452
|
+
nameSet.add(directive.name);
|
|
453
|
+
}
|
|
454
|
+
else if (directive.test) {
|
|
455
|
+
tests.push(directive.test);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
return function (directive) { return (nameSet.has(directive.name.value) ||
|
|
459
|
+
tests.some(function (test) { return test(directive); })); };
|
|
460
|
+
}
|
|
461
|
+
function makeInUseGetterFunction(defaultKey) {
|
|
462
|
+
var map = new Map();
|
|
463
|
+
return function inUseGetterFunction(key) {
|
|
464
|
+
if (key === void 0) { key = defaultKey; }
|
|
465
|
+
var inUse = map.get(key);
|
|
466
|
+
if (!inUse) {
|
|
467
|
+
map.set(key, inUse = {
|
|
468
|
+
variables: new Set,
|
|
469
|
+
fragmentSpreads: new Set,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return inUse;
|
|
459
473
|
};
|
|
460
474
|
}
|
|
461
475
|
function removeDirectivesFromDocument(directives, doc) {
|
|
462
|
-
var
|
|
463
|
-
var
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
476
|
+
var getInUseByOperationName = makeInUseGetterFunction("");
|
|
477
|
+
var getInUseByFragmentName = makeInUseGetterFunction("");
|
|
478
|
+
var getInUse = function (ancestors) {
|
|
479
|
+
for (var p = 0, ancestor = void 0; p < ancestors.length && (ancestor = ancestors[p]); ++p) {
|
|
480
|
+
if (isArray(ancestor))
|
|
481
|
+
continue;
|
|
482
|
+
if (ancestor.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
483
|
+
return getInUseByOperationName(ancestor.name && ancestor.name.value);
|
|
484
|
+
}
|
|
485
|
+
if (ancestor.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
|
486
|
+
return getInUseByFragmentName(ancestor.name.value);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
__DEV__ && globals.invariant.error("Could not find operation or fragment");
|
|
490
|
+
return null;
|
|
491
|
+
};
|
|
492
|
+
var operationCount = 0;
|
|
493
|
+
for (var i = doc.definitions.length - 1; i >= 0; --i) {
|
|
494
|
+
if (doc.definitions[i].kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
495
|
+
++operationCount;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
var directiveMatcher = getDirectiveMatcher(directives);
|
|
499
|
+
var hasRemoveDirective = directives.some(function (directive) { return directive.remove; });
|
|
500
|
+
var shouldRemoveField = function (nodeDirectives) { return (hasRemoveDirective &&
|
|
501
|
+
nodeDirectives &&
|
|
502
|
+
nodeDirectives.some(directiveMatcher)); };
|
|
503
|
+
var originalFragmentDefsByPath = new Map();
|
|
504
|
+
var firstVisitMadeChanges = false;
|
|
505
|
+
var fieldOrInlineFragmentVisitor = {
|
|
506
|
+
enter: function (node) {
|
|
507
|
+
if (shouldRemoveField(node.directives)) {
|
|
508
|
+
firstVisitMadeChanges = true;
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
var docWithoutDirectiveSubtrees = graphql.visit(doc, {
|
|
514
|
+
Field: fieldOrInlineFragmentVisitor,
|
|
515
|
+
InlineFragment: fieldOrInlineFragmentVisitor,
|
|
516
|
+
VariableDefinition: {
|
|
517
|
+
enter: function () {
|
|
518
|
+
return false;
|
|
519
|
+
},
|
|
520
|
+
},
|
|
467
521
|
Variable: {
|
|
468
|
-
enter: function (node, _key,
|
|
469
|
-
|
|
470
|
-
|
|
522
|
+
enter: function (node, _key, _parent, _path, ancestors) {
|
|
523
|
+
var inUse = getInUse(ancestors);
|
|
524
|
+
if (inUse) {
|
|
525
|
+
inUse.variables.add(node.name.value);
|
|
471
526
|
}
|
|
472
527
|
},
|
|
473
528
|
},
|
|
474
|
-
|
|
475
|
-
enter: function (node) {
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (arg.value.kind === 'Variable') {
|
|
484
|
-
variablesToRemove.push({
|
|
485
|
-
name: arg.value.name.value,
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
if (node.selectionSet) {
|
|
491
|
-
getAllFragmentSpreadsFromSelectionSet(node.selectionSet).forEach(function (frag) {
|
|
492
|
-
fragmentSpreadsToRemove.push({
|
|
493
|
-
name: frag.name.value,
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
529
|
+
FragmentSpread: {
|
|
530
|
+
enter: function (node, _key, _parent, _path, ancestors) {
|
|
531
|
+
if (shouldRemoveField(node.directives)) {
|
|
532
|
+
firstVisitMadeChanges = true;
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
var inUse = getInUse(ancestors);
|
|
536
|
+
if (inUse) {
|
|
537
|
+
inUse.fragmentSpreads.add(node.name.value);
|
|
499
538
|
}
|
|
500
539
|
},
|
|
501
540
|
},
|
|
502
|
-
|
|
503
|
-
enter: function (node) {
|
|
504
|
-
|
|
541
|
+
FragmentDefinition: {
|
|
542
|
+
enter: function (node, _key, _parent, path) {
|
|
543
|
+
originalFragmentDefsByPath.set(JSON.stringify(path), node);
|
|
544
|
+
},
|
|
545
|
+
leave: function (node, _key, _parent, path) {
|
|
546
|
+
var originalNode = originalFragmentDefsByPath.get(JSON.stringify(path));
|
|
547
|
+
if (node === originalNode) {
|
|
548
|
+
return node;
|
|
549
|
+
}
|
|
550
|
+
if (operationCount > 0 &&
|
|
551
|
+
node.selectionSet.selections.every(function (selection) { return (selection.kind === graphql.Kind.FIELD &&
|
|
552
|
+
selection.name.value === '__typename'); })) {
|
|
553
|
+
getInUseByFragmentName(node.name.value).removed = true;
|
|
554
|
+
firstVisitMadeChanges = true;
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
505
557
|
},
|
|
506
558
|
},
|
|
507
559
|
Directive: {
|
|
508
|
-
|
|
509
|
-
if (
|
|
560
|
+
leave: function (node) {
|
|
561
|
+
if (directiveMatcher(node)) {
|
|
562
|
+
firstVisitMadeChanges = true;
|
|
510
563
|
return null;
|
|
511
564
|
}
|
|
512
565
|
},
|
|
513
566
|
},
|
|
514
|
-
})
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
modifiedDoc = removeArgumentsFromDocument(variablesToRemove, modifiedDoc);
|
|
518
|
-
}
|
|
519
|
-
if (modifiedDoc &&
|
|
520
|
-
filterInPlace(fragmentSpreadsToRemove, function (fs) { return !!fs.name && !fragmentSpreadsInUse[fs.name]; })
|
|
521
|
-
.length) {
|
|
522
|
-
modifiedDoc = removeFragmentSpreadFromDocument(fragmentSpreadsToRemove, modifiedDoc);
|
|
567
|
+
});
|
|
568
|
+
if (!firstVisitMadeChanges) {
|
|
569
|
+
return doc;
|
|
523
570
|
}
|
|
524
|
-
|
|
571
|
+
var populateTransitiveVars = function (inUse) {
|
|
572
|
+
if (!inUse.transitiveVars) {
|
|
573
|
+
inUse.transitiveVars = new Set(inUse.variables);
|
|
574
|
+
if (!inUse.removed) {
|
|
575
|
+
inUse.fragmentSpreads.forEach(function (childFragmentName) {
|
|
576
|
+
populateTransitiveVars(getInUseByFragmentName(childFragmentName)).transitiveVars.forEach(function (varName) {
|
|
577
|
+
inUse.transitiveVars.add(varName);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return inUse;
|
|
583
|
+
};
|
|
584
|
+
var allFragmentNamesUsed = new Set();
|
|
585
|
+
docWithoutDirectiveSubtrees.definitions.forEach(function (def) {
|
|
586
|
+
if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
587
|
+
populateTransitiveVars(getInUseByOperationName(def.name && def.name.value)).fragmentSpreads.forEach(function (childFragmentName) {
|
|
588
|
+
allFragmentNamesUsed.add(childFragmentName);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
else if (def.kind === graphql.Kind.FRAGMENT_DEFINITION &&
|
|
592
|
+
operationCount === 0 &&
|
|
593
|
+
!getInUseByFragmentName(def.name.value).removed) {
|
|
594
|
+
allFragmentNamesUsed.add(def.name.value);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
allFragmentNamesUsed.forEach(function (fragmentName) {
|
|
598
|
+
populateTransitiveVars(getInUseByFragmentName(fragmentName)).fragmentSpreads.forEach(function (childFragmentName) {
|
|
599
|
+
allFragmentNamesUsed.add(childFragmentName);
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
var fragmentWillBeRemoved = function (fragmentName) { return !!(!allFragmentNamesUsed.has(fragmentName) ||
|
|
603
|
+
getInUseByFragmentName(fragmentName).removed); };
|
|
604
|
+
var enterVisitor = {
|
|
605
|
+
enter: function (node) {
|
|
606
|
+
if (fragmentWillBeRemoved(node.name.value)) {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
return nullIfDocIsEmpty(graphql.visit(docWithoutDirectiveSubtrees, {
|
|
612
|
+
FragmentSpread: enterVisitor,
|
|
613
|
+
FragmentDefinition: enterVisitor,
|
|
614
|
+
OperationDefinition: {
|
|
615
|
+
leave: function (node) {
|
|
616
|
+
if (node.variableDefinitions) {
|
|
617
|
+
var usedVariableNames_1 = populateTransitiveVars(getInUseByOperationName(node.name && node.name.value)).transitiveVars;
|
|
618
|
+
if (usedVariableNames_1.size < node.variableDefinitions.length) {
|
|
619
|
+
return tslib.__assign(tslib.__assign({}, node), { variableDefinitions: node.variableDefinitions.filter(function (varDef) { return usedVariableNames_1.has(varDef.variable.name.value); }) });
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
}));
|
|
525
625
|
}
|
|
526
626
|
var addTypenameToDocument = Object.assign(function (doc) {
|
|
527
627
|
return graphql.visit(doc, {
|
|
528
628
|
SelectionSet: {
|
|
529
629
|
enter: function (node, _key, parent) {
|
|
530
630
|
if (parent &&
|
|
531
|
-
parent.kind ===
|
|
631
|
+
parent.kind === graphql.Kind.OPERATION_DEFINITION) {
|
|
532
632
|
return;
|
|
533
633
|
}
|
|
534
634
|
var selections = node.selections;
|
|
@@ -578,7 +678,7 @@ function getArgumentMatcher(config) {
|
|
|
578
678
|
return function argumentMatcher(argument) {
|
|
579
679
|
return config.some(function (aConfig) {
|
|
580
680
|
return argument.value &&
|
|
581
|
-
argument.value.kind ===
|
|
681
|
+
argument.value.kind === graphql.Kind.VARIABLE &&
|
|
582
682
|
argument.value.name &&
|
|
583
683
|
(aConfig.name === argument.value.name.value ||
|
|
584
684
|
(aConfig.test && aConfig.test(argument)));
|
|
@@ -633,19 +733,6 @@ function removeFragmentSpreadFromDocument(config, doc) {
|
|
|
633
733
|
FragmentDefinition: { enter: enter },
|
|
634
734
|
}));
|
|
635
735
|
}
|
|
636
|
-
function getAllFragmentSpreadsFromSelectionSet(selectionSet) {
|
|
637
|
-
var allFragments = [];
|
|
638
|
-
selectionSet.selections.forEach(function (selection) {
|
|
639
|
-
if ((isField(selection) || isInlineFragment(selection)) &&
|
|
640
|
-
selection.selectionSet) {
|
|
641
|
-
getAllFragmentSpreadsFromSelectionSet(selection.selectionSet).forEach(function (frag) { return allFragments.push(frag); });
|
|
642
|
-
}
|
|
643
|
-
else if (selection.kind === 'FragmentSpread') {
|
|
644
|
-
allFragments.push(selection);
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
return allFragments;
|
|
648
|
-
}
|
|
649
736
|
function buildQueryFromSelectionSet(document) {
|
|
650
737
|
var definition = getMainDefinition(document);
|
|
651
738
|
var definitionOperation = definition.operation;
|
|
@@ -669,22 +756,6 @@ function removeClientSetsFromDocument(document) {
|
|
|
669
756
|
remove: true,
|
|
670
757
|
},
|
|
671
758
|
], document);
|
|
672
|
-
if (modifiedDoc) {
|
|
673
|
-
modifiedDoc = graphql.visit(modifiedDoc, {
|
|
674
|
-
FragmentDefinition: {
|
|
675
|
-
enter: function (node) {
|
|
676
|
-
if (node.selectionSet) {
|
|
677
|
-
var isTypenameOnly = node.selectionSet.selections.every(function (selection) {
|
|
678
|
-
return isField(selection) && selection.name.value === '__typename';
|
|
679
|
-
});
|
|
680
|
-
if (isTypenameOnly) {
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
759
|
return modifiedDoc;
|
|
689
760
|
}
|
|
690
761
|
|
|
@@ -1085,9 +1156,9 @@ var Concast = (function (_super) {
|
|
|
1085
1156
|
}
|
|
1086
1157
|
},
|
|
1087
1158
|
complete: function () {
|
|
1088
|
-
var sub =
|
|
1159
|
+
var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
|
1089
1160
|
if (sub !== null) {
|
|
1090
|
-
var value =
|
|
1161
|
+
var value = sources.shift();
|
|
1091
1162
|
if (!value) {
|
|
1092
1163
|
if (sub)
|
|
1093
1164
|
setTimeout(function () { return sub.unsubscribe(); });
|
|
@@ -1181,10 +1252,6 @@ var Concast = (function (_super) {
|
|
|
1181
1252
|
}(zenObservableTs.Observable));
|
|
1182
1253
|
fixObservableSubclass(Concast);
|
|
1183
1254
|
|
|
1184
|
-
function isNonEmptyArray(value) {
|
|
1185
|
-
return Array.isArray(value) && value.length > 0;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1255
|
function isExecutionPatchIncrementalResult(value) {
|
|
1189
1256
|
return "incremental" in value;
|
|
1190
1257
|
}
|
|
@@ -1287,6 +1354,7 @@ exports.hasAllDirectives = hasAllDirectives;
|
|
|
1287
1354
|
exports.hasAnyDirectives = hasAnyDirectives;
|
|
1288
1355
|
exports.hasClientExports = hasClientExports;
|
|
1289
1356
|
exports.hasDirectives = hasDirectives;
|
|
1357
|
+
exports.isArray = isArray;
|
|
1290
1358
|
exports.isDocumentNode = isDocumentNode;
|
|
1291
1359
|
exports.isField = isField;
|
|
1292
1360
|
exports.isInlineFragment = isInlineFragment;
|