Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Jun 24, 2022
1 parent a0faa51 commit 506ac6d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"clean": "git clean -dfqX -- ./node_modules **/{dist,node_modules}/ **/tsconfig*tsbuildinfo",
"precompile": "node scripts/precompile.mjs",
"postcompile": "node scripts/postcompile.mjs",
"compile": "tsc --build tsconfig.build.json packages/server/tsconfig.cjs.json; x=$?; mv packages/server/src/.packageVersion.ts.original packages/server/src/packageVersion.ts; exit $x",
"compile": "tsc --build tsconfig.build.json packages/*/tsconfig.cjs.json; x=$?; mv packages/server/src/.packageVersion.ts.original packages/server/src/packageVersion.ts; exit $x",
"watch": "tsc --build tsconfig.build.json --watch",
"install-with-npm-8.5": "npm i -g npm@^8.5.0 && npm i",
"postinstall": "npm run compile",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-response-cache/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const config = require('../../jest.config.base');
import baseConfig from '../../jest.config.base.js';

module.exports = Object.assign(Object.create(null), config);
export default baseConfig;
13 changes: 11 additions & 2 deletions packages/plugin-response-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
"name": "@apollo/server-plugin-response-cache",
"version": "4.0.0",
"description": "Apollo Server full query response cache",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"exports": {
".": {
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/apollographql/apollo-server",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import type {
ApolloServerPlugin,
GraphQLRequestListener,
BaseContext,
CacheHint,
GraphQLRequestContext,
GraphQLRequestListener,
GraphQLResponse,
CacheHint,
BaseContext,
} from '@apollo/server';
import { newHTTPGraphQLHead } from '@apollo/server';
import { createHash } from '@apollo/utils.createhash';
import {
KeyValueCache,
PrefixingKeyValueCache,
} from '@apollo/utils.keyvaluecache';

type ValueOrPromise<T> = T | Promise<T>;

// XXX This should use createSHA from apollo-server-core in order to work on
// non-Node environments. I'm not sure where that should end up ---
// apollo-server-sha as its own tiny module? apollo-server-env seems bad because
// that would add sha.js to unnecessary places, I think?
import { createHash } from '@apollo/utils.createhash';
import { CacheScope } from 'packages/server/src/plugin/schemaReporting/generated/operations';
import { newHTTPGraphQLHead } from 'packages/server/src/runHttpQuery';

interface Options<TContext = Record<string, any>> {
// Underlying cache used to save results. All writes will be under keys that
// start with 'fqc:' and are followed by a fixed-size cryptographic hash of a
Expand Down Expand Up @@ -302,7 +295,7 @@ export default function plugin<TContext extends BaseContext>(
.catch(logger.warn);
};

const isPrivate = policyIfCacheable.scope === CacheScope.Private;
const isPrivate = policyIfCacheable.scope === 'PRIVATE';
if (isPrivate) {
if (!options.sessionId) {
logger.warn(
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-response-cache/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import plugin from './ApolloServerPluginResponseCache';
import plugin from './ApolloServerPluginResponseCache.js';

export default plugin;
11 changes: 11 additions & 0 deletions packages/plugin-response-cache/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": ".",
"compilerOptions": {
"module": "commonjs",
"outDir": "./dist/cjs",
// We delete the CJS .d.ts files in postcompile so we don't need to
// ever make their maps. (We can't disable creating the files because
// this is a composite project.)
"declarationMap": false,
},
}
6 changes: 4 additions & 2 deletions packages/plugin-response-cache/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"extends": "../../tsconfig.base",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist/esm"
},
"include": ["src/**/*"],
"exclude": ["**/__tests__"],
"references": [
{ "path": "../server" }
{
"path": "../server"
}
]
}
2 changes: 2 additions & 0 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export {

// TODO(AS4): consider moving to `@apollo/server/express`
export { expressMiddleware } from './express/index.js';

export { newHTTPGraphQLHead } from './runHttpQuery.js';
22 changes: 12 additions & 10 deletions scripts/postcompile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import { writeFileSync } from 'fs';
import rimraf from 'rimraf';

// Tell Node what kinds of files the ".js" files in these subdirectories are.
writeFileSync(
path.join('packages', 'server', 'dist', 'esm', 'package.json'),
JSON.stringify({ type: 'module' }),
);
writeFileSync(
path.join('packages', 'server', 'dist', 'cjs', 'package.json'),
JSON.stringify({ type: 'commonjs' }),
);
for (const dir of ['plugin-response-cache', 'server']) {
writeFileSync(
path.join('packages', dir, 'dist', 'esm', 'package.json'),
JSON.stringify({ type: 'module' }),
);
writeFileSync(
path.join('packages', dir, 'dist', 'cjs', 'package.json'),
JSON.stringify({ type: 'commonjs' }),
);

// Remove CJS .d.ts files: we don't need two copies!
rimraf.sync('packages/server/dist/cjs/**/*.d.ts');
// Remove CJS .d.ts files: we don't need two copies!
rimraf.sync(`packages/${dir}/dist/cjs/**/*.d.ts`);
}

0 comments on commit 506ac6d

Please sign in to comment.