diff --git a/CHANGELOG.md b/CHANGELOG.md index 01baf7a975b..43d3391614a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Apollo Client 3.1.0 + +## Bug Fixes + +- Rework interdependencies between `@apollo/client/*` entry points, so that CommonJS and ESM modules are supported equally well, without any duplication of shared code.
+ [@benjamn](https://github.com/benjamn) in [#6058](https://github.com/apollographql/apollo-client/pull/6058) + ## Apollo Client 3.0.2 ## Bug Fixes diff --git a/config/entryPoints.js b/config/entryPoints.js new file mode 100644 index 00000000000..4c1a5cf1396 --- /dev/null +++ b/config/entryPoints.js @@ -0,0 +1,109 @@ +const entryPoints = [ + { dirs: [], bundleName: "main" }, + { dirs: ['cache'] }, + { dirs: ['core'] }, + { dirs: ['errors'] }, + { dirs: ['link', 'batch'] }, + { dirs: ['link', 'batch-http'] }, + { dirs: ['link', 'context'] }, + { dirs: ['link', 'core'] }, + { dirs: ['link', 'error'] }, + { dirs: ['link', 'http'] }, + { dirs: ['link', 'retry'] }, + { dirs: ['link', 'schema'] }, + { dirs: ['link', 'utils'] }, + { dirs: ['link', 'ws'] }, + { dirs: ['react'] }, + { dirs: ['react', 'components'] }, + { dirs: ['react', 'context'] }, + { dirs: ['react', 'data'] }, + { dirs: ['react', 'hoc'] }, + { dirs: ['react', 'hooks'] }, + { dirs: ['react', 'parser'] }, + { dirs: ['react', 'ssr'] }, + { dirs: ['utilities'] }, + { dirs: ['testing'], extensions: [".js", ".jsx"] }, +]; + +const lookupTrie = Object.create(null); +entryPoints.forEach(info => { + let node = lookupTrie; + info.dirs.forEach(dir => { + const dirs = node.dirs || (node.dirs = Object.create(null)); + node = dirs[dir] || (dirs[dir] = { isEntry: false }); + }); + node.isEntry = true; +}); + +exports.forEach = function(callback, context) { + entryPoints.forEach(callback, context); +}; + +exports.map = function map(callback, context) { + return entryPoints.map(callback, context); +}; + +const path = require("path").posix; + +exports.check = function (id, parentId) { + const resolved = path.resolve(path.dirname(parentId), id); + const importedParts = partsAfterDist(resolved); + + if (importedParts) { + const entryPointIndex = lengthOfLongestEntryPoint(importedParts); + if (entryPointIndex === importedParts.length) { + return true; + } + + if (entryPointIndex >= 0) { + const parentParts = partsAfterDist(parentId); + const parentEntryPointIndex = lengthOfLongestEntryPoint(parentParts); + const sameEntryPoint = + entryPointIndex === parentEntryPointIndex && + arraysEqualUpTo(importedParts, parentParts, entryPointIndex); + + // If the imported ID and the parent ID have the same longest entry + // point prefix, then this import is safely confined within that + // entry point. Returning false lets Rollup know this import is not + // external, and can be bundled into the CJS bundle that we build + // for this shared entry point. + if (sameEntryPoint) { + return false; + } + + console.warn(`Risky cross-entry-point nested import of ${id} in ${ + partsAfterDist(parentId).join("/") + }`); + } + } + + return false; +}; + +function partsAfterDist(id) { + const parts = id.split(path.sep); + const distIndex = parts.lastIndexOf("dist"); + if (distIndex >= 0) { + return parts.slice(distIndex + 1); + } +} + +function lengthOfLongestEntryPoint(parts) { + let node = lookupTrie; + let longest = -1; + for (let i = 0; node && i < parts.length; ++i) { + if (node.isEntry) longest = i; + node = node.dirs && node.dirs[parts[i]]; + } + if (node && node.isEntry) { + return parts.length; + } + return longest; +} + +function arraysEqualUpTo(a, b, end) { + for (let i = 0; i < end; ++i) { + if (a[i] !== b[i]) return false; + } + return true; +} diff --git a/config/jest.config.js b/config/jest.config.js index a9be01c5de9..5bf85221c8f 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -1,3 +1,5 @@ +const { compilerOptions } = require("../tsconfig.json"); + module.exports = { rootDir: '..', transform: { @@ -6,6 +8,10 @@ module.exports = { globals: { 'ts-jest': { diagnostics: true, + tsConfig: { + ...compilerOptions, + allowJs: true, + }, }, }, moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], diff --git a/config/prepareDist.js b/config/prepareDist.js index f6857111edc..847d4b5029d 100644 --- a/config/prepareDist.js +++ b/config/prepareDist.js @@ -12,6 +12,7 @@ // store it in the appropriate dist sub-directory. const fs = require('fs'); +const path = require('path'); const recast = require('recast'); const distRoot = `${__dirname}/../dist`; @@ -20,6 +21,7 @@ const distRoot = `${__dirname}/../dist`; /* @apollo/client */ const packageJson = require('../package.json'); +const entryPoints = require('./entryPoints.js'); // The root package.json is marked as private to prevent publishing // from happening in the root of the project. This sets the package back to @@ -52,134 +54,23 @@ const destDir = `${srcDir}/dist`; fs.copyFileSync(`${srcDir}/README.md`, `${destDir}/README.md`); fs.copyFileSync(`${srcDir}/LICENSE`, `${destDir}/LICENSE`); - -/* - * @apollo/client/core - * @apollo/client/cache - * @apollo/client/utilities - * @apollo/client/react/ssr - * @apollo/client/react/hoc - * @apollo/client/react/components - */ - -function buildPackageJson(bundleName, entryPoint) { - return JSON.stringify({ - name: `@apollo/client/${entryPoint || bundleName}`, - main: `${bundleName}.cjs.js`, - module: 'index.js', - types: 'index.d.ts', - }, null, 2) + "\n"; -} - -function loadExportNames(bundleName) { - const indexSrc = - fs.readFileSync(`${distRoot}/${bundleName}/index.js`); - const exportNames = []; - recast.visit(recast.parse(indexSrc), { - visitExportSpecifier(path) { - exportNames.push(path.value.exported.name); - return false; - }, - }); - return exportNames; -} - -function writeCjsIndex(bundleName, exportNames, includeNames = true) { - const filterPrefix = includeNames ? '' : '!'; - fs.writeFileSync(`${distRoot}/${bundleName}/${bundleName}.cjs.js`, [ - "var allExports = require('../apollo-client.cjs');", - `var names = new Set(${JSON.stringify(exportNames)});`, - "Object.keys(allExports).forEach(function (name) {", - ` if (${filterPrefix}names.has(name)) {`, - " exports[name] = allExports[name];", - " }", - "});", - "", - ].join('\n')); -} - // Create individual bundle package.json files, storing them in their // associated dist directory. This helps provide a way for the Apollo Client // core to be used without React, as well as AC's cache, utilities, SSR, // components, HOC, and various links to be used by themselves, via CommonJS // entry point files that only include the exports needed for each bundle. - -// @apollo/client/core -fs.writeFileSync(`${distRoot}/core/package.json`, buildPackageJson('core')); -writeCjsIndex('core', loadExportNames('react'), false); - -// @apollo/client/cache -fs.writeFileSync(`${distRoot}/cache/package.json`, buildPackageJson('cache')); -writeCjsIndex('cache', loadExportNames('cache')); - -// @apollo/client/utilities -fs.writeFileSync( - `${distRoot}/utilities/package.json`, - buildPackageJson('utilities') -); - -// @apollo/client/react/ssr -fs.writeFileSync( - `${distRoot}/react/ssr/package.json`, - buildPackageJson('ssr', 'react/ssr') -); - -// @apollo/client/react/components -fs.writeFileSync( - `${distRoot}/react/components/package.json`, - buildPackageJson('components', 'react/components') -); - -// @apollo/client/react/hoc -fs.writeFileSync( - `${distRoot}/react/hoc/package.json`, - buildPackageJson('hoc', 'react/hoc') -); - -// @apollo/client/link/batch -fs.writeFileSync( - `${distRoot}/link/batch/package.json`, - buildPackageJson('batch', 'link/batch') -); - -// @apollo/client/link/batch-http -fs.writeFileSync( - `${distRoot}/link/batch-http/package.json`, - buildPackageJson('batch-http', 'link/batch-http') -); - -// @apollo/client/link/context -fs.writeFileSync( - `${distRoot}/link/context/package.json`, - buildPackageJson('context', 'link/context') -); - -// @apollo/client/link/error -fs.writeFileSync( - `${distRoot}/link/error/package.json`, - buildPackageJson('error', 'link/error') -); - -// @apollo/client/link/retry -fs.writeFileSync( - `${distRoot}/link/retry/package.json`, - buildPackageJson('retry', 'link/retry') -); - -// @apollo/client/link/schema -fs.writeFileSync( - `${distRoot}/link/schema/package.json`, - buildPackageJson('schema', 'link/schema') -); - -// @apollo/client/link/ws -fs.writeFileSync( - `${distRoot}/link/ws/package.json`, - buildPackageJson('ws', 'link/ws') -); - -// @apollo/client/link/http -fs.writeFileSync( - `${distRoot}/link/http/package.json`, - buildPackageJson('http', 'link/http') -); +entryPoints.forEach(function buildPackageJson({ + dirs, + bundleName = dirs[dirs.length - 1], +}) { + if (!dirs.length) return; + fs.writeFileSync( + path.join(distRoot, ...dirs, 'package.json'), + JSON.stringify({ + name: path.posix.join('@apollo', 'client', ...dirs), + main: `${bundleName}.cjs.js`, + module: 'index.js', + types: 'index.d.ts', + }, null, 2) + "\n", + ); +}); diff --git a/config/processInvariants.ts b/config/processInvariants.ts new file mode 100644 index 00000000000..8af71d3b3ef --- /dev/null +++ b/config/processInvariants.ts @@ -0,0 +1,149 @@ +import { readFileSync, writeFileSync } from "fs"; +import { resolve, relative } from "path"; +import glob = require("glob"); + +const distDir = resolve(__dirname, "..", "dist"); + +glob(`${distDir}/**/*.js`, (error, files) => { + if (error) throw error; + + files.sort().forEach(file => { + const relPath = relative(distDir, file); + + // Outside the distDir, somehow. + if (relPath.startsWith("../")) return; + + // Avoid re-transforming CommonJS bundle files. + if (relPath.endsWith(".cjs.js")) return; + + const source = readFileSync(file, "utf8"); + const output = transform(source, relPath); + if (source !== output) { + console.log("transformed invariants in " + relPath); + writeFileSync(file, output, "utf8"); + } + }); +}); + +import * as recast from "recast"; +import * as parser from "recast/parsers/babel"; +const b = recast.types.builders; +let nextErrorCode = 1; + +function transform(code: string, id: string) { + // If the code doesn't seem to contain anything invariant-related, we + // can skip parsing and transforming it. + if (!/invariant/i.test(code)) { + return code; + } + + const ast = recast.parse(code, { parser }); + + recast.visit(ast, { + visitCallExpression(path) { + this.traverse(path); + const node = path.node; + + if (isCallWithLength(node, "invariant", 1)) { + if (isNodeEnvConditional(path.parent.node)) { + return; + } + + const newArgs = node.arguments.slice(0, 1); + newArgs.push(b.numericLiteral(nextErrorCode++)); + + return b.conditionalExpression( + makeNodeEnvTest(), + b.callExpression.from({ + ...node, + arguments: newArgs, + }), + node, + ); + } + + if (node.callee.type === "MemberExpression" && + isIdWithName(node.callee.object, "invariant") && + isIdWithName(node.callee.property, "warn", "error")) { + if (isNodeEnvLogicalOr(path.parent.node)) { + return; + } + return b.logicalExpression("||", makeNodeEnvTest(), node); + } + }, + + visitNewExpression(path) { + this.traverse(path); + const node = path.node; + if (isCallWithLength(node, "InvariantError", 0)) { + if (isNodeEnvConditional(path.parent.node)) { + return; + } + + const newArgs = [ + b.numericLiteral(nextErrorCode++), + ]; + + return b.conditionalExpression( + makeNodeEnvTest(), + b.newExpression.from({ + ...node, + arguments: newArgs, + }), + node, + ); + } + } + }); + + return recast.print(ast).code; +} + +const n = recast.types.namedTypes; +type Node = recast.types.namedTypes.Node; +type CallExpression = recast.types.namedTypes.CallExpression; +type NewExpression = recast.types.namedTypes.NewExpression; + +function isIdWithName(node: Node, ...names: string[]) { + return n.Identifier.check(node) && + names.some(name => name === node.name); +} + +function isCallWithLength( + node: CallExpression | NewExpression, + name: string, + length: number, +) { + return isIdWithName(node.callee, name) && + node.arguments.length > length; +} + +function isNodeEnvConditional(node: Node) { + return n.ConditionalExpression.check(node) && + isNodeEnvExpr(node.test); +} + +function isNodeEnvLogicalOr(node: Node) { + return n.LogicalExpression.check(node) && + node.operator === "||" && + isNodeEnvExpr(node.left); +} + +function makeNodeEnvTest() { + return b.binaryExpression( + "===", + b.memberExpression( + b.memberExpression( + b.identifier("process"), + b.identifier("env") + ), + b.identifier("NODE_ENV"), + ), + b.stringLiteral("production"), + ); +} + +const referenceNodeEnvExpr = makeNodeEnvTest(); +function isNodeEnvExpr(node: Node) { + return recast.types.astNodesAreEquivalent(node, referenceNodeEnvExpr); +} diff --git a/config/rollup.config.js b/config/rollup.config.js index e29a4858aa8..db9929c7089 100644 --- a/config/rollup.config.js +++ b/config/rollup.config.js @@ -1,13 +1,13 @@ -import nodeResolve from 'rollup-plugin-node-resolve'; -import invariantPlugin from 'rollup-plugin-invariant'; +import nodeResolve from '@rollup/plugin-node-resolve'; import { terser as minify } from 'rollup-plugin-terser'; -import fs from 'fs'; +import path from 'path'; -import packageJson from '../package.json'; +const packageJson = require('../package.json'); +const entryPoints = require('./entryPoints'); const distDir = './dist'; -const external = [ +const externalPackages = new Set([ '@wry/context', '@wry/equality', 'fast-json-stable-stringify', @@ -24,83 +24,23 @@ const external = [ 'ts-invariant', 'tslib', 'zen-observable', -]; - -function prepareESM(input, outputDir) { - return { - input, - external, - output: { - dir: outputDir, - format: 'esm', - sourcemap: true, - }, - // The purpose of this job is to ensure each `./dist` ESM file is run - // through the `invariantPlugin`, with any resulting changes added - // directly back into each ESM file. By setting `preserveModules` - // to `true`, we're making sure Rollup doesn't attempt to create a single - // combined ESM bundle with the final result of running this job. - preserveModules: true, - plugins: [ - nodeResolve(), - invariantPlugin({ - // Instead of completely stripping InvariantError messages in - // production, this option assigns a numeric code to the - // production version of each error (unique to the call/throw - // location), which makes it much easier to trace production - // errors back to the unminified code where they were thrown, - // where the full error string can be found. See #4519. - errorCodes: true, - }) - ], - }; -} +]); function prepareCJS(input, output) { return { input, - external, + external(id) { + return externalPackages.has(id); + }, output: { file: output, format: 'cjs', sourcemap: true, exports: 'named', + externalLiveBindings: false, }, plugins: [ nodeResolve(), - // When generating the `dist/core/core.cjs.js` entry point (in - // `config/prepareDist.js`), we filter and re-export the exports we - // need from the main Apollo Client CJS bundle (to exclude React related - // code). This means that consumers of `core.cjs.js` attempt to load the - // full AC CJS bundle first (before filtering exports), which then means - // the React require in the AC CJS bundle is attempted and not found - // (since people using `core.cjs.js` want to use Apollo Client without - // React). To address this, we make React an optional require in the CJS - // bundle. - (() => { - const cjsBundle = output.replace(`${distDir}/`, ''); - return { - generateBundle(_option, bundle) { - const parts = bundle[cjsBundle].code.split( - /var React = require\('react'\);/); - // The React import should appear only once in the CJS bundle, - // since we build the CJS bundle using Rollup, which (hopefully!) - // deduplicates all external imports. - if (parts && parts.length === 2) { - bundle[cjsBundle].code = [ - parts[0], - "try { var React = require('react'); } catch (error) {}", - parts[1], - ].join("\n"); - } else { - throw new Error( - 'The CJS bundle could not be prepared as a single React ' + - 'require could not be found.' - ); - } - } - } - })() ], }; } @@ -128,90 +68,40 @@ function prepareCJSMinified(input) { }; } -function prepareUtilities() { - const utilsDistDir = `${distDir}/utilities`; - return { - input: `${utilsDistDir}/index.js`, - external, - output: { - file: `${utilsDistDir}/utilities.cjs.js`, - format: 'cjs', - sourcemap: true, - exports: 'named', - }, - plugins: [ - nodeResolve(), - ], - }; -} - -// Build a separate CJS only `testing.js` bundle, that includes React -// testing utilities like `MockedProvider` (testing utilities are kept out of -// the main `apollo-client` bundle). This bundle can be accessed directly -// like: -// -// import { MockedProvider } from '@apollo/client/testing'; -function prepareTesting() { - const bundleName = 'testing'; - - // Create a type file for the new testing bundle that points to the existing - // `react/testing` type definitions. - fs.writeFileSync( - `${distDir}/${bundleName}.d.ts`, - "export * from './utilities/testing';" - ); - - return { - input: `${distDir}/utilities/testing/index.js`, - external, - output: { - file: `${distDir}/${bundleName}.js`, - format: 'cjs', - }, - plugins: [ - nodeResolve({ - extensions: ['.js', '.jsx'], - }), - ], - }; -} - -function prepareBundle(name, path) { - const dir = `${distDir}/${path}`; +function prepareBundle({ + dirs, + bundleName = dirs[dirs.length - 1], + extensions, +}) { + const dir = path.join(distDir, ...dirs); return { input: `${dir}/index.js`, - external, + external(id, parentId) { + return externalPackages.has(id) || + entryPoints.check(id, parentId); + }, output: { - file: `${dir}/${name}.cjs.js`, + file: `${dir}/${bundleName}.cjs.js`, format: 'cjs', sourcemap: true, exports: 'named', + externalLiveBindings: false, }, plugins: [ - nodeResolve(), + extensions ? nodeResolve({ extensions }) : nodeResolve(), ], }; } -function rollup() { - return [ - prepareESM(packageJson.module, distDir), - prepareCJS(packageJson.module, packageJson.main), - prepareCJSMinified(packageJson.main), - prepareUtilities(), - prepareTesting(), - prepareBundle('ssr', 'react/ssr'), - prepareBundle('components', 'react/components'), - prepareBundle('hoc', 'react/hoc'), - prepareBundle('batch', 'link/batch'), - prepareBundle('batch-http', 'link/batch-http'), - prepareBundle('context', 'link/context'), - prepareBundle('error', 'link/error'), - prepareBundle('retry', 'link/retry'), - prepareBundle('schema', 'link/schema'), - prepareBundle('ws', 'link/ws'), - prepareBundle('http', 'link/http'), - ]; -} - -export default rollup(); +export default [ + ...entryPoints.map(prepareBundle), + // Convert the ESM entry point to a single CJS bundle. + prepareCJS( + './dist/index.js', + './dist/apollo-client.cjs.js', + ), + // Minify that single CJS bundle. + prepareCJSMinified( + './dist/apollo-client.cjs.js', + ), +]; diff --git a/config/tsconfig.json b/config/tsconfig.json new file mode 100644 index 00000000000..fcf8e935cbb --- /dev/null +++ b/config/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "noImplicitAny": true, + "strictNullChecks": true, + "noUnusedParameters": false, + "noUnusedLocals": true, + "skipLibCheck": true, + "moduleResolution": "node", + "importHelpers": true, + "target": "es5", + "module": "commonjs", + "esModuleInterop": true, + }, +} diff --git a/package-lock.json b/package-lock.json index bf2607577dd..2a025b7dd59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -343,9 +343,9 @@ } }, "@babel/parser": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.10.4.tgz", - "integrity": "sha512-8jHII4hf+YVDsskTF6WuMB3X4Eh+PsUkC2ljq22so5rHvH+T8BzyL94VOdyFLNR8tBSVXOTbNHOKpR4TfRxVtA==", + "version": "7.10.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.10.5.tgz", + "integrity": "sha512-wfryxy4bE1UivvQKSQDU4/X6dr+i8bctjUjj8Zyt3DQy7NtPizJXT8M52nqpNKL+nq2PW8lxk4ZqLj0fD4B4hQ==", "dev": true }, "@babel/plugin-proposal-class-properties": { @@ -963,6 +963,14 @@ "@babel/types": "7.10.4", "@graphql-tools/utils": "6.0.12", "vue-template-compiler": "^2.6.11" + }, + "dependencies": { + "@babel/parser": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.10.4.tgz", + "integrity": "sha512-8jHII4hf+YVDsskTF6WuMB3X4Eh+PsUkC2ljq22so5rHvH+T8BzyL94VOdyFLNR8tBSVXOTbNHOKpR4TfRxVtA==", + "dev": true + } } }, "@graphql-tools/import": { @@ -2068,6 +2076,57 @@ "fastq": "^1.6.0" } }, + "@rollup/plugin-node-resolve": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-8.4.0.tgz", + "integrity": "sha512-LFqKdRLn0ShtQyf6SBYO69bGE1upV6wUhBX0vFOUnLAyzx5cwp8svA0eHUnu8+YU57XOkrMtfG63QOpQx25pHQ==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "@types/resolve": "1.17.1", + "builtin-modules": "^3.1.0", + "deep-freeze": "^0.0.1", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.17.0" + }, + "dependencies": { + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "dependencies": { + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, "@sheerun/mutationobserver-shim": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz", @@ -2183,6 +2242,16 @@ "integrity": "sha512-NCEfv49jmDsBAixjMjEHKVgmVQlJ+uK56FOc+2roYPExnXCZDpi6mJOHQ3v23BiO84hBDStND9R2itJr7PNoow==", "dev": true }, + "@types/glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==", + "dev": true, + "requires": { + "@types/minimatch": "*", + "@types/node": "*" + } + }, "@types/graceful-fs": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.3.tgz", @@ -2309,6 +2378,12 @@ "integrity": "sha512-Ft5BNFmv2pHDgxV5JDsndOWTRJ+56zte0ZpYLowp03tW+K+t8u8YMOzAnpuqPgzX6WO1XpDIUm7u04M8vdDiVQ==", "dev": true }, + "@types/minimatch": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", + "dev": true + }, "@types/node": { "version": "14.0.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.18.tgz", @@ -2362,9 +2437,9 @@ } }, "@types/resolve": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", - "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", + "integrity": "sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==", "dev": true, "requires": { "@types/node": "*" @@ -2621,6 +2696,12 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -3651,6 +3732,12 @@ "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", "dev": true }, + "deep-freeze": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/deep-freeze/-/deep-freeze-0.0.1.tgz", + "integrity": "sha1-OgsABd4YZygZ39OM0x+RF5yJPoQ=", + "dev": true + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -3737,6 +3824,12 @@ "integrity": "sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==", "dev": true }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, "diff-sequences": { "version": "25.2.6", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-25.2.6.tgz", @@ -8985,44 +9078,6 @@ } } }, - "rollup-plugin-invariant": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/rollup-plugin-invariant/-/rollup-plugin-invariant-0.5.6.tgz", - "integrity": "sha512-KdkvPqSi7SfzuX8u//Hl3liU+EppwBfagz30YkwEnRrYzS/rwgCmmINCHtkJemdYVZ3XKuI8vXcTleoWaYxwTA==", - "dev": true, - "requires": { - "recast": "^0.18.0", - "rollup-pluginutils": "^2.3.3", - "tslib": "^1.9.3" - }, - "dependencies": { - "recast": { - "version": "0.18.10", - "resolved": "https://registry.npmjs.org/recast/-/recast-0.18.10.tgz", - "integrity": "sha512-XNvYvkfdAN9QewbrxeTOjgINkdY/odTgTS56ZNEWL9Ml0weT4T3sFtvnTuF+Gxyu46ANcRm1ntrF6F5LAJPAaQ==", - "dev": true, - "requires": { - "ast-types": "0.13.3", - "esprima": "~4.0.0", - "private": "^0.1.8", - "source-map": "~0.6.1" - } - } - } - }, - "rollup-plugin-node-resolve": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", - "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", - "dev": true, - "requires": { - "@types/resolve": "0.0.8", - "builtin-modules": "^3.1.0", - "is-module": "^1.0.0", - "resolve": "^1.11.1", - "rollup-pluginutils": "^2.8.1" - } - }, "rollup-plugin-terser": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.1.3.tgz", @@ -10029,6 +10084,31 @@ } } }, + "ts-node": { + "version": "8.10.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", + "integrity": "sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + }, + "dependencies": { + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } + }, "tsc-watch": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/tsc-watch/-/tsc-watch-3.0.1.tgz", @@ -10657,6 +10737,12 @@ } } }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + }, "zen-observable": { "version": "0.8.15", "resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz", diff --git a/package.json b/package.json index 649341c25c5..78cf7c01836 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "author": "opensource@apollographql.com", "license": "MIT", - "main": "./dist/apollo-client.cjs.js", + "main": "./dist/main.cjs.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", "sideEffects": [ @@ -32,7 +32,7 @@ "homepage": "https://www.apollographql.com", "scripts": { "prebuild": "npm run clean", - "build": "tsc", + "build": "tsc && ts-node-script config/processInvariants.ts", "postbuild": "npm run bundle && npm run prepdist", "watch": "tsc-watch --onSuccess \"npm run postbuild\"", "clean": "rimraf -r dist coverage lib", @@ -79,9 +79,12 @@ "zen-observable": "^0.8.14" }, "devDependencies": { + "@babel/parser": "7.10.5", + "@rollup/plugin-node-resolve": "8.4.0", "@testing-library/react": "9.4.1", "@types/fast-json-stable-stringify": "2.0.0", "@types/fetch-mock": "^7.3.2", + "@types/glob": "7.1.3", "@types/hoist-non-react-statics": "^3.3.1", "@types/jest": "26.0.5", "@types/lodash": "4.14.157", @@ -92,6 +95,7 @@ "bundlesize": "0.18.0", "cross-fetch": "3.0.5", "fetch-mock": "7.7.3", + "glob": "7.1.6", "graphql": "15.3.0", "graphql-tools": "^6.0.12", "jest": "26.1.0", @@ -103,12 +107,11 @@ "recompose": "^0.30.0", "rimraf": "3.0.2", "rollup": "1.31.1", - "rollup-plugin-invariant": "0.5.6", - "rollup-plugin-node-resolve": "5.2.0", "rollup-plugin-terser": "5.1.3", "rxjs": "6.6.0", "subscriptions-transport-ws": "^0.9.17", "ts-jest": "26.1.1", + "ts-node": "8.10.2", "tsc-watch": "3.0.1", "typescript": "3.9.6", "wait-for-observables": "^1.0.3" diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index d1ad5e409a7..b6341a63b5e 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -1,14 +1,18 @@ import gql from 'graphql-tag'; -import { Observable } from '../utilities/observables/Observable'; -import { makeReference } from '../core'; -import { ApolloLink } from '../link/core/ApolloLink'; -import { HttpLink } from '../link/http/HttpLink'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { stripSymbols } from '../utilities/testing/stripSymbols'; -import { ApolloClient } from '../'; -import { DefaultOptions } from '../ApolloClient'; -import { FetchPolicy, QueryOptions } from '../core/watchQueryOptions'; +import { + ApolloClient, + DefaultOptions, + FetchPolicy, + QueryOptions, + makeReference, +} from '../core'; + +import { Observable } from '../utilities'; +import { ApolloLink } from '../link/core'; +import { HttpLink } from '../link/http'; +import { InMemoryCache } from '../cache'; +import { stripSymbols } from '../testing'; describe('ApolloClient', () => { describe('constructor', () => { diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap new file mode 100644 index 00000000000..b8bfd656234 --- /dev/null +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -0,0 +1,351 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`exports of public entry points @apollo/client 1`] = ` +Array [ + "ApolloCache", + "ApolloClient", + "ApolloConsumer", + "ApolloError", + "ApolloLink", + "ApolloProvider", + "Cache", + "DocumentType", + "HttpLink", + "InMemoryCache", + "MissingFieldError", + "NetworkStatus", + "Observable", + "ObservableQuery", + "checkFetcher", + "concat", + "createHttpLink", + "createSignalIfSupported", + "defaultDataIdFromObject", + "disableExperimentalFragmentVariables", + "disableFragmentWarnings", + "empty", + "enableExperimentalFragmentVariables", + "execute", + "fallbackHttpConfig", + "from", + "fromError", + "fromPromise", + "getApolloContext", + "gql", + "isApolloError", + "isReference", + "makeReference", + "makeVar", + "operationName", + "parseAndCheckHttpResponse", + "parser", + "resetApolloContext", + "resetCaches", + "rewriteURIForGET", + "selectHttpOptionsAndBody", + "selectURI", + "serializeFetchParameter", + "split", + "throwServerError", + "toPromise", + "useApolloClient", + "useLazyQuery", + "useMutation", + "useQuery", + "useSubscription", +] +`; + +exports[`exports of public entry points @apollo/client/cache 1`] = ` +Array [ + "ApolloCache", + "Cache", + "InMemoryCache", + "MissingFieldError", + "cacheSlot", + "defaultDataIdFromObject", + "isReference", + "makeReference", + "makeVar", +] +`; + +exports[`exports of public entry points @apollo/client/core 1`] = ` +Array [ + "ApolloCache", + "ApolloClient", + "ApolloError", + "ApolloLink", + "Cache", + "HttpLink", + "InMemoryCache", + "MissingFieldError", + "NetworkStatus", + "Observable", + "ObservableQuery", + "checkFetcher", + "concat", + "createHttpLink", + "createSignalIfSupported", + "defaultDataIdFromObject", + "disableExperimentalFragmentVariables", + "disableFragmentWarnings", + "empty", + "enableExperimentalFragmentVariables", + "execute", + "fallbackHttpConfig", + "from", + "fromError", + "fromPromise", + "gql", + "isApolloError", + "isReference", + "makeReference", + "makeVar", + "parseAndCheckHttpResponse", + "resetCaches", + "rewriteURIForGET", + "selectHttpOptionsAndBody", + "selectURI", + "serializeFetchParameter", + "split", + "throwServerError", + "toPromise", +] +`; + +exports[`exports of public entry points @apollo/client/errors 1`] = ` +Array [ + "ApolloError", + "isApolloError", +] +`; + +exports[`exports of public entry points @apollo/client/link/batch 1`] = ` +Array [ + "BatchLink", + "OperationBatcher", +] +`; + +exports[`exports of public entry points @apollo/client/link/batch-http 1`] = ` +Array [ + "BatchHttpLink", +] +`; + +exports[`exports of public entry points @apollo/client/link/context 1`] = ` +Array [ + "setContext", +] +`; + +exports[`exports of public entry points @apollo/client/link/core 1`] = ` +Array [ + "ApolloLink", + "concat", + "empty", + "execute", + "from", + "split", +] +`; + +exports[`exports of public entry points @apollo/client/link/error 1`] = ` +Array [ + "ErrorLink", + "onError", +] +`; + +exports[`exports of public entry points @apollo/client/link/http 1`] = ` +Array [ + "HttpLink", + "checkFetcher", + "createHttpLink", + "createSignalIfSupported", + "fallbackHttpConfig", + "parseAndCheckHttpResponse", + "rewriteURIForGET", + "selectHttpOptionsAndBody", + "selectURI", + "serializeFetchParameter", +] +`; + +exports[`exports of public entry points @apollo/client/link/retry 1`] = ` +Array [ + "RetryLink", +] +`; + +exports[`exports of public entry points @apollo/client/link/schema 1`] = ` +Array [ + "SchemaLink", +] +`; + +exports[`exports of public entry points @apollo/client/link/utils 1`] = ` +Array [ + "createOperation", + "fromError", + "fromPromise", + "throwServerError", + "toPromise", + "transformOperation", + "validateOperation", +] +`; + +exports[`exports of public entry points @apollo/client/link/ws 1`] = ` +Array [ + "WebSocketLink", +] +`; + +exports[`exports of public entry points @apollo/client/react 1`] = ` +Array [ + "ApolloConsumer", + "ApolloProvider", + "DocumentType", + "getApolloContext", + "operationName", + "parser", + "resetApolloContext", + "useApolloClient", + "useLazyQuery", + "useMutation", + "useQuery", + "useSubscription", +] +`; + +exports[`exports of public entry points @apollo/client/react/components 1`] = ` +Array [ + "Mutation", + "Query", + "Subscription", +] +`; + +exports[`exports of public entry points @apollo/client/react/context 1`] = ` +Array [ + "ApolloConsumer", + "ApolloProvider", + "getApolloContext", + "resetApolloContext", +] +`; + +exports[`exports of public entry points @apollo/client/react/data 1`] = ` +Array [ + "MutationData", + "OperationData", + "QueryData", + "SubscriptionData", +] +`; + +exports[`exports of public entry points @apollo/client/react/hoc 1`] = ` +Array [ + "graphql", + "withApollo", + "withMutation", + "withQuery", + "withSubscription", +] +`; + +exports[`exports of public entry points @apollo/client/react/hooks 1`] = ` +Array [ + "useApolloClient", + "useLazyQuery", + "useMutation", + "useQuery", + "useSubscription", +] +`; + +exports[`exports of public entry points @apollo/client/react/parser 1`] = ` +Array [ + "DocumentType", + "operationName", + "parser", +] +`; + +exports[`exports of public entry points @apollo/client/react/ssr 1`] = ` +Array [ + "RenderPromises", + "getDataFromTree", + "getMarkupFromTree", + "renderToStringWithData", +] +`; + +exports[`exports of public entry points @apollo/client/testing 1`] = ` +Array [ + "MockLink", + "MockSubscriptionLink", + "MockedProvider", + "createMockClient", + "itAsync", + "mockObservableLink", + "mockSingleLink", + "stripSymbols", + "subscribeAndCount", +] +`; + +exports[`exports of public entry points @apollo/client/utilities 1`] = ` +Array [ + "Concast", + "DeepMerger", + "Observable", + "addTypenameToDocument", + "argumentsObjectFromField", + "asyncMap", + "buildQueryFromSelectionSet", + "canUseWeakMap", + "checkDocument", + "cloneDeep", + "concatPagination", + "createFragmentMap", + "getDefaultValues", + "getDirectiveNames", + "getFragmentDefinition", + "getFragmentDefinitions", + "getFragmentFromSelection", + "getFragmentQueryDocument", + "getInclusionDirectives", + "getMainDefinition", + "getOperationDefinition", + "getOperationName", + "getQueryDefinition", + "getStoreKeyName", + "getTypenameFromResult", + "graphQLResultHasError", + "hasClientExports", + "hasDirectives", + "isField", + "isInlineFragment", + "isNonEmptyArray", + "isReference", + "iterateObserversSafely", + "makeReference", + "maybeDeepFreeze", + "mergeDeep", + "mergeDeepArray", + "offsetLimitPagination", + "relayStylePagination", + "removeArgumentsFromDocument", + "removeClientSetsFromDocument", + "removeConnectionDirectiveFromDocument", + "removeDirectivesFromDocument", + "removeFragmentSpreadFromDocument", + "resultKeyNameFromField", + "shouldInclude", + "storeKeyNameFromField", + "valueToObjectRepresentation", +] +`; diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index ac738824a89..b1e3a1d8281 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -2,17 +2,25 @@ import { cloneDeep, assign } from 'lodash'; import { GraphQLError, ExecutionResult, DocumentNode } from 'graphql'; import gql from 'graphql-tag'; -import { Observable, ObservableSubscription } from '../utilities/observables/Observable'; -import { ApolloLink } from '../link/core/ApolloLink'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { stripSymbols } from '../utilities/testing/stripSymbols'; -import { FetchPolicy, WatchQueryFetchPolicy, QueryOptions } from '../core/watchQueryOptions'; -import { ApolloError } from '../errors/ApolloError'; -import { ApolloClient } from '..'; -import subscribeAndCount from '../utilities/testing/subscribeAndCount'; -import { itAsync } from '../utilities/testing/itAsync'; -import { mockSingleLink } from '../utilities/testing/mocking/mockLink'; -import { ObservableQuery, PossibleTypesMap, makeVar } from '../core'; +import { + ApolloClient, + FetchPolicy, + WatchQueryFetchPolicy, + QueryOptions, + ObservableQuery, +} from '../core'; + +import { Observable, ObservableSubscription } from '../utilities'; +import { ApolloLink } from '../link/core'; +import { InMemoryCache, makeVar, PossibleTypesMap } from '../cache'; +import { ApolloError } from '../errors'; + +import { + itAsync, + stripSymbols, + subscribeAndCount, + mockSingleLink, +} from '../testing'; describe('client', () => { it('can be loaded via require', () => { diff --git a/src/__tests__/exports.ts b/src/__tests__/exports.ts new file mode 100644 index 00000000000..5f896488d05 --- /dev/null +++ b/src/__tests__/exports.ts @@ -0,0 +1,72 @@ +import * as cache from "../cache"; +import * as client from ".."; +import * as core from "../core"; +import * as errors from "../errors"; +import * as linkBatch from "../link/batch"; +import * as linkBatchHTTP from "../link/batch-http"; +import * as linkContext from "../link/context"; +import * as linkCore from "../link/core"; +import * as linkError from "../link/error"; +import * as linkHTTP from "../link/http"; +import * as linkRetry from "../link/retry"; +import * as linkSchema from "../link/schema"; +import * as linkUtils from "../link/utils"; +import * as linkWS from "../link/ws"; +import * as react from "../react"; +import * as reactComponents from "../react/components"; +import * as reactContext from "../react/context"; +import * as reactData from "../react/data"; +import * as reactHOC from "../react/hoc"; +import * as reactHooks from "../react/hooks"; +import * as reactParser from "../react/parser"; +import * as reactSSR from "../react/ssr"; +import * as testing from "../testing"; +import * as utilities from "../utilities"; + +const entryPoints = require("../../config/entryPoints.js"); + +type Namespace = object; + +describe('exports of public entry points', () => { + const testedIds = new Set(); + + function check(id: string, ns: Namespace) { + it(id, () => { + testedIds.add(id); + expect(Object.keys(ns).sort()).toMatchSnapshot(); + }); + } + + check("@apollo/client", client); + check("@apollo/client/cache", cache); + check("@apollo/client/core", core); + check("@apollo/client/errors", errors); + check("@apollo/client/link/batch", linkBatch); + check("@apollo/client/link/batch-http", linkBatchHTTP); + check("@apollo/client/link/context", linkContext); + check("@apollo/client/link/core", linkCore); + check("@apollo/client/link/error", linkError); + check("@apollo/client/link/http", linkHTTP); + check("@apollo/client/link/retry", linkRetry); + check("@apollo/client/link/schema", linkSchema); + check("@apollo/client/link/utils", linkUtils); + check("@apollo/client/link/ws", linkWS); + check("@apollo/client/react", react); + check("@apollo/client/react/components", reactComponents); + check("@apollo/client/react/context", reactContext); + check("@apollo/client/react/data", reactData); + check("@apollo/client/react/hoc", reactHOC); + check("@apollo/client/react/hooks", reactHooks); + check("@apollo/client/react/parser", reactParser); + check("@apollo/client/react/ssr", reactSSR); + check("@apollo/client/testing", testing); + check("@apollo/client/utilities", utilities); + + it("completeness", () => { + const { join } = require("path").posix; + entryPoints.forEach((info: Record) => { + const id = join("@apollo/client", ...info.dirs); + expect(testedIds).toContain(id); + }); + }); +}); diff --git a/src/__tests__/fetchMore.ts b/src/__tests__/fetchMore.ts index 56e1333a926..c1b8bd2956b 100644 --- a/src/__tests__/fetchMore.ts +++ b/src/__tests__/fetchMore.ts @@ -1,11 +1,9 @@ import { assign, cloneDeep } from 'lodash'; import gql from 'graphql-tag'; -import { mockSingleLink } from '../utilities/testing/mocking/mockLink'; -import subscribeAndCount from '../utilities/testing/subscribeAndCount'; -import { InMemoryCache, InMemoryCacheConfig } from '../cache/inmemory/inMemoryCache'; -import { ApolloClient, NetworkStatus, ObservableQuery } from '../'; -import { itAsync } from '../utilities/testing/itAsync'; +import { itAsync, mockSingleLink, subscribeAndCount } from '../testing'; +import { InMemoryCache, InMemoryCacheConfig } from '../cache'; +import { ApolloClient, NetworkStatus, ObservableQuery } from '../core'; import { offsetLimitPagination, concatPagination } from '../utilities'; describe('updateQuery on a simple query', () => { diff --git a/src/__tests__/graphqlSubscriptions.ts b/src/__tests__/graphqlSubscriptions.ts index 82164783387..39a010b7136 100644 --- a/src/__tests__/graphqlSubscriptions.ts +++ b/src/__tests__/graphqlSubscriptions.ts @@ -1,11 +1,9 @@ import gql from 'graphql-tag'; -import { - mockObservableLink -} from '../utilities/testing/mocking/mockSubscriptionLink'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { ApolloClient } from '../'; +import { ApolloClient } from '../core'; +import { InMemoryCache } from '../cache'; import { QueryManager } from '../core/QueryManager'; +import { mockObservableLink } from '../testing'; describe('GraphQL Subscriptions', () => { const results = [ diff --git a/src/__tests__/local-state/export.ts b/src/__tests__/local-state/export.ts index a3ce48dc761..45eac6ace1f 100644 --- a/src/__tests__/local-state/export.ts +++ b/src/__tests__/local-state/export.ts @@ -1,11 +1,11 @@ import gql from 'graphql-tag'; import { print } from 'graphql/language/printer'; -import { Observable } from '../../utilities/observables/Observable'; -import { itAsync } from '../../utilities/testing/itAsync'; -import { ApolloLink } from '../../link/core/ApolloLink'; -import { ApolloClient } from '../..'; -import { InMemoryCache } from '../../cache/inmemory/inMemoryCache'; +import { Observable } from '../../utilities'; +import { itAsync } from '../../testing'; +import { ApolloLink } from '../../link/core'; +import { ApolloClient } from '../../core'; +import { InMemoryCache } from '../../cache'; describe('@client @export tests', () => { it( diff --git a/src/__tests__/local-state/general.ts b/src/__tests__/local-state/general.ts index a81401d72c7..5537f1bc011 100644 --- a/src/__tests__/local-state/general.ts +++ b/src/__tests__/local-state/general.ts @@ -2,13 +2,12 @@ import gql from 'graphql-tag'; import { DocumentNode, GraphQLError } from 'graphql'; import { getIntrospectionQuery } from 'graphql/utilities'; -import { Observable } from '../../utilities/observables/Observable'; -import { ApolloLink } from '../../link/core/ApolloLink'; -import { Operation } from '../../link/core/types'; -import { ApolloClient } from '../..'; -import { ApolloCache } from '../../cache/core/cache'; -import { InMemoryCache } from '../../cache/inmemory/inMemoryCache'; -import { itAsync } from '../../utilities/testing/itAsync'; +import { Observable } from '../../utilities'; +import { ApolloLink } from '../../link/core'; +import { Operation } from '../../link/core'; +import { ApolloClient } from '../../core'; +import { ApolloCache, InMemoryCache } from '../../cache'; +import { itAsync } from '../../testing'; describe('General functionality', () => { it('should not impact normal non-@client use', () => { diff --git a/src/__tests__/local-state/resolvers.ts b/src/__tests__/local-state/resolvers.ts index 77f06c7b856..a6273cce4ee 100644 --- a/src/__tests__/local-state/resolvers.ts +++ b/src/__tests__/local-state/resolvers.ts @@ -2,16 +2,21 @@ import gql from 'graphql-tag'; import { DocumentNode, ExecutionResult } from 'graphql'; import { assign } from 'lodash'; -import { Observable, Observer } from '../../utilities/observables/Observable'; -import { ApolloLink } from '../../link/core/ApolloLink'; -import { ApolloClient } from '../..'; +import { LocalState } from '../../core/LocalState'; + +import { + ApolloClient, + ApolloQueryResult, + Resolvers, + WatchQueryOptions, +} from '../../core'; + +import { InMemoryCache } from '../../cache'; +import { Observable, Observer } from '../../utilities'; +import { ApolloLink } from '../../link/core'; +import { itAsync } from '../../testing'; import mockQueryManager from '../../utilities/testing/mocking/mockQueryManager'; import wrap from '../../utilities/testing/wrap'; -import { itAsync } from '../../utilities/testing/itAsync'; -import { ApolloQueryResult, Resolvers } from '../../core/types'; -import { WatchQueryOptions } from '../../core/watchQueryOptions'; -import { LocalState } from '../../core/LocalState'; -import { InMemoryCache } from '../../cache/inmemory/inMemoryCache'; // Helper method that sets up a mockQueryManager and then passes on the // results to an observer. diff --git a/src/__tests__/local-state/subscriptions.ts b/src/__tests__/local-state/subscriptions.ts index e7e18b8ed22..cc8e1933a52 100644 --- a/src/__tests__/local-state/subscriptions.ts +++ b/src/__tests__/local-state/subscriptions.ts @@ -1,9 +1,9 @@ import gql from 'graphql-tag'; -import { Observable } from '../../utilities/observables/Observable'; -import { ApolloLink } from '../../link/core/ApolloLink'; -import { ApolloClient } from '../..'; -import { InMemoryCache } from '../../cache/inmemory/inMemoryCache'; +import { Observable } from '../../utilities'; +import { ApolloLink } from '../../link/core'; +import { ApolloClient } from '../../core'; +import { InMemoryCache } from '../../cache'; describe('Basic functionality', () => { it('should not break subscriptions', done => { diff --git a/src/__tests__/mutationResults.ts b/src/__tests__/mutationResults.ts index 6b585d1bbfd..9d87841f9fe 100644 --- a/src/__tests__/mutationResults.ts +++ b/src/__tests__/mutationResults.ts @@ -1,13 +1,11 @@ import { cloneDeep } from 'lodash'; import gql from 'graphql-tag'; -import { Observable, ObservableSubscription as Subscription } from '../utilities/observables/Observable'; -import { ApolloLink } from '../link/core/ApolloLink'; -import { mockSingleLink } from '../utilities/testing/mocking/mockLink'; -import { ApolloClient } from '..'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { itAsync } from '../utilities/testing/itAsync'; -import subscribeAndCount from '../utilities/testing/subscribeAndCount'; +import { ApolloClient } from '../core'; +import { InMemoryCache } from '../cache'; +import { ApolloLink } from '../link/core'; +import { Observable, ObservableSubscription as Subscription } from '../utilities'; +import { itAsync, subscribeAndCount, mockSingleLink } from '../testing'; describe('mutation results', () => { const query = gql` diff --git a/src/__tests__/optimistic.ts b/src/__tests__/optimistic.ts index 637cac4d67f..126f81e3a69 100644 --- a/src/__tests__/optimistic.ts +++ b/src/__tests__/optimistic.ts @@ -3,17 +3,34 @@ import { take, toArray, map } from 'rxjs/operators'; import { assign, cloneDeep } from 'lodash'; import gql from 'graphql-tag'; -import { mockSingleLink } from '../utilities/testing/mocking/mockLink'; -import { MutationQueryReducersMap } from '../core/types'; -import { Observable, ObservableSubscription as Subscription } from '../utilities/observables/Observable'; -import { ApolloClient } from '../'; -import { addTypenameToDocument } from '../utilities/graphql/transform'; -import { makeReference, ApolloLink, ApolloCache } from '../core'; -import { stripSymbols } from '../utilities/testing/stripSymbols'; -import { itAsync } from '../utilities/testing/itAsync'; -import { Cache } from '../cache/core/types/Cache'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { QueryManager } from '../core/QueryManager'; +import { + ApolloClient, + makeReference, + ApolloLink, + ApolloCache, + MutationQueryReducersMap, +} from '../core'; + +import { + QueryManager, +} from '../core/QueryManager'; + +import { + Cache, + InMemoryCache, +} from '../cache'; + +import { + Observable, + ObservableSubscription as Subscription, + addTypenameToDocument, +} from '../utilities'; + +import { + stripSymbols, + itAsync, + mockSingleLink, +} from '../testing'; describe('optimistic mutation results', () => { const query = gql` diff --git a/src/__tests__/subscribeToMore.ts b/src/__tests__/subscribeToMore.ts index e5a775fe202..3c5b4959ac1 100644 --- a/src/__tests__/subscribeToMore.ts +++ b/src/__tests__/subscribeToMore.ts @@ -1,14 +1,15 @@ import gql from 'graphql-tag'; import { DocumentNode, OperationDefinitionNode } from 'graphql'; -import { ApolloLink } from '../link/core/ApolloLink'; -import { Operation } from '../link/core/types'; -import { mockSingleLink } from '../utilities/testing/mocking/mockLink'; -import { mockObservableLink } from '../utilities/testing/mocking/mockSubscriptionLink'; -import { ApolloClient } from '../'; -import { InMemoryCache } from '../cache/inmemory/inMemoryCache'; -import { stripSymbols } from '../utilities/testing/stripSymbols'; -import { itAsync } from '../utilities/testing/itAsync'; +import { ApolloClient } from '../core'; +import { InMemoryCache } from '../cache'; +import { ApolloLink, Operation } from '../link/core'; +import { + itAsync, + stripSymbols, + mockSingleLink, + mockObservableLink, +} from '../testing'; const isSub = (operation: Operation) => (operation.query as DocumentNode).definitions diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 27020553ef9..6babc4aeb58 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -1,8 +1,11 @@ import { DocumentNode } from 'graphql'; import { wrap } from 'optimism'; -import { getFragmentQueryDocument } from '../../utilities/graphql/fragments'; -import { StoreObject, Reference } from '../../utilities/graphql/storeUtils'; +import { + StoreObject, + Reference, + getFragmentQueryDocument, +} from '../../utilities'; import { DataProxy } from './types/DataProxy'; import { Cache } from './types/Cache'; diff --git a/src/cache/core/types/common.ts b/src/cache/core/types/common.ts index f8c0fa17acd..7d58ebc3769 100644 --- a/src/cache/core/types/common.ts +++ b/src/cache/core/types/common.ts @@ -5,7 +5,7 @@ import { StoreObject, StoreValue, isReference, -} from '../../../core'; +} from '../../../utilities'; // The Readonly type only really works for object types, since it marks // all of the object's properties as readonly, but there are many cases when diff --git a/src/cache/index.ts b/src/cache/index.ts index 5e618fb9cb1..96cb9b0436f 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -7,7 +7,7 @@ export { Reference, isReference, makeReference, -} from '../utilities/graphql/storeUtils'; +} from '../utilities'; export { InMemoryCache, @@ -17,6 +17,7 @@ export { export { ReactiveVar, makeVar, + cacheSlot, } from './inmemory/reactiveVars'; export { diff --git a/src/cache/inmemory/entityStore.ts b/src/cache/inmemory/entityStore.ts index d961cbceb02..6f18eddada9 100644 --- a/src/cache/inmemory/entityStore.ts +++ b/src/cache/inmemory/entityStore.ts @@ -6,11 +6,11 @@ import { StoreValue, StoreObject, Reference, - makeReference -} from '../../utilities/graphql/storeUtils'; -import { DeepMerger } from '../../utilities/common/mergeDeep'; -import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze'; -import { canUseWeakMap } from '../../utilities/common/canUse'; + makeReference, + DeepMerger, + maybeDeepFreeze, + canUseWeakMap, +} from '../../utilities'; import { NormalizedCache, NormalizedCacheObject } from './types'; import { hasOwn, fieldNameFromStoreName } from './helpers'; import { Policies } from './policies'; diff --git a/src/cache/inmemory/helpers.ts b/src/cache/inmemory/helpers.ts index d41568f26db..9cdd09ae12c 100644 --- a/src/cache/inmemory/helpers.ts +++ b/src/cache/inmemory/helpers.ts @@ -6,9 +6,10 @@ import { isReference, StoreValue, StoreObject, - isField -} from '../../utilities/graphql/storeUtils'; -import { DeepMerger, ReconcilerFunction } from '../../utilities/common/mergeDeep'; + isField, + DeepMerger, + ReconcilerFunction, +} from '../../utilities'; export const hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 24839ac4f4a..1260e83e1d2 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -6,8 +6,12 @@ import { dep, wrap } from 'optimism'; import { ApolloCache } from '../core/cache'; import { Cache } from '../core/types/Cache'; -import { addTypenameToDocument } from '../../utilities/graphql/transform'; -import { StoreObject, Reference, isReference } from '../../utilities/graphql/storeUtils'; +import { + addTypenameToDocument, + StoreObject, + Reference, + isReference, +} from '../../utilities'; import { ApolloReducerConfig, NormalizedCacheObject, diff --git a/src/cache/inmemory/policies.ts b/src/cache/inmemory/policies.ts index 955f41ff837..e7c0e1267bb 100644 --- a/src/cache/inmemory/policies.ts +++ b/src/cache/inmemory/policies.ts @@ -11,8 +11,6 @@ import { invariant, InvariantError } from 'ts-invariant'; import { FragmentMap, getFragmentFromSelection, -} from '../../utilities/graphql/fragments'; -import { isField, getTypenameFromResult, storeKeyNameFromField, @@ -22,8 +20,8 @@ import { Reference, isReference, getStoreKeyName, -} from '../../utilities/graphql/storeUtils'; -import { canUseWeakMap } from '../../utilities/common/canUse'; + canUseWeakMap, +} from '../../utilities'; import { IdGetter, ReadMergeModifyContext } from "./types"; import { hasOwn, diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index 520d3abfa88..d0b343db628 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -16,18 +16,17 @@ import { isReference, makeReference, StoreObject, -} from '../../utilities/graphql/storeUtils'; -import { createFragmentMap, FragmentMap } from '../../utilities/graphql/fragments'; -import { shouldInclude } from '../../utilities/graphql/directives'; -import { addTypenameToDocument } from '../../utilities/graphql/transform'; -import { + createFragmentMap, + FragmentMap, + shouldInclude, + addTypenameToDocument, getDefaultValues, getFragmentDefinitions, getMainDefinition, getQueryDefinition, -} from '../../utilities/graphql/getFromAST'; -import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze'; -import { mergeDeepArray } from '../../utilities/common/mergeDeep'; + maybeDeepFreeze, + mergeDeepArray, +} from '../../utilities'; import { Cache } from '../core/types/Cache'; import { DiffQueryAgainstStoreOptions, diff --git a/src/cache/inmemory/types.ts b/src/cache/inmemory/types.ts index 30521af6637..9e83bf65932 100644 --- a/src/cache/inmemory/types.ts +++ b/src/cache/inmemory/types.ts @@ -5,7 +5,7 @@ import { StoreObject, StoreValue, Reference, -} from '../../utilities/graphql/storeUtils'; +} from '../../utilities'; import { FieldValueGetter } from './entityStore'; import { KeyFieldsFunction } from './policies'; import { diff --git a/src/cache/inmemory/writeToStore.ts b/src/cache/inmemory/writeToStore.ts index 9b1583984ca..fea1d64bf5c 100644 --- a/src/cache/inmemory/writeToStore.ts +++ b/src/cache/inmemory/writeToStore.ts @@ -6,15 +6,9 @@ import { createFragmentMap, FragmentMap, getFragmentFromSelection, -} from '../../utilities/graphql/fragments'; - -import { getDefaultValues, getFragmentDefinitions, getOperationDefinition, -} from '../../utilities/graphql/getFromAST'; - -import { getTypenameFromResult, makeReference, isField, @@ -23,10 +17,10 @@ import { StoreObject, Reference, isReference, -} from '../../utilities/graphql/storeUtils'; - -import { shouldInclude, hasDirectives } from '../../utilities/graphql/directives'; -import { cloneDeep } from '../../utilities/common/cloneDeep'; + shouldInclude, + hasDirectives, + cloneDeep, +} from '../../utilities'; import { NormalizedCache, ReadMergeModifyContext } from './types'; import { makeProcessedFieldsMerger, FieldValueToBeMerged, fieldNameFromStoreName } from './helpers'; diff --git a/src/ApolloClient.ts b/src/core/ApolloClient.ts similarity index 96% rename from src/ApolloClient.ts rename to src/core/ApolloClient.ts index 709bca67651..20c53d7e989 100644 --- a/src/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -1,30 +1,33 @@ import { ExecutionResult, DocumentNode } from 'graphql'; import { invariant, InvariantError } from 'ts-invariant'; -import { ApolloLink } from './link/core/ApolloLink'; -import { FetchResult, GraphQLRequest } from './link/core/types'; -import { execute } from './link/core/execute'; -import { ApolloCache } from './cache/core/cache'; -import { DataProxy } from './cache/core/types/DataProxy'; -import { QueryManager } from './core/QueryManager'; +import { ApolloLink, FetchResult, GraphQLRequest, execute } from '../link/core'; +import { ApolloCache, DataProxy } from '../cache'; +import { Observable } from '../utilities'; +import { version } from '../version'; +import { HttpLink, UriFunction } from '../link/http'; + +import { QueryManager } from './QueryManager'; +import { ObservableQuery } from './ObservableQuery'; + import { ApolloQueryResult, OperationVariables, Resolvers, -} from './core/types'; -import { ObservableQuery } from './core/ObservableQuery'; -import { LocalState, FragmentMatcher } from './core/LocalState'; -import { Observable } from './utilities/observables/Observable'; +} from './types'; + import { QueryOptions, WatchQueryOptions, - SubscriptionOptions, MutationOptions, + SubscriptionOptions, WatchQueryFetchPolicy, -} from './core/watchQueryOptions'; -import { version } from './version'; -import { HttpLink } from './link/http/HttpLink'; -import { UriFunction } from './link/http/selectHttpOptionsAndBody'; +} from './watchQueryOptions'; + +import { + LocalState, + FragmentMatcher, +} from './LocalState'; export interface DefaultOptions { watchQuery?: Partial; diff --git a/src/core/LocalState.ts b/src/core/LocalState.ts index d60ed0c9bd9..680b8d92f3d 100644 --- a/src/core/LocalState.ts +++ b/src/core/LocalState.ts @@ -11,29 +11,28 @@ import { import { visit, BREAK } from 'graphql/language/visitor'; import { invariant } from 'ts-invariant'; -import { ApolloCache } from '../cache/core/cache'; -import { - getMainDefinition, - getFragmentDefinitions, -} from '../utilities/graphql/getFromAST'; -import { hasDirectives, shouldInclude } from '../utilities/graphql/directives'; -import { FragmentMap, createFragmentMap } from '../utilities/graphql/fragments'; -import { - buildQueryFromSelectionSet, - removeClientSetsFromDocument, -} from '../utilities/graphql/transform'; -import { mergeDeep, mergeDeepArray } from '../utilities/common/mergeDeep'; +import { ApolloCache } from '../cache'; import { + FragmentMap, + StoreObject, argumentsObjectFromField, - resultKeyNameFromField, + buildQueryFromSelectionSet, + createFragmentMap, + getFragmentDefinitions, + getMainDefinition, + hasDirectives, isField, isInlineFragment, - StoreObject, -} from '../utilities/graphql/storeUtils'; -import { ApolloClient } from '../ApolloClient'; + mergeDeep, + mergeDeepArray, + removeClientSetsFromDocument, + resultKeyNameFromField, + shouldInclude, +} from '../utilities'; +import { ApolloClient } from './ApolloClient'; import { Resolvers, OperationVariables } from './types'; -import { FetchResult } from '../link/core/types'; -import { cacheSlot } from '../cache/inmemory/reactiveVars'; +import { FetchResult } from '../link/core'; +import { cacheSlot } from '../cache'; export type Resolver = ( rootValue?: any, diff --git a/src/data/mutations.ts b/src/core/MutationStore.ts similarity index 100% rename from src/data/mutations.ts rename to src/core/MutationStore.ts diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index e735baaa3ed..b76dc96bd5a 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -1,16 +1,17 @@ import { invariant, InvariantError } from 'ts-invariant'; import { equal } from '@wry/equality'; -import { cloneDeep } from '../utilities/common/cloneDeep'; -import { getOperationDefinition } from '../utilities/graphql/getFromAST'; import { NetworkStatus, isNetworkRequestInFlight } from './networkStatus'; import { + cloneDeep, + getOperationDefinition, Observable, Observer, - ObservableSubscription -} from '../utilities/observables/Observable'; -import { iterateObserversSafely } from '../utilities/observables/iteration'; -import { ApolloError } from '../errors/ApolloError'; + ObservableSubscription, + iterateObserversSafely, + isNonEmptyArray, +} from '../utilities'; +import { ApolloError } from '../errors'; import { QueryManager } from './QueryManager'; import { ApolloQueryResult, OperationVariables } from './types'; import { @@ -20,7 +21,6 @@ import { ErrorPolicy, } from './watchQueryOptions'; import { QueryStoreValue } from './QueryInfo'; -import { isNonEmptyArray } from '../utilities/common/arrays'; import { Reobserver } from './Reobserver'; export type ApolloCurrentQueryResult = ApolloQueryResult & { diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index 740a439d868..0fc41862ebc 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -1,20 +1,21 @@ import { DocumentNode, GraphQLError } from 'graphql'; import { equal } from "@wry/equality"; -import { Cache } from '../cache/core/types/Cache'; -import { ApolloCache } from '../cache/core/cache'; +import { Cache, ApolloCache } from '../cache'; import { WatchQueryOptions } from './watchQueryOptions'; import { ObservableQuery } from './ObservableQuery'; import { QueryListener } from './types'; -import { FetchResult } from '../link/core/types'; -import { ObservableSubscription } from '../utilities/observables/Observable'; -import { isNonEmptyArray } from '../utilities/common/arrays'; -import { graphQLResultHasError } from '../utilities/common/errorHandling'; +import { FetchResult } from '../link/core'; +import { + ObservableSubscription, + isNonEmptyArray, + graphQLResultHasError, +} from '../utilities'; import { NetworkStatus, isNetworkRequestInFlight, } from './networkStatus'; -import { ApolloError } from '../errors/ApolloError'; +import { ApolloError } from '../errors'; export type QueryStoreValue = Pick { // Standard data for all these tests diff --git a/src/core/__tests__/QueryManager/index.ts b/src/core/__tests__/QueryManager/index.ts index 328a311f0f0..a2341344aae 100644 --- a/src/core/__tests__/QueryManager/index.ts +++ b/src/core/__tests__/QueryManager/index.ts @@ -6,8 +6,7 @@ import gql from 'graphql-tag'; import { DocumentNode, GraphQLError } from 'graphql'; import { Observable, Observer } from '../../../utilities/observables/Observable'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { GraphQLRequest, FetchResult } from '../../../link/core/types'; +import { ApolloLink, GraphQLRequest, FetchResult } from '../../../link/core'; import { InMemoryCache, InMemoryCacheConfig } from '../../../cache/inmemory/inMemoryCache'; import { ApolloReducerConfig, @@ -26,7 +25,7 @@ import { ObservableQuery } from '../../ObservableQuery'; import { MutationBaseOptions, MutationOptions, WatchQueryOptions } from '../../watchQueryOptions'; import { QueryManager } from '../../QueryManager'; -import { ApolloError } from '../../../errors/ApolloError'; +import { ApolloError } from '../../../errors'; // testing utils import wrap from '../../../utilities/testing/wrap'; @@ -36,7 +35,7 @@ import observableToPromise, { import subscribeAndCount from '../../../utilities/testing/subscribeAndCount'; import { stripSymbols } from '../../../utilities/testing/stripSymbols'; import { itAsync } from '../../../utilities/testing/itAsync'; -import { ApolloClient } from '../../../ApolloClient'; +import { ApolloClient } from '../../../core' interface MockedMutation { reject: (reason: any) => any; diff --git a/src/core/__tests__/QueryManager/links.ts b/src/core/__tests__/QueryManager/links.ts index 665f22c4118..b4b8da86d39 100644 --- a/src/core/__tests__/QueryManager/links.ts +++ b/src/core/__tests__/QueryManager/links.ts @@ -2,7 +2,7 @@ import gql from 'graphql-tag'; import { Observable } from '../../../utilities/observables/Observable'; -import { ApolloLink } from '../../../link/core/ApolloLink'; +import { ApolloLink } from '../../../link/core'; import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; import { stripSymbols } from '../../../utilities/testing/stripSymbols'; diff --git a/src/core/__tests__/fetchPolicies.ts b/src/core/__tests__/fetchPolicies.ts index 37be0148f51..87390d649f2 100644 --- a/src/core/__tests__/fetchPolicies.ts +++ b/src/core/__tests__/fetchPolicies.ts @@ -1,13 +1,14 @@ import gql from 'graphql-tag'; -import { ApolloLink } from '../../link/core/ApolloLink'; -import { InMemoryCache } from '../../cache/inmemory/inMemoryCache'; -import { stripSymbols } from '../../utilities/testing/stripSymbols'; -import { itAsync } from '../../utilities/testing/itAsync'; -import { ApolloClient } from '../..'; -import subscribeAndCount from '../../utilities/testing/subscribeAndCount'; -import { mockSingleLink } from '../../utilities/testing/mocking/mockLink'; -import { NetworkStatus } from '../networkStatus'; +import { ApolloClient, NetworkStatus } from '../../core'; +import { ApolloLink } from '../../link/core'; +import { InMemoryCache } from '../../cache'; +import { + stripSymbols, + subscribeAndCount, + itAsync, + mockSingleLink, +} from '../../testing'; const query = gql` query { diff --git a/src/core/index.ts b/src/core/index.ts index ba129c93743..d53ec7f6a03 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -3,8 +3,8 @@ export { ApolloClient, ApolloClientOptions, - DefaultOptions -} from '../ApolloClient'; + DefaultOptions, +} from './ApolloClient'; export { ObservableQuery, FetchMoreOptions, @@ -28,24 +28,44 @@ export { NetworkStatus } from './networkStatus'; export * from './types'; export { Resolver, - FragmentMatcher as LocalStateFragmentMatcher, + FragmentMatcher, } from './LocalState'; -export { isApolloError, ApolloError } from '../errors/ApolloError'; +export { isApolloError, ApolloError } from '../errors'; /* Cache */ -export * from '../cache'; +export { + Cache, + ApolloCache, + InMemoryCache, + MissingFieldError, + defaultDataIdFromObject, + makeVar, +} from '../cache'; /* Link */ export * from '../link/core'; export * from '../link/http'; -export * from '../link/utils'; +export { + fromError, + toPromise, + fromPromise, + ServerError, + throwServerError, +} from '../link/utils'; + +/* Utilities */ + export { Observable, Observer, - ObservableSubscription -} from '../utilities/observables/Observable'; + ObservableSubscription, + Reference, + isReference, + makeReference, + StoreObject, +} from '../utilities'; /* Supporting */ diff --git a/src/core/types.ts b/src/core/types.ts index 5bc3933867b..f0f82d2aab3 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -1,6 +1,6 @@ import { DocumentNode, GraphQLError } from 'graphql'; -import { FetchResult } from '../link/core/types'; +import { FetchResult } from '../link/core'; import { QueryInfo } from './QueryInfo'; import { NetworkStatus } from './networkStatus'; import { Resolver } from './LocalState'; diff --git a/src/core/watchQueryOptions.ts b/src/core/watchQueryOptions.ts index 46d7acda81c..fe598bac9be 100644 --- a/src/core/watchQueryOptions.ts +++ b/src/core/watchQueryOptions.ts @@ -1,7 +1,7 @@ import { DocumentNode } from 'graphql'; -import { ApolloCache } from '../cache/core/cache'; -import { FetchResult } from '../link/core/types'; +import { ApolloCache } from '../cache'; +import { FetchResult } from '../link/core'; import { MutationQueryReducersMap } from './types'; import { PureQueryOptions, OperationVariables } from './types'; diff --git a/src/errors/__tests__/ApolloError.ts b/src/errors/__tests__/ApolloError.ts index f280a3c9789..f1a69f03b3d 100644 --- a/src/errors/__tests__/ApolloError.ts +++ b/src/errors/__tests__/ApolloError.ts @@ -1,4 +1,4 @@ -import { ApolloError } from '../ApolloError'; +import { ApolloError } from '..'; import { GraphQLError } from 'graphql'; describe('ApolloError', () => { diff --git a/src/errors/ApolloError.ts b/src/errors/index.ts similarity index 91% rename from src/errors/ApolloError.ts rename to src/errors/index.ts index 7d26ad1a73e..99b279d8588 100644 --- a/src/errors/ApolloError.ts +++ b/src/errors/index.ts @@ -1,8 +1,8 @@ import { GraphQLError } from 'graphql'; -import { isNonEmptyArray } from '../utilities/common/arrays'; -import { ServerParseError } from '../link/http/parseAndCheckHttpResponse'; -import { ServerError } from '../link/utils/throwServerError'; +import { isNonEmptyArray } from '../utilities'; +import { ServerParseError } from '../link/http'; +import { ServerError } from '../link/utils'; export function isApolloError(err: Error): err is ApolloError { return err.hasOwnProperty('graphQLErrors'); diff --git a/src/link/batch-http/batchHttpLink.ts b/src/link/batch-http/batchHttpLink.ts index 0130df1f104..ba6d5812120 100644 --- a/src/link/batch-http/batchHttpLink.ts +++ b/src/link/batch-http/batchHttpLink.ts @@ -1,18 +1,17 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; -import { fromError } from '../utils/fromError'; -import { serializeFetchParameter } from '../http/serializeFetchParameter'; -import { selectURI } from '../http/selectURI'; -import { parseAndCheckHttpResponse } from '../http/parseAndCheckHttpResponse'; -import { checkFetcher } from '../http/checkFetcher'; +import { ApolloLink, Operation, FetchResult } from '../core'; +import { Observable } from '../../utilities'; +import { fromError } from '../utils'; import { + serializeFetchParameter, + selectURI, + parseAndCheckHttpResponse, + checkFetcher, selectHttpOptionsAndBody, fallbackHttpConfig, - HttpOptions -} from '../http/selectHttpOptionsAndBody'; -import { createSignalIfSupported } from '../http/createSignalIfSupported'; -import { BatchLink } from '../batch/batchLink'; + HttpOptions, + createSignalIfSupported, +} from '../http'; +import { BatchLink } from '../batch'; export namespace BatchHttpLink { export interface Options extends HttpOptions { diff --git a/src/link/batch/batchLink.ts b/src/link/batch/batchLink.ts index 2c35f5e8cfb..1872ee54948 100644 --- a/src/link/batch/batchLink.ts +++ b/src/link/batch/batchLink.ts @@ -1,7 +1,5 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; -import { NextLink } from '../core/types'; +import { ApolloLink, Operation, FetchResult, NextLink } from '../core'; +import { Observable } from '../../utilities'; import { OperationBatcher, BatchHandler } from './batching'; export { OperationBatcher, BatchableRequest, BatchHandler } from './batching'; diff --git a/src/link/batch/batching.ts b/src/link/batch/batching.ts index ceb5d4c6a70..b15f60ef39a 100644 --- a/src/link/batch/batching.ts +++ b/src/link/batch/batching.ts @@ -1,6 +1,5 @@ -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; -import { NextLink } from '../core/types'; +import { Operation, FetchResult, NextLink } from '../core'; +import { Observable } from '../../utilities'; export type BatchHandler = ( operations: Operation[], diff --git a/src/link/context/__tests__/index.ts b/src/link/context/__tests__/index.ts index 8284cdc6776..f677bd664f5 100644 --- a/src/link/context/__tests__/index.ts +++ b/src/link/context/__tests__/index.ts @@ -1,6 +1,6 @@ import gql from 'graphql-tag'; -import { ApolloLink } from '../../core/ApolloLink'; +import { ApolloLink } from '../../core'; import { Observable } from '../../../utilities/observables/Observable'; import { execute } from '../../core/execute'; import { setContext } from '../index'; diff --git a/src/link/context/index.ts b/src/link/context/index.ts index 84ee52cfa26..c427a769fa3 100644 --- a/src/link/context/index.ts +++ b/src/link/context/index.ts @@ -1,7 +1,5 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, GraphQLRequest } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; -import { NextLink } from '../core/types'; +import { ApolloLink, Operation, GraphQLRequest, NextLink } from '../core'; +import { Observable } from '../../utilities'; export type ContextSetter = ( operation: GraphQLRequest, diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index 234700e2a01..62ef169ca3c 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -1,6 +1,6 @@ import { InvariantError, invariant } from 'ts-invariant'; -import { Observable } from '../../utilities/observables/Observable'; +import { Observable } from '../../utilities'; import { NextLink, Operation, @@ -8,9 +8,11 @@ import { FetchResult, GraphQLRequest } from './types'; -import { validateOperation } from '../utils/validateOperation'; -import { createOperation } from '../utils/createOperation'; -import { transformOperation } from '../utils/transformOperation'; +import { + validateOperation, + createOperation, + transformOperation, +} from '../utils'; function passthrough(op: Operation, forward: NextLink) { return (forward ? forward(op) : Observable.of()) as Observable; diff --git a/src/link/core/types.ts b/src/link/core/types.ts index e40d4a748d8..9f5be3497f4 100644 --- a/src/link/core/types.ts +++ b/src/link/core/types.ts @@ -2,7 +2,7 @@ import { DocumentNode } from 'graphql/language/ast'; import { ExecutionResult } from 'graphql/execution/execute'; export { DocumentNode }; -import { Observable } from '../../utilities/observables/Observable'; +import { Observable } from '../../utilities'; export interface GraphQLRequest { query: DocumentNode; diff --git a/src/link/error/index.ts b/src/link/error/index.ts index 52f45e6ec1a..68027391319 100644 --- a/src/link/error/index.ts +++ b/src/link/error/index.ts @@ -1,12 +1,10 @@ import { GraphQLError, ExecutionResult } from 'graphql'; -import { ApolloLink } from '../core/ApolloLink'; -import { Observable } from '../../utilities/observables/Observable'; -import { Operation, FetchResult } from '../core/types'; -import { NextLink } from '../core/types'; +import { ApolloLink, Operation, FetchResult, NextLink } from '../core'; +import { Observable } from '../../utilities'; -import { ServerError } from '../utils/throwServerError'; -import { ServerParseError } from '../http/parseAndCheckHttpResponse'; +import { ServerError } from '../utils'; +import { ServerParseError } from '../http'; export interface ErrorResponse { graphQLErrors?: ReadonlyArray; diff --git a/src/link/http/HttpLink.ts b/src/link/http/HttpLink.ts index 31cac386cce..cc2a8d5fa14 100644 --- a/src/link/http/HttpLink.ts +++ b/src/link/http/HttpLink.ts @@ -1,5 +1,4 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { RequestHandler } from '../core/types'; +import { ApolloLink, RequestHandler } from '../core'; import { HttpOptions } from './selectHttpOptionsAndBody'; import { createHttpLink } from './createHttpLink'; diff --git a/src/link/http/createHttpLink.ts b/src/link/http/createHttpLink.ts index b22dec7352b..38dd803cfd6 100644 --- a/src/link/http/createHttpLink.ts +++ b/src/link/http/createHttpLink.ts @@ -1,6 +1,7 @@ import { DefinitionNode } from 'graphql'; -import { Observable } from '../../utilities/observables/Observable'; +import { ApolloLink } from '../core'; +import { Observable } from '../../utilities'; import { serializeFetchParameter } from './serializeFetchParameter'; import { selectURI } from './selectURI'; import { parseAndCheckHttpResponse } from './parseAndCheckHttpResponse'; @@ -12,8 +13,7 @@ import { } from './selectHttpOptionsAndBody'; import { createSignalIfSupported } from './createSignalIfSupported'; import { rewriteURIForGET } from './rewriteURIForGET'; -import { ApolloLink } from '../core/ApolloLink'; -import { fromError } from '../utils/fromError'; +import { fromError } from '../utils'; export const createHttpLink = (linkOptions: HttpOptions = {}) => { let { diff --git a/src/link/http/parseAndCheckHttpResponse.ts b/src/link/http/parseAndCheckHttpResponse.ts index 2528e0624e3..2f314fd0a5b 100644 --- a/src/link/http/parseAndCheckHttpResponse.ts +++ b/src/link/http/parseAndCheckHttpResponse.ts @@ -1,5 +1,5 @@ -import { Operation } from '../core/types'; -import { throwServerError } from '../utils/throwServerError'; +import { Operation } from '../core'; +import { throwServerError } from '../utils'; const { hasOwnProperty } = Object.prototype; diff --git a/src/link/http/selectHttpOptionsAndBody.ts b/src/link/http/selectHttpOptionsAndBody.ts index d53993b4c4e..93c62d614d4 100644 --- a/src/link/http/selectHttpOptionsAndBody.ts +++ b/src/link/http/selectHttpOptionsAndBody.ts @@ -1,6 +1,6 @@ import { print } from 'graphql/language/printer'; -import { Operation } from '../core/types'; +import { Operation } from '../core'; export interface UriFunction { (operation: Operation): string; diff --git a/src/link/http/selectURI.ts b/src/link/http/selectURI.ts index 9412f2fba47..461098f2e2e 100644 --- a/src/link/http/selectURI.ts +++ b/src/link/http/selectURI.ts @@ -1,4 +1,4 @@ -import { Operation } from '../core/types'; +import { Operation } from '../core'; export const selectURI = ( operation: Operation, diff --git a/src/link/retry/delayFunction.ts b/src/link/retry/delayFunction.ts index 5e3ed60cda4..2b4bb3f2cc1 100644 --- a/src/link/retry/delayFunction.ts +++ b/src/link/retry/delayFunction.ts @@ -1,4 +1,4 @@ -import { Operation } from '../core/types'; +import { Operation } from '../core'; /** * Advanced mode: a function that implements the strategy for calculating delays diff --git a/src/link/retry/retryFunction.ts b/src/link/retry/retryFunction.ts index 5dddbb97ba8..891a76317b6 100644 --- a/src/link/retry/retryFunction.ts +++ b/src/link/retry/retryFunction.ts @@ -1,4 +1,4 @@ -import { Operation } from '../core/types'; +import { Operation } from '../core'; /** * Advanced mode: a function that determines both whether a particular diff --git a/src/link/retry/retryLink.ts b/src/link/retry/retryLink.ts index 49f203c9c8a..46c36d50f64 100644 --- a/src/link/retry/retryLink.ts +++ b/src/link/retry/retryLink.ts @@ -1,7 +1,5 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; -import { NextLink } from '../core/types'; +import { ApolloLink, Operation, FetchResult, NextLink } from '../core'; +import { Observable } from '../../utilities'; import { DelayFunction, DelayFunctionOptions, diff --git a/src/link/schema/index.ts b/src/link/schema/index.ts index 1d4df130dfb..d2bde09767f 100644 --- a/src/link/schema/index.ts +++ b/src/link/schema/index.ts @@ -1,9 +1,8 @@ import { execute } from 'graphql/execution/execute'; import { GraphQLSchema } from 'graphql/type/schema'; -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; +import { ApolloLink, Operation, FetchResult } from '../core'; +import { Observable } from '../../utilities'; export namespace SchemaLink { export type ResolverContextFunction = ( diff --git a/src/link/utils/createOperation.ts b/src/link/utils/createOperation.ts index dba0c410b09..8970e3595d1 100644 --- a/src/link/utils/createOperation.ts +++ b/src/link/utils/createOperation.ts @@ -1,4 +1,4 @@ -import { GraphQLRequest, Operation } from '../core/types'; +import { GraphQLRequest, Operation } from '../core'; export function createOperation( starting: any, diff --git a/src/link/utils/fromError.ts b/src/link/utils/fromError.ts index 7d0a6ef0340..f832a7c62d2 100644 --- a/src/link/utils/fromError.ts +++ b/src/link/utils/fromError.ts @@ -1,4 +1,4 @@ -import { Observable } from '../../utilities/observables/Observable'; +import { Observable } from '../../utilities'; export function fromError(errorValue: any): Observable { return new Observable(observer => { diff --git a/src/link/utils/fromPromise.ts b/src/link/utils/fromPromise.ts index 8485c5d6364..039d71654a5 100644 --- a/src/link/utils/fromPromise.ts +++ b/src/link/utils/fromPromise.ts @@ -1,4 +1,4 @@ -import { Observable } from '../../utilities/observables/Observable'; +import { Observable } from '../../utilities'; export function fromPromise(promise: Promise): Observable { return new Observable(observer => { diff --git a/src/link/utils/index.ts b/src/link/utils/index.ts index 81a951851fc..5c28f516365 100644 --- a/src/link/utils/index.ts +++ b/src/link/utils/index.ts @@ -2,3 +2,6 @@ export { fromError } from './fromError'; export { toPromise } from './toPromise'; export { fromPromise } from './fromPromise'; export { ServerError, throwServerError } from './throwServerError'; +export { validateOperation } from './validateOperation'; +export { createOperation } from './createOperation'; +export { transformOperation } from './transformOperation'; diff --git a/src/link/utils/toPromise.ts b/src/link/utils/toPromise.ts index 6ed43d5207a..5752348dee5 100644 --- a/src/link/utils/toPromise.ts +++ b/src/link/utils/toPromise.ts @@ -1,6 +1,6 @@ import { invariant } from 'ts-invariant'; -import { Observable } from '../../utilities/observables/Observable'; +import { Observable } from '../../utilities'; export function toPromise(observable: Observable): Promise { let completed = false; diff --git a/src/link/utils/transformOperation.ts b/src/link/utils/transformOperation.ts index 95b78b3eaba..41a54ce48f1 100644 --- a/src/link/utils/transformOperation.ts +++ b/src/link/utils/transformOperation.ts @@ -1,5 +1,5 @@ -import { GraphQLRequest, Operation } from '../core/types'; -import { getOperationName } from '../../utilities/graphql/getFromAST'; +import { GraphQLRequest, Operation } from '../core'; +import { getOperationName } from '../../utilities'; export function transformOperation(operation: GraphQLRequest): GraphQLRequest { const transformedOperation: GraphQLRequest = { diff --git a/src/link/utils/validateOperation.ts b/src/link/utils/validateOperation.ts index e04fb46ddb1..61e1b855430 100644 --- a/src/link/utils/validateOperation.ts +++ b/src/link/utils/validateOperation.ts @@ -1,6 +1,6 @@ import { InvariantError } from 'ts-invariant'; -import { GraphQLRequest } from '../core/types'; +import { GraphQLRequest } from '../core'; export function validateOperation(operation: GraphQLRequest): GraphQLRequest { const OPERATION_FIELDS = [ diff --git a/src/link/ws/__tests__/webSocketLink.ts b/src/link/ws/__tests__/webSocketLink.ts index cc91e8fc307..7524d3e1305 100644 --- a/src/link/ws/__tests__/webSocketLink.ts +++ b/src/link/ws/__tests__/webSocketLink.ts @@ -2,9 +2,9 @@ import { SubscriptionClient } from 'subscriptions-transport-ws'; import { ExecutionResult } from 'graphql'; import gql from 'graphql-tag'; -import { Observable } from '../../../utilities/observables/Observable'; -import { execute } from '../../core/execute'; -import { WebSocketLink } from '../webSocketLink'; +import { Observable } from '../../../utilities'; +import { execute } from '../../core'; +import { WebSocketLink } from '..'; const query = gql` query SampleQuery { diff --git a/src/link/ws/index.ts b/src/link/ws/index.ts index 0dcd3aaea56..1cc1fffa0d6 100644 --- a/src/link/ws/index.ts +++ b/src/link/ws/index.ts @@ -1 +1,55 @@ -export * from './webSocketLink'; +import { SubscriptionClient, ClientOptions } from 'subscriptions-transport-ws'; + +import { ApolloLink, Operation, FetchResult } from '../core'; +import { Observable } from '../../utilities'; + +export namespace WebSocketLink { + /** + * Configuration to use when constructing the subscription client (subscriptions-transport-ws). + */ + export interface Configuration { + /** + * The endpoint to connect to. + */ + uri: string; + + /** + * Options to pass when constructing the subscription client. + */ + options?: ClientOptions; + + /** + * A custom WebSocket implementation to use. + */ + webSocketImpl?: any; + } +} + +// For backwards compatibility. +export import WebSocketParams = WebSocketLink.Configuration; + +export class WebSocketLink extends ApolloLink { + private subscriptionClient: SubscriptionClient; + + constructor( + paramsOrClient: WebSocketLink.Configuration | SubscriptionClient, + ) { + super(); + + if (paramsOrClient instanceof SubscriptionClient) { + this.subscriptionClient = paramsOrClient; + } else { + this.subscriptionClient = new SubscriptionClient( + paramsOrClient.uri, + paramsOrClient.options, + paramsOrClient.webSocketImpl, + ); + } + } + + public request(operation: Operation): Observable | null { + return this.subscriptionClient.request(operation) as Observable< + FetchResult + >; + } +} diff --git a/src/link/ws/webSocketLink.ts b/src/link/ws/webSocketLink.ts deleted file mode 100644 index 4b3f5faf780..00000000000 --- a/src/link/ws/webSocketLink.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { ApolloLink } from '../core/ApolloLink'; -import { Operation, FetchResult } from '../core/types'; -import { Observable } from '../../utilities/observables/Observable'; - -import { SubscriptionClient, ClientOptions } from 'subscriptions-transport-ws'; - -export namespace WebSocketLink { - /** - * Configuration to use when constructing the subscription client (subscriptions-transport-ws). - */ - export interface Configuration { - /** - * The endpoint to connect to. - */ - uri: string; - - /** - * Options to pass when constructing the subscription client. - */ - options?: ClientOptions; - - /** - * A custom WebSocket implementation to use. - */ - webSocketImpl?: any; - } -} - -// For backwards compatibility. -export import WebSocketParams = WebSocketLink.Configuration; - -export class WebSocketLink extends ApolloLink { - private subscriptionClient: SubscriptionClient; - - constructor( - paramsOrClient: WebSocketLink.Configuration | SubscriptionClient, - ) { - super(); - - if (paramsOrClient instanceof SubscriptionClient) { - this.subscriptionClient = paramsOrClient; - } else { - this.subscriptionClient = new SubscriptionClient( - paramsOrClient.uri, - paramsOrClient.options, - paramsOrClient.webSocketImpl, - ); - } - } - - public request(operation: Operation): Observable | null { - return this.subscriptionClient.request(operation) as Observable< - FetchResult - >; - } -} diff --git a/src/react/components/Mutation.tsx b/src/react/components/Mutation.tsx index ba23a191ec2..6a725d8ddd4 100644 --- a/src/react/components/Mutation.tsx +++ b/src/react/components/Mutation.tsx @@ -1,8 +1,8 @@ import PropTypes from 'prop-types'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; import { MutationComponentOptions } from './types'; -import { useMutation } from '../hooks/useMutation'; +import { useMutation } from '../hooks'; export function Mutation( props: MutationComponentOptions diff --git a/src/react/components/Query.tsx b/src/react/components/Query.tsx index 8134da5c492..0f180411ff3 100644 --- a/src/react/components/Query.tsx +++ b/src/react/components/Query.tsx @@ -1,8 +1,8 @@ import PropTypes from 'prop-types'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; import { QueryComponentOptions } from './types'; -import { useQuery } from '../hooks/useQuery'; +import { useQuery } from '../hooks'; export function Query( props: QueryComponentOptions diff --git a/src/react/components/Subscription.tsx b/src/react/components/Subscription.tsx index f625290289f..1d3786087e4 100644 --- a/src/react/components/Subscription.tsx +++ b/src/react/components/Subscription.tsx @@ -1,8 +1,8 @@ import PropTypes from 'prop-types'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; import { SubscriptionComponentOptions } from './types'; -import { useSubscription } from '../hooks/useSubscription'; +import { useSubscription } from '../hooks'; export function Subscription( props: SubscriptionComponentOptions diff --git a/src/react/components/__tests__/client/Mutation.test.tsx b/src/react/components/__tests__/client/Mutation.test.tsx index 0425d1163b4..e3c3861d3d8 100644 --- a/src/react/components/__tests__/client/Mutation.test.tsx +++ b/src/react/components/__tests__/client/Mutation.test.tsx @@ -3,14 +3,11 @@ import gql from 'graphql-tag'; import { ExecutionResult, GraphQLError } from 'graphql'; import { render, cleanup, fireEvent, wait } from '@testing-library/react'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloError } from '../../../../errors/ApolloError'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { DataProxy } from '../../../../cache/core/types/DataProxy'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { MockedProvider } from '../../../../utilities/testing/mocking/MockedProvider'; -import { MockLink, mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloError } from '../../../../errors'; +import { DataProxy, InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider } from '../../../context'; +import { stripSymbols, MockedProvider, MockLink, mockSingleLink } from '../../../../testing'; import { Query } from '../../Query'; import { Mutation } from '../../Mutation'; diff --git a/src/react/components/__tests__/client/Query.test.tsx b/src/react/components/__tests__/client/Query.test.tsx index 84279dfed7f..5d2814476aa 100644 --- a/src/react/components/__tests__/client/Query.test.tsx +++ b/src/react/components/__tests__/client/Query.test.tsx @@ -3,17 +3,13 @@ import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; import { render, wait } from '@testing-library/react'; -import { ApolloClient } from '../../../../ApolloClient'; -import { NetworkStatus } from '../../../../core/networkStatus'; -import { ApolloError } from '../../../../errors/ApolloError'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { MockedProvider } from '../../../../utilities/testing/mocking/MockedProvider'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient, NetworkStatus } from '../../../../core'; +import { ApolloError } from '../../../../errors'; +import { ApolloLink } from '../../../../link/core'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider } from '../../../context'; +import { itAsync, stripSymbols, MockedProvider, mockSingleLink } from '../../../../testing'; import { Query } from '../../Query'; -import { itAsync } from '../../../../utilities/testing/itAsync'; const allPeopleQuery: DocumentNode = gql` query people { diff --git a/src/react/components/__tests__/client/Subscription.test.tsx b/src/react/components/__tests__/client/Subscription.test.tsx index 97b9e48c6a3..b6a33ca9165 100644 --- a/src/react/components/__tests__/client/Subscription.test.tsx +++ b/src/react/components/__tests__/client/Subscription.test.tsx @@ -2,14 +2,12 @@ import React from 'react'; import gql from 'graphql-tag'; import { render, wait } from '@testing-library/react'; -import { ApolloClient } from '../../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { MockSubscriptionLink } from '../../../../utilities/testing/mocking/mockSubscriptionLink'; -import { Operation } from '../../../../link/core/types'; +import { ApolloClient } from '../../../../core'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider } from '../../../context'; +import { ApolloLink, Operation } from '../../../../link/core'; +import { itAsync, MockSubscriptionLink } from '../../../../testing'; import { Subscription } from '../../Subscription'; -import { itAsync } from '../../../../utilities/testing/itAsync'; const results = [ 'Luke Skywalker', diff --git a/src/react/components/__tests__/ssr/getDataFromTree.test.tsx b/src/react/components/__tests__/ssr/getDataFromTree.test.tsx index 66caf7c315f..15bc9a7fa0a 100644 --- a/src/react/components/__tests__/ssr/getDataFromTree.test.tsx +++ b/src/react/components/__tests__/ssr/getDataFromTree.test.tsx @@ -2,12 +2,11 @@ import React from 'react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { getApolloContext } from '../../../context/ApolloContext'; -import { getDataFromTree } from '../../../ssr/getDataFromTree'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; +import { ApolloClient } from '../../../../core'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider, getApolloContext } from '../../../context'; +import { getDataFromTree } from '../../../ssr'; +import { mockSingleLink } from '../../../../testing'; import { Query } from '../../Query'; describe('SSR', () => { diff --git a/src/react/components/__tests__/ssr/server.test.tsx b/src/react/components/__tests__/ssr/server.test.tsx index 81c028e6529..7fb8704c0ab 100644 --- a/src/react/components/__tests__/ssr/server.test.tsx +++ b/src/react/components/__tests__/ssr/server.test.tsx @@ -10,12 +10,12 @@ import { } from 'graphql'; import gql from 'graphql-tag'; -import { ApolloClient } from '../../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { Observable } from '../../../../utilities/observables/Observable'; -import { renderToStringWithData } from '../../../ssr/renderToStringWithData'; +import { ApolloClient } from '../../../../core'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider } from '../../../context'; +import { ApolloLink } from '../../../../link/core'; +import { Observable } from '../../../../utilities'; +import { renderToStringWithData } from '../../../ssr'; import { Query } from '../../Query'; const planetMap = new Map([['Planet:1', { id: 'Planet:1', name: 'Tatooine' }]]); diff --git a/src/react/components/types.ts b/src/react/components/types.ts index 9e48ec62a6f..7229777f6d7 100644 --- a/src/react/components/types.ts +++ b/src/react/components/types.ts @@ -1,6 +1,6 @@ import { DocumentNode } from 'graphql'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; import { QueryFunctionOptions, QueryResult, diff --git a/src/react/context/ApolloConsumer.tsx b/src/react/context/ApolloConsumer.tsx index 8c5c1d7f1fe..97316113c1b 100644 --- a/src/react/context/ApolloConsumer.tsx +++ b/src/react/context/ApolloConsumer.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { invariant } from 'ts-invariant'; -import { ApolloClient } from '../../ApolloClient'; +import { ApolloClient } from '../../core'; import { getApolloContext } from './ApolloContext'; export interface ApolloConsumerProps { diff --git a/src/react/context/ApolloContext.ts b/src/react/context/ApolloContext.ts index e9fa0911796..404c2c0145a 100644 --- a/src/react/context/ApolloContext.ts +++ b/src/react/context/ApolloContext.ts @@ -1,5 +1,5 @@ import React from 'react'; -import { ApolloClient } from '../../ApolloClient'; +import { ApolloClient } from '../../core'; export interface ApolloContextValue { client?: ApolloClient; diff --git a/src/react/context/ApolloProvider.tsx b/src/react/context/ApolloProvider.tsx index 42fa65d1b2f..adc6d66dd3a 100644 --- a/src/react/context/ApolloProvider.tsx +++ b/src/react/context/ApolloProvider.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { invariant } from 'ts-invariant'; -import { ApolloClient } from '../../ApolloClient'; +import { ApolloClient } from '../../core'; import { getApolloContext } from './ApolloContext'; export interface ApolloProviderProps { diff --git a/src/react/context/__tests__/ApolloConsumer.test.tsx b/src/react/context/__tests__/ApolloConsumer.test.tsx index 27d3d96320b..0cf0b858b81 100644 --- a/src/react/context/__tests__/ApolloConsumer.test.tsx +++ b/src/react/context/__tests__/ApolloConsumer.test.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { render, cleanup } from '@testing-library/react'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; +import { ApolloLink } from '../../../link/core'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache as Cache } from '../../../cache'; import { ApolloProvider } from '../ApolloProvider'; import { ApolloConsumer } from '../ApolloConsumer'; import { getApolloContext } from '../ApolloContext'; diff --git a/src/react/context/__tests__/ApolloProvider.test.tsx b/src/react/context/__tests__/ApolloProvider.test.tsx index 9ef9d72ba09..cd844668c03 100644 --- a/src/react/context/__tests__/ApolloProvider.test.tsx +++ b/src/react/context/__tests__/ApolloProvider.test.tsx @@ -1,9 +1,9 @@ import React, { useContext } from 'react'; import { render, cleanup } from '@testing-library/react'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; +import { ApolloLink } from '../../../link/core'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache as Cache } from '../../../cache'; import { ApolloProvider } from '../ApolloProvider'; import { getApolloContext } from '../ApolloContext'; diff --git a/src/react/context/index.ts b/src/react/context/index.ts new file mode 100644 index 00000000000..860b3839b46 --- /dev/null +++ b/src/react/context/index.ts @@ -0,0 +1,3 @@ +export * from './ApolloConsumer'; +export * from './ApolloContext'; +export * from './ApolloProvider'; diff --git a/src/react/data/MutationData.ts b/src/react/data/MutationData.ts index 88cd9d160d5..64945215f8d 100644 --- a/src/react/data/MutationData.ts +++ b/src/react/data/MutationData.ts @@ -1,7 +1,7 @@ import { equal } from '@wry/equality'; -import { DocumentType } from '../parser/parser'; -import { ApolloError } from '../../errors/ApolloError'; +import { DocumentType } from '../parser'; +import { ApolloError } from '../../errors'; import { MutationDataOptions, MutationTuple, @@ -9,8 +9,8 @@ import { MutationResult } from '../types/types'; import { OperationData } from './OperationData'; -import { OperationVariables } from '../../core/types'; -import { FetchResult } from '../../link/core/types'; +import { OperationVariables } from '../../core'; +import { FetchResult } from '../../link/core'; export class MutationData< TData = any, diff --git a/src/react/data/OperationData.ts b/src/react/data/OperationData.ts index 92e1f6fbe6d..54b1352b1be 100644 --- a/src/react/data/OperationData.ts +++ b/src/react/data/OperationData.ts @@ -2,8 +2,8 @@ import { DocumentNode } from 'graphql'; import { equal } from '@wry/equality'; import { invariant } from 'ts-invariant'; -import { ApolloClient } from '../../ApolloClient'; -import { DocumentType, parser, operationName } from '../parser/parser'; +import { ApolloClient } from '../../core'; +import { DocumentType, parser, operationName } from '../parser'; import { CommonOptions } from '../types/types'; export abstract class OperationData { diff --git a/src/react/data/QueryData.ts b/src/react/data/QueryData.ts index 898cc74099f..ce3e45f20a2 100644 --- a/src/react/data/QueryData.ts +++ b/src/react/data/QueryData.ts @@ -1,22 +1,21 @@ import { equal } from '@wry/equality'; -import { ApolloError } from '../../errors/ApolloError'; -import { NetworkStatus } from '../../core/networkStatus'; +import { ApolloError } from '../../errors'; + import { + NetworkStatus, FetchMoreQueryOptions, - SubscribeToMoreOptions -} from '../../core/watchQueryOptions'; -import { + SubscribeToMoreOptions, ObservableQuery, FetchMoreOptions, UpdateQueryOptions -} from '../../core/ObservableQuery'; +} from '../../core'; import { ObservableSubscription -} from '../../utilities/observables/Observable'; +} from '../../utilities'; -import { DocumentType } from '../parser/parser'; +import { DocumentType } from '../parser'; import { QueryResult, QueryPreviousData, diff --git a/src/react/data/index.ts b/src/react/data/index.ts new file mode 100644 index 00000000000..26776e66350 --- /dev/null +++ b/src/react/data/index.ts @@ -0,0 +1,4 @@ +export { SubscriptionData } from './SubscriptionData'; +export { OperationData } from './OperationData'; +export { MutationData } from './MutationData'; +export { QueryData } from './QueryData'; diff --git a/src/react/hoc/__tests__/client-option.test.tsx b/src/react/hoc/__tests__/client-option.test.tsx index b0633ae3179..52de762ef6f 100644 --- a/src/react/hoc/__tests__/client-option.test.tsx +++ b/src/react/hoc/__tests__/client-option.test.tsx @@ -3,14 +3,12 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../ApolloClient'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../core'; +import { ApolloProvider } from '../../context'; +import { InMemoryCache as Cache } from '../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../testing'; import { graphql } from '../graphql'; import { ChildProps } from '../types'; -import { itAsync } from '../../../utilities/testing/itAsync'; describe('client option', () => { it('renders with client from options', () => { diff --git a/src/react/hoc/__tests__/fragments.test.tsx b/src/react/hoc/__tests__/fragments.test.tsx index 6aa69c6fe5c..60cb5e9fc01 100644 --- a/src/react/hoc/__tests__/fragments.test.tsx +++ b/src/react/hoc/__tests__/fragments.test.tsx @@ -3,14 +3,12 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../ApolloClient'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../core'; +import { ApolloProvider } from '../../context'; +import { InMemoryCache as Cache } from '../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../testing'; import { graphql } from '../graphql'; import { ChildProps } from '../types'; -import { itAsync } from '../../../utilities/testing/itAsync'; describe('fragments', () => { // XXX in a later version, we should support this for composition diff --git a/src/react/hoc/__tests__/mutations/index.test.tsx b/src/react/hoc/__tests__/mutations/index.test.tsx index e39123f3f47..b687d6980fe 100644 --- a/src/react/hoc/__tests__/mutations/index.test.tsx +++ b/src/react/hoc/__tests__/mutations/index.test.tsx @@ -3,12 +3,14 @@ import { render, cleanup } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; -import { createMockClient } from '../../../../utilities/testing/mocking/mockClient'; -import { MockedProvider } from '../../../../utilities/testing/mocking/MockedProvider'; -import { ApolloClient } from '../../../../ApolloClient'; -import { NormalizedCacheObject } from '../../../../cache/inmemory/types'; -import { ApolloProvider } from '../../../context/ApolloProvider'; +import { ApolloClient } from '../../../../core'; +import { + stripSymbols, + createMockClient, + MockedProvider, +} from '../../../../testing'; +import { NormalizedCacheObject } from '../../../../cache'; +import { ApolloProvider } from '../../../context'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; diff --git a/src/react/hoc/__tests__/mutations/queries.test.tsx b/src/react/hoc/__tests__/mutations/queries.test.tsx index 51229b4470f..1c32f5e89f6 100644 --- a/src/react/hoc/__tests__/mutations/queries.test.tsx +++ b/src/react/hoc/__tests__/mutations/queries.test.tsx @@ -3,16 +3,17 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { MutationUpdaterFn } from '../../../../core/watchQueryOptions'; -import { createMockClient } from '../../../../utilities/testing/mocking/mockClient'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient, MutationUpdaterFn } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { + itAsync, + stripSymbols, + createMockClient, + mockSingleLink, +} from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('graphql(mutation) query integration', () => { itAsync('allows for passing optimisticResponse for a mutation', (resolve, reject) => { diff --git a/src/react/hoc/__tests__/mutations/recycled-queries.test.tsx b/src/react/hoc/__tests__/mutations/recycled-queries.test.tsx index cbc4365395b..40bcbb731d9 100644 --- a/src/react/hoc/__tests__/mutations/recycled-queries.test.tsx +++ b/src/react/hoc/__tests__/mutations/recycled-queries.test.tsx @@ -3,13 +3,11 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { MutationUpdaterFn } from '../../../../core/watchQueryOptions'; +import { ApolloClient, MutationUpdaterFn } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; import { MutationFunction } from '../../../types/types'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; diff --git a/src/react/hoc/__tests__/queries/api.test.tsx b/src/react/hoc/__tests__/queries/api.test.tsx index b48a916206b..566ea979284 100644 --- a/src/react/hoc/__tests__/queries/api.test.tsx +++ b/src/react/hoc/__tests__/queries/api.test.tsx @@ -3,14 +3,12 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] api', () => { const consoleWarn = console.warn; diff --git a/src/react/hoc/__tests__/queries/errors.test.tsx b/src/react/hoc/__tests__/queries/errors.test.tsx index b120383cdc5..c854d40ae20 100644 --- a/src/react/hoc/__tests__/queries/errors.test.tsx +++ b/src/react/hoc/__tests__/queries/errors.test.tsx @@ -4,16 +4,14 @@ import gql from 'graphql-tag'; import { withState } from 'recompose'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; import { QueryResult } from '../../../types/types'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { Query } from '../../../components/Query'; import { graphql } from '../../graphql'; import { ChildProps, DataValue } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] errors', () => { let error: typeof console.error; diff --git a/src/react/hoc/__tests__/queries/index.test.tsx b/src/react/hoc/__tests__/queries/index.test.tsx index 513e15aa1bd..c352db302d9 100644 --- a/src/react/hoc/__tests__/queries/index.test.tsx +++ b/src/react/hoc/__tests__/queries/index.test.tsx @@ -4,15 +4,13 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloLink } from '../../../../link/core'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps, DataProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('queries', () => { let error: typeof console.error; diff --git a/src/react/hoc/__tests__/queries/lifecycle.test.tsx b/src/react/hoc/__tests__/queries/lifecycle.test.tsx index e3ce07dbff7..d1a0a38bb3e 100644 --- a/src/react/hoc/__tests__/queries/lifecycle.test.tsx +++ b/src/react/hoc/__tests__/queries/lifecycle.test.tsx @@ -3,14 +3,13 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { Query as QueryComponent } from '../../../components/Query'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, mockSingleLink } from '../../../../testing'; +import { Query as QueryComponent } from '../../../components'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] lifecycle', () => { // lifecycle diff --git a/src/react/hoc/__tests__/queries/loading.test.tsx b/src/react/hoc/__tests__/queries/loading.test.tsx index f06e7650ffb..3289f58c216 100644 --- a/src/react/hoc/__tests__/queries/loading.test.tsx +++ b/src/react/hoc/__tests__/queries/loading.test.tsx @@ -3,13 +3,12 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] loading', () => { // networkStatus / loading diff --git a/src/react/hoc/__tests__/queries/observableQuery.test.tsx b/src/react/hoc/__tests__/queries/observableQuery.test.tsx index ed1b7f37b20..7f856749ac8 100644 --- a/src/react/hoc/__tests__/queries/observableQuery.test.tsx +++ b/src/react/hoc/__tests__/queries/observableQuery.test.tsx @@ -3,14 +3,12 @@ import { render, fireEvent, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] observableQuery', () => { // observableQuery diff --git a/src/react/hoc/__tests__/queries/polling.test.tsx b/src/react/hoc/__tests__/queries/polling.test.tsx index a92b4a08ef7..3c1044fba67 100644 --- a/src/react/hoc/__tests__/queries/polling.test.tsx +++ b/src/react/hoc/__tests__/queries/polling.test.tsx @@ -3,15 +3,13 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloLink } from '../../../../core'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; +import { ApolloClient, ApolloLink } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, mockSingleLink } from '../../../../testing'; +import { Observable } from '../../../../utilities'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; -import { Observable } from '../../../../utilities/observables/Observable'; describe('[queries] polling', () => { let error: typeof console.error; diff --git a/src/react/hoc/__tests__/queries/reducer.test.tsx b/src/react/hoc/__tests__/queries/reducer.test.tsx index 2db4bc851d4..e880c82d962 100644 --- a/src/react/hoc/__tests__/queries/reducer.test.tsx +++ b/src/react/hoc/__tests__/queries/reducer.test.tsx @@ -3,14 +3,12 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { DataValue } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] reducer', () => { // props reducer diff --git a/src/react/hoc/__tests__/queries/skip.test.tsx b/src/react/hoc/__tests__/queries/skip.test.tsx index 2fe713e008b..19d43677fe2 100644 --- a/src/react/hoc/__tests__/queries/skip.test.tsx +++ b/src/react/hoc/__tests__/queries/skip.test.tsx @@ -3,15 +3,13 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloLink } from '../../../../link/core'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] skip', () => { itAsync('allows you to skip a query without running it', (resolve, reject) => { diff --git a/src/react/hoc/__tests__/queries/updateQuery.test.tsx b/src/react/hoc/__tests__/queries/updateQuery.test.tsx index 61460f01f3d..c4a31836eb9 100644 --- a/src/react/hoc/__tests__/queries/updateQuery.test.tsx +++ b/src/react/hoc/__tests__/queries/updateQuery.test.tsx @@ -3,14 +3,12 @@ import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; import { render, wait } from '@testing-library/react'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { itAsync, stripSymbols, mockSingleLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; -import { itAsync } from '../../../../utilities/testing/itAsync'; describe('[queries] updateQuery', () => { // updateQuery diff --git a/src/react/hoc/__tests__/shared-operations.test.tsx b/src/react/hoc/__tests__/shared-operations.test.tsx index b711639aca6..9ad1fc2322b 100644 --- a/src/react/hoc/__tests__/shared-operations.test.tsx +++ b/src/react/hoc/__tests__/shared-operations.test.tsx @@ -3,11 +3,11 @@ import { render, cleanup } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../ApolloClient'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; +import { ApolloClient } from '../../../core'; +import { ApolloProvider } from '../../context'; +import { InMemoryCache as Cache } from '../../../cache'; +import { ApolloLink } from '../../../link/core'; +import { mockSingleLink } from '../../../testing'; import { graphql } from '../graphql'; import { ChildProps, DataValue } from '../types'; import { withApollo } from '../withApollo'; diff --git a/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx b/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx index c96ad6453c3..2d4abcf1126 100644 --- a/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx +++ b/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx @@ -4,12 +4,12 @@ import ReactDOM from 'react-dom/server'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { mockSingleLink } from '../../../../utilities/testing/mocking/mockLink'; -import { Query } from '../../../components/Query'; -import { getDataFromTree, getMarkupFromTree } from '../../../ssr/getDataFromTree'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { mockSingleLink } from '../../../../testing'; +import { Query } from '../../../components'; +import { getDataFromTree, getMarkupFromTree } from '../../../ssr'; import { graphql } from '../../graphql'; import { ChildProps, DataValue } from '../../types'; diff --git a/src/react/hoc/__tests__/ssr/server.test.tsx b/src/react/hoc/__tests__/ssr/server.test.tsx index f8fa3d61ca8..f7ba71de7ea 100644 --- a/src/react/hoc/__tests__/ssr/server.test.tsx +++ b/src/react/hoc/__tests__/ssr/server.test.tsx @@ -11,12 +11,12 @@ import { } from 'graphql'; import gql from 'graphql-tag'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { Observable } from '../../../../utilities/observables/Observable'; -import { renderToStringWithData } from '../../../ssr/renderToStringWithData'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloLink } from '../../../../link/core'; +import { Observable } from '../../../../utilities'; +import { renderToStringWithData } from '../../../ssr'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; diff --git a/src/react/hoc/__tests__/subscriptions/subscriptions.test.tsx b/src/react/hoc/__tests__/subscriptions/subscriptions.test.tsx index 48a1eba9e3b..34eecca9c8d 100644 --- a/src/react/hoc/__tests__/subscriptions/subscriptions.test.tsx +++ b/src/react/hoc/__tests__/subscriptions/subscriptions.test.tsx @@ -3,12 +3,11 @@ import { render, cleanup } from '@testing-library/react'; import gql from 'graphql-tag'; import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../../ApolloClient'; -import { ApolloProvider } from '../../../context/ApolloProvider'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; -import { MockSubscriptionLink } from '../../../../utilities/testing/mocking/mockSubscriptionLink'; -import { stripSymbols } from '../../../../utilities/testing/stripSymbols'; +import { ApolloClient } from '../../../../core'; +import { ApolloProvider } from '../../../context'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloLink } from '../../../../link/core'; +import { stripSymbols, MockSubscriptionLink } from '../../../../testing'; import { graphql } from '../../graphql'; import { ChildProps } from '../../types'; diff --git a/src/react/hoc/graphql.tsx b/src/react/hoc/graphql.tsx index e104ad47992..a85f40a3861 100644 --- a/src/react/hoc/graphql.tsx +++ b/src/react/hoc/graphql.tsx @@ -1,6 +1,6 @@ import { DocumentNode } from 'graphql'; -import { parser, DocumentType } from '../parser/parser'; +import { parser, DocumentType } from '../parser'; import { withQuery } from './query-hoc'; import { withMutation } from './mutation-hoc'; import { withSubscription } from './subscription-hoc'; diff --git a/src/react/hoc/hoc-utils.tsx b/src/react/hoc/hoc-utils.tsx index 322cd7e5067..1a80dd6d151 100644 --- a/src/react/hoc/hoc-utils.tsx +++ b/src/react/hoc/hoc-utils.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { invariant } from 'ts-invariant'; -import { OperationVariables } from '../../core/types'; -import { IDocumentDefinition } from '../parser/parser'; +import { OperationVariables } from '../../core'; +import { IDocumentDefinition } from '../parser'; export const defaultMapPropsToOptions = () => ({}); export const defaultMapResultToProps:

(props: P) => P = props => props; diff --git a/src/react/hoc/mutation-hoc.tsx b/src/react/hoc/mutation-hoc.tsx index 4188e51544a..5159753e678 100644 --- a/src/react/hoc/mutation-hoc.tsx +++ b/src/react/hoc/mutation-hoc.tsx @@ -2,13 +2,13 @@ import React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; -import { parser } from '../parser/parser'; +import { parser } from '../parser'; import { BaseMutationOptions, MutationFunction, MutationResult } from '../types/types'; -import { Mutation } from '../components/Mutation'; +import { Mutation } from '../components'; import { defaultMapPropsToOptions, diff --git a/src/react/hoc/query-hoc.tsx b/src/react/hoc/query-hoc.tsx index dcc4c2f0966..428a64714d9 100644 --- a/src/react/hoc/query-hoc.tsx +++ b/src/react/hoc/query-hoc.tsx @@ -2,9 +2,9 @@ import React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; -import { parser } from '../parser/parser'; +import { parser } from '../parser'; import { BaseQueryOptions } from '../types/types'; -import { Query } from '../components/Query'; +import { Query } from '../components'; import { getDisplayName, GraphQLBase, diff --git a/src/react/hoc/subscription-hoc.tsx b/src/react/hoc/subscription-hoc.tsx index 641d47ac588..906d14a905f 100644 --- a/src/react/hoc/subscription-hoc.tsx +++ b/src/react/hoc/subscription-hoc.tsx @@ -2,9 +2,9 @@ import React from 'react'; import { DocumentNode } from 'graphql'; import hoistNonReactStatics from 'hoist-non-react-statics'; -import { parser } from '../parser/parser'; +import { parser } from '../parser'; import { BaseQueryOptions } from '../types/types'; -import { Subscription } from '../components/Subscription'; +import { Subscription } from '../components'; import { getDisplayName, GraphQLBase, diff --git a/src/react/hoc/types.ts b/src/react/hoc/types.ts index 4307a1e6115..909878aa6f3 100644 --- a/src/react/hoc/types.ts +++ b/src/react/hoc/types.ts @@ -1,14 +1,13 @@ -import { ApolloClient } from '../../ApolloClient'; -import { ApolloQueryResult, OperationVariables } from '../../core/types'; -import { ApolloError } from '../../errors/ApolloError'; +import { ApolloClient } from '../../core'; +import { ApolloError } from '../../errors'; import { + ApolloQueryResult, + OperationVariables, FetchMoreOptions, UpdateQueryOptions, -} from '../../core/ObservableQuery'; -import { FetchMoreQueryOptions, SubscribeToMoreOptions, -} from '../../core/watchQueryOptions'; +} from '../../core'; import { MutationFunction, BaseQueryOptions, diff --git a/src/react/hoc/withApollo.tsx b/src/react/hoc/withApollo.tsx index 295a096c916..9b6422b0ef1 100644 --- a/src/react/hoc/withApollo.tsx +++ b/src/react/hoc/withApollo.tsx @@ -2,7 +2,7 @@ import React from 'react'; import hoistNonReactStatics from 'hoist-non-react-statics'; import { invariant } from 'ts-invariant'; -import { ApolloConsumer } from '../context/ApolloConsumer'; +import { ApolloConsumer } from '../context'; import { OperationOption, WithApolloClient } from './types'; function getDisplayName

(WrappedComponent: React.ComponentType

) { diff --git a/src/react/hooks/__tests__/useApolloClient.test.tsx b/src/react/hooks/__tests__/useApolloClient.test.tsx index 1a1490efbb7..2043350fd24 100644 --- a/src/react/hooks/__tests__/useApolloClient.test.tsx +++ b/src/react/hooks/__tests__/useApolloClient.test.tsx @@ -2,12 +2,11 @@ import React from 'react'; import { render, cleanup } from '@testing-library/react'; import { InvariantError } from 'ts-invariant'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; +import { ApolloClient } from '../../../core'; +import { ApolloLink } from '../../../link/core'; +import { ApolloProvider, resetApolloContext } from '../../context'; +import { InMemoryCache } from '../../../cache'; import { useApolloClient } from '../useApolloClient'; -import { resetApolloContext } from '../../context/ApolloContext'; describe('useApolloClient Hook', () => { afterEach(() => { diff --git a/src/react/hooks/__tests__/useLazyQuery.test.tsx b/src/react/hooks/__tests__/useLazyQuery.test.tsx index 4f26803c37e..568a2013b59 100644 --- a/src/react/hooks/__tests__/useLazyQuery.test.tsx +++ b/src/react/hooks/__tests__/useLazyQuery.test.tsx @@ -3,10 +3,10 @@ import { DocumentNode } from 'graphql'; import gql from 'graphql-tag'; import { render, wait } from '@testing-library/react'; -import { MockedProvider } from '../../../utilities/testing'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache } from '../../../cache'; +import { ApolloProvider } from '../../context'; +import { MockedProvider } from '../../../testing'; import { useLazyQuery } from '../useLazyQuery'; describe('useLazyQuery Hook', () => { diff --git a/src/react/hooks/__tests__/useMutation.test.tsx b/src/react/hooks/__tests__/useMutation.test.tsx index 4afa79add91..5d466398b28 100644 --- a/src/react/hooks/__tests__/useMutation.test.tsx +++ b/src/react/hooks/__tests__/useMutation.test.tsx @@ -3,11 +3,10 @@ import { DocumentNode, GraphQLError } from 'graphql'; import gql from 'graphql-tag'; import { render, cleanup, wait } from '@testing-library/react'; -import { MockedProvider, mockSingleLink } from '../../../utilities/testing'; -import { itAsync } from '../../../utilities/testing/itAsync'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache } from '../../../cache'; +import { itAsync, MockedProvider, mockSingleLink } from '../../../testing'; +import { ApolloProvider } from '../../context'; import { useMutation } from '../useMutation'; describe('useMutation Hook', () => { diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 6a87cdbfd66..be8d208663c 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -3,20 +3,15 @@ import { DocumentNode, GraphQLError } from 'graphql'; import gql from 'graphql-tag'; import { render, cleanup, wait } from '@testing-library/react'; -import { Observable } from '../../../utilities/observables/Observable'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { MockedProvider, mockSingleLink } from '../../../utilities/testing'; -import { MockLink } from '../../../utilities/testing/mocking/mockLink'; -import { itAsync } from '../../../utilities/testing/itAsync'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; +import { ApolloClient, NetworkStatus } from '../../../core'; +import { InMemoryCache } from '../../../cache'; +import { ApolloProvider } from '../../context'; +import { Observable, Reference, concatPagination } from '../../../utilities'; +import { ApolloLink } from '../../../link/core'; +import { itAsync, MockLink, MockedProvider, mockSingleLink } from '../../../testing'; import { useQuery } from '../useQuery'; import { useMutation } from '../useMutation'; import { QueryFunctionOptions } from '../..'; -import { NetworkStatus } from '../../../core/networkStatus'; -import { Reference } from '../../../utilities/graphql/storeUtils'; -import { concatPagination } from '../../../utilities'; describe('useQuery Hook', () => { const CAR_QUERY: DocumentNode = gql` diff --git a/src/react/hooks/__tests__/useSubscription.test.tsx b/src/react/hooks/__tests__/useSubscription.test.tsx index c5d66c826a0..3ffeccd19ee 100644 --- a/src/react/hooks/__tests__/useSubscription.test.tsx +++ b/src/react/hooks/__tests__/useSubscription.test.tsx @@ -2,10 +2,10 @@ import React from 'react'; import { render, cleanup, wait } from '@testing-library/react'; import gql from 'graphql-tag'; -import { MockSubscriptionLink } from '../../../utilities/testing/mocking/mockSubscriptionLink'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache as Cache } from '../../../cache'; +import { ApolloProvider } from '../../context'; +import { MockSubscriptionLink } from '../../../testing'; import { useSubscription } from '../useSubscription'; describe('useSubscription Hook', () => { diff --git a/src/react/hooks/index.ts b/src/react/hooks/index.ts new file mode 100644 index 00000000000..b301bfed59d --- /dev/null +++ b/src/react/hooks/index.ts @@ -0,0 +1,5 @@ +export * from './useApolloClient'; +export * from './useLazyQuery'; +export * from './useMutation'; +export * from './useQuery'; +export * from './useSubscription'; diff --git a/src/react/hooks/useApolloClient.ts b/src/react/hooks/useApolloClient.ts index c7b4deb4d3d..52390348a0a 100644 --- a/src/react/hooks/useApolloClient.ts +++ b/src/react/hooks/useApolloClient.ts @@ -1,8 +1,8 @@ import React from 'react'; import { invariant } from 'ts-invariant'; -import { ApolloClient } from '../../ApolloClient'; -import { getApolloContext } from '../context/ApolloContext'; +import { ApolloClient } from '../../core'; +import { getApolloContext } from '../context'; export function useApolloClient(): ApolloClient { const { client } = React.useContext(getApolloContext()); diff --git a/src/react/hooks/useLazyQuery.ts b/src/react/hooks/useLazyQuery.ts index 03bf70c208d..987622915e9 100644 --- a/src/react/hooks/useLazyQuery.ts +++ b/src/react/hooks/useLazyQuery.ts @@ -2,7 +2,7 @@ import { DocumentNode } from 'graphql'; import { LazyQueryHookOptions, QueryTuple } from '../types/types'; import { useBaseQuery } from './utils/useBaseQuery'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; export function useLazyQuery( query: DocumentNode, diff --git a/src/react/hooks/useMutation.ts b/src/react/hooks/useMutation.ts index 902ebe85101..fbc2202e4b8 100644 --- a/src/react/hooks/useMutation.ts +++ b/src/react/hooks/useMutation.ts @@ -2,9 +2,9 @@ import { useContext, useState, useRef, useEffect } from 'react'; import { DocumentNode } from 'graphql'; import { MutationHookOptions, MutationTuple } from '../types/types'; -import { MutationData } from '../data/MutationData'; -import { OperationVariables } from '../../core/types'; -import { getApolloContext } from '../context/ApolloContext'; +import { MutationData } from '../data'; +import { OperationVariables } from '../../core'; +import { getApolloContext } from '../context'; export function useMutation( mutation: DocumentNode, diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index 8823020d214..ae226cebc91 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -2,7 +2,7 @@ import { DocumentNode } from 'graphql'; import { QueryHookOptions, QueryResult } from '../types/types'; import { useBaseQuery } from './utils/useBaseQuery'; -import { OperationVariables } from '../../core/types'; +import { OperationVariables } from '../../core'; export function useQuery( query: DocumentNode, diff --git a/src/react/hooks/useSubscription.ts b/src/react/hooks/useSubscription.ts index a5dad16bc61..aa4b6f1e372 100644 --- a/src/react/hooks/useSubscription.ts +++ b/src/react/hooks/useSubscription.ts @@ -2,9 +2,9 @@ import { useContext, useState, useRef, useEffect } from 'react'; import { DocumentNode } from 'graphql'; import { SubscriptionHookOptions } from '../types/types'; -import { SubscriptionData } from '../data/SubscriptionData'; -import { OperationVariables } from '../../core/types'; -import { getApolloContext } from '../context/ApolloContext'; +import { SubscriptionData } from '../data'; +import { OperationVariables } from '../../core'; +import { getApolloContext } from '../context'; export function useSubscription( subscription: DocumentNode, diff --git a/src/react/hooks/utils/useBaseQuery.ts b/src/react/hooks/utils/useBaseQuery.ts index 6e75b471938..ac293453770 100644 --- a/src/react/hooks/utils/useBaseQuery.ts +++ b/src/react/hooks/utils/useBaseQuery.ts @@ -7,10 +7,10 @@ import { QueryTuple, QueryResult, } from '../../types/types'; -import { QueryData } from '../../data/QueryData'; +import { QueryData } from '../../data'; import { useDeepMemo } from './useDeepMemo'; -import { OperationVariables } from '../../../core/types'; -import { getApolloContext } from '../../context/ApolloContext'; +import { OperationVariables } from '../../../core'; +import { getApolloContext } from '../../context'; export function useBaseQuery( query: DocumentNode, diff --git a/src/react/index.ts b/src/react/index.ts index 0cf189fadde..a423c3c75a1 100644 --- a/src/react/index.ts +++ b/src/react/index.ts @@ -1,21 +1,18 @@ -export { ApolloProvider } from './context/ApolloProvider'; -export { ApolloConsumer } from './context/ApolloConsumer'; export { + ApolloProvider, + ApolloConsumer, getApolloContext, resetApolloContext, ApolloContextValue -} from './context/ApolloContext'; -export { useQuery } from './hooks/useQuery'; -export { useLazyQuery } from './hooks/useLazyQuery'; -export { useMutation } from './hooks/useMutation'; -export { useSubscription } from './hooks/useSubscription'; -export { useApolloClient } from './hooks/useApolloClient'; -export { RenderPromises } from './ssr/RenderPromises'; +} from './context'; + +export * from './hooks'; + export { DocumentType, IDocumentDefinition, operationName, parser -} from './parser/parser'; +} from './parser'; export * from './types/types'; diff --git a/src/react/parser/__tests__/parser.test.ts b/src/react/parser/__tests__/parser.test.ts index 8b50adf438d..3ce3501b2c0 100644 --- a/src/react/parser/__tests__/parser.test.ts +++ b/src/react/parser/__tests__/parser.test.ts @@ -1,6 +1,6 @@ import gql from 'graphql-tag'; -import { parser, DocumentType } from '../parser'; +import { parser, DocumentType } from '..'; type OperationDefinition = any; diff --git a/src/react/parser/parser.ts b/src/react/parser/index.ts similarity index 100% rename from src/react/parser/parser.ts rename to src/react/parser/index.ts diff --git a/src/react/ssr/RenderPromises.ts b/src/react/ssr/RenderPromises.ts index 734c7ef395c..f7caa69cbd3 100644 --- a/src/react/ssr/RenderPromises.ts +++ b/src/react/ssr/RenderPromises.ts @@ -1,6 +1,6 @@ import { DocumentNode } from 'graphql'; -import { ObservableQuery } from '../../core/ObservableQuery'; +import { ObservableQuery } from '../../core'; import { QueryDataOptions } from '../types/types'; import { QueryData } from '../data/QueryData'; diff --git a/src/react/ssr/__tests__/useLazyQuery.test.tsx b/src/react/ssr/__tests__/useLazyQuery.test.tsx index 8c8565df602..4263f036327 100644 --- a/src/react/ssr/__tests__/useLazyQuery.test.tsx +++ b/src/react/ssr/__tests__/useLazyQuery.test.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { DocumentNode } from 'graphql'; import gql from 'graphql-tag'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { useLazyQuery } from '../../hooks/useLazyQuery'; -import { renderToStringWithData } from '..'; +import { mockSingleLink } from '../../../testing'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache } from '../../../cache'; +import { ApolloProvider } from '../../context'; +import { useLazyQuery } from '../../hooks'; +import { renderToStringWithData } from '../../ssr'; describe('useLazyQuery Hook SSR', () => { const CAR_QUERY: DocumentNode = gql` diff --git a/src/react/ssr/__tests__/useQuery.test.tsx b/src/react/ssr/__tests__/useQuery.test.tsx index 14db259fad8..176a30fe64b 100644 --- a/src/react/ssr/__tests__/useQuery.test.tsx +++ b/src/react/ssr/__tests__/useQuery.test.tsx @@ -1,12 +1,11 @@ import React from 'react'; import { DocumentNode } from 'graphql'; import gql from 'graphql-tag'; -import { MockedProvider } from '../../../utilities/testing/mocking/MockedProvider'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../context/ApolloProvider'; -import { useQuery } from '../../hooks/useQuery'; +import { MockedProvider, mockSingleLink } from '../../../testing'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache } from '../../../cache'; +import { ApolloProvider } from '../../context'; +import { useQuery } from '../../hooks'; import { render, wait } from '@testing-library/react'; import { renderToStringWithData } from '..'; diff --git a/src/react/ssr/getDataFromTree.ts b/src/react/ssr/getDataFromTree.ts index 8c5972a9eea..4e2b53a143e 100644 --- a/src/react/ssr/getDataFromTree.ts +++ b/src/react/ssr/getDataFromTree.ts @@ -1,5 +1,5 @@ import React from 'react'; -import { getApolloContext } from '../context/ApolloContext'; +import { getApolloContext } from '../context'; import { RenderPromises } from './RenderPromises'; export function getDataFromTree( diff --git a/src/react/ssr/index.ts b/src/react/ssr/index.ts index 136d3ca7bc7..f239c2a435f 100644 --- a/src/react/ssr/index.ts +++ b/src/react/ssr/index.ts @@ -1,2 +1,3 @@ export { getMarkupFromTree, getDataFromTree } from './getDataFromTree'; export { renderToStringWithData } from './renderToStringWithData'; +export { RenderPromises } from './RenderPromises'; diff --git a/src/react/types/types.ts b/src/react/types/types.ts index f53a7600bc0..0be5c2bb66d 100644 --- a/src/react/types/types.ts +++ b/src/react/types/types.ts @@ -1,24 +1,23 @@ import { ReactNode } from 'react'; import { DocumentNode } from 'graphql'; -import { Observable } from '../../utilities/observables/Observable'; -import { FetchResult } from '../../link/core/types'; -import { ApolloClient } from '../../ApolloClient'; +import { Observable } from '../../utilities'; +import { FetchResult } from '../../link/core'; +import { ApolloClient } from '../../core'; +import { ApolloError } from '../../errors'; import { ApolloQueryResult, - PureQueryOptions, - OperationVariables -} from '../../core/types'; -import { ApolloError } from '../../errors/ApolloError'; -import { - FetchPolicy, - WatchQueryFetchPolicy, ErrorPolicy, + FetchMoreOptions, FetchMoreQueryOptions, + FetchPolicy, MutationUpdaterFn, -} from '../../core/watchQueryOptions'; -import { FetchMoreOptions, ObservableQuery } from '../../core/ObservableQuery'; -import { NetworkStatus } from '../../core/networkStatus'; + NetworkStatus, + ObservableQuery, + OperationVariables, + PureQueryOptions, + WatchQueryFetchPolicy, +} from '../../core'; /* Common types */ diff --git a/src/testing/index.ts b/src/testing/index.ts new file mode 100644 index 00000000000..bec83b671fe --- /dev/null +++ b/src/testing/index.ts @@ -0,0 +1 @@ +export * from '../utilities/testing'; diff --git a/src/utilities/index.ts b/src/utilities/index.ts index d7a1f0e7821..ef1cb96602d 100644 --- a/src/utilities/index.ts +++ b/src/utilities/index.ts @@ -27,6 +27,7 @@ export { } from './graphql/getFromAST'; export { + StoreObject, Reference, StoreValue, Directives, @@ -67,3 +68,19 @@ export { offsetLimitPagination, relayStylePagination, } from './policies/pagination'; + +export { + Observable, + Observer, + ObservableSubscription +} from './observables/Observable'; + +export * from './common/mergeDeep'; +export * from './common/cloneDeep'; +export * from './common/maybeDeepFreeze'; +export * from './observables/iteration'; +export * from './observables/asyncMap'; +export * from './observables/Concast'; +export * from './common/arrays'; +export * from './common/errorHandling'; +export * from './common/canUse'; diff --git a/src/utilities/testing/index.ts b/src/utilities/testing/index.ts index 43bd1f9421b..a053a4d6b60 100644 --- a/src/utilities/testing/index.ts +++ b/src/utilities/testing/index.ts @@ -6,3 +6,5 @@ export { } from './mocking/mockSubscriptionLink'; export { createMockClient } from './mocking/mockClient'; export { stripSymbols } from './stripSymbols'; +export { default as subscribeAndCount } from './subscribeAndCount'; +export { itAsync } from './itAsync'; diff --git a/src/utilities/testing/mocking/MockedProvider.tsx b/src/utilities/testing/mocking/MockedProvider.tsx index 42fa7e40240..5612a0f53c5 100644 --- a/src/utilities/testing/mocking/MockedProvider.tsx +++ b/src/utilities/testing/mocking/MockedProvider.tsx @@ -1,13 +1,12 @@ import React from 'react'; -import { ApolloClient, DefaultOptions } from '../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../react/context/ApolloProvider'; -import { MockLink } from '../../../utilities/testing/mocking/mockLink'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { Resolvers } from '../../../core/types'; -import { ApolloCache } from '../../../cache/core/cache'; -import { MockedResponse } from '../../../utilities/testing/mocking/mockLink'; +import { ApolloClient, DefaultOptions } from '../../../core'; +import { InMemoryCache as Cache } from '../../../cache'; +import { ApolloProvider } from '../../../react/context'; +import { MockLink, MockedResponse } from './mockLink'; +import { ApolloLink } from '../../../link/core'; +import { Resolvers } from '../../../core'; +import { ApolloCache } from '../../../cache'; export interface MockedProviderProps { mocks?: ReadonlyArray; diff --git a/src/utilities/testing/mocking/__tests__/MockedProvider.test.tsx b/src/utilities/testing/mocking/__tests__/MockedProvider.test.tsx index c71752cbbd7..a89efcb2881 100644 --- a/src/utilities/testing/mocking/__tests__/MockedProvider.test.tsx +++ b/src/utilities/testing/mocking/__tests__/MockedProvider.test.tsx @@ -8,7 +8,7 @@ import { MockedResponse, MockLink } from '../mockLink'; import { DocumentNode } from 'graphql'; import { useQuery } from '../../../../react/hooks/useQuery'; import { InMemoryCache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloLink } from '../../../../link/core/ApolloLink'; +import { ApolloLink } from '../../../../link/core'; const variables = { username: 'mock_username' diff --git a/src/utilities/testing/mocking/__tests__/mockSubscriptionLink.test.tsx b/src/utilities/testing/mocking/__tests__/mockSubscriptionLink.test.tsx index eeaa8d1e2f9..ff7bca2dd67 100644 --- a/src/utilities/testing/mocking/__tests__/mockSubscriptionLink.test.tsx +++ b/src/utilities/testing/mocking/__tests__/mockSubscriptionLink.test.tsx @@ -3,10 +3,10 @@ import { render, wait } from '@testing-library/react'; import gql from 'graphql-tag'; import { MockSubscriptionLink } from '../mockSubscriptionLink'; -import { ApolloClient } from '../../../../ApolloClient'; -import { InMemoryCache as Cache } from '../../../../cache/inmemory/inMemoryCache'; -import { ApolloProvider } from '../../../../react/context/ApolloProvider'; -import { useSubscription } from '../../../../react/hooks/useSubscription'; +import { ApolloClient } from '../../../../core'; +import { InMemoryCache as Cache } from '../../../../cache'; +import { ApolloProvider } from '../../../../react/context'; +import { useSubscription } from '../../../../react/hooks'; describe('mockSubscriptionLink', () => { it('should work with multiple subscribers to the same mock websocket', () => { diff --git a/src/utilities/testing/mocking/mockClient.ts b/src/utilities/testing/mocking/mockClient.ts index 7cff0551af3..f68d719b898 100644 --- a/src/utilities/testing/mocking/mockClient.ts +++ b/src/utilities/testing/mocking/mockClient.ts @@ -1,9 +1,8 @@ import { DocumentNode } from 'graphql'; -import { ApolloClient } from '../../../ApolloClient'; -import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache'; -import { NormalizedCacheObject } from '../../../cache/inmemory/types'; -import { mockSingleLink } from '../../../utilities/testing/mocking/mockLink'; +import { ApolloClient } from '../../../core'; +import { InMemoryCache, NormalizedCacheObject } from '../../../cache'; +import { mockSingleLink } from './mockLink'; export function createMockClient( data: TData, diff --git a/src/utilities/testing/mocking/mockLink.ts b/src/utilities/testing/mocking/mockLink.ts index 290e71edf2a..c74b5dba244 100644 --- a/src/utilities/testing/mocking/mockLink.ts +++ b/src/utilities/testing/mocking/mockLink.ts @@ -1,20 +1,21 @@ import { print } from 'graphql/language/printer'; import { equal } from '@wry/equality'; +import { invariant } from 'ts-invariant'; -import { Observable } from '../../../utilities/observables/Observable'; -import { ApolloLink } from '../../../link/core/ApolloLink'; import { + ApolloLink, Operation, GraphQLRequest, FetchResult, -} from '../../../link/core/types'; +} from '../../../link/core'; + import { + Observable, addTypenameToDocument, removeClientSetsFromDocument, removeConnectionDirectiveFromDocument, -} from '../../../utilities/graphql/transform'; -import { cloneDeep } from '../../../utilities/common/cloneDeep'; -import invariant from 'ts-invariant'; + cloneDeep, +} from '../../../utilities'; export type ResultFunction = () => T; diff --git a/src/utilities/testing/mocking/mockSubscriptionLink.ts b/src/utilities/testing/mocking/mockSubscriptionLink.ts index 642499db788..cf4a51a79ca 100644 --- a/src/utilities/testing/mocking/mockSubscriptionLink.ts +++ b/src/utilities/testing/mocking/mockSubscriptionLink.ts @@ -1,6 +1,5 @@ -import { Observable } from '../../../utilities/observables/Observable'; -import { ApolloLink } from '../../../link/core/ApolloLink'; -import { FetchResult, Operation } from '../../../link/core/types'; +import { Observable } from '../../../utilities'; +import { ApolloLink, FetchResult, Operation } from '../../../link/core'; export interface MockedSubscription { request: Operation;