├── docs ├── .nvmrc ├── sketch │ └── APQs.sketch ├── source │ ├── images │ │ ├── graphql.png │ │ ├── playground.png │ │ ├── selectrep.png │ │ ├── index-diagram.png │ │ ├── welcometoreact.png │ │ ├── graphql-playground.png │ │ ├── index-get-started.png │ │ ├── composition_schema-1.png │ │ ├── composition_schema-2.png │ │ ├── features │ │ │ ├── error-code.png │ │ │ ├── error-stacktrace.png │ │ │ └── error-user-input.png │ │ ├── graphiql-casual-mocks.png │ │ ├── sitedeployinprogress.png │ │ ├── deployment │ │ │ ├── heroku │ │ │ │ ├── new-app.png │ │ │ │ ├── create-app.png │ │ │ │ ├── add-env-vars.png │ │ │ │ ├── add-integration.png │ │ │ │ └── heroku-github-instructions.png │ │ │ ├── zeit │ │ │ │ ├── zeit-apollo-server.png │ │ │ │ └── now-github-permissions.png │ │ │ └── azure-functions │ │ │ │ ├── apollo-server.png │ │ │ │ ├── apollo-server-on-azure.png │ │ │ │ └── apollo-server-on-azure-sucess.png │ │ ├── persistedQueries.newPath.png │ │ ├── persistedQueries.optPath.png │ │ ├── willSendResponse-flowchart.png │ │ ├── getting-started │ │ │ ├── graphql-playground.png │ │ │ └── graphql-playground-response.png │ │ └── index-get-started.svg │ ├── api │ │ └── graphql-subscriptions.md │ ├── deployment │ │ └── index.md │ ├── index.mdx │ ├── data │ │ └── file-uploads.md │ ├── requests.md │ ├── monitoring │ │ └── health-checks.md │ └── security │ │ └── terminating-ssl.md ├── .gitignore ├── package.json └── README.md ├── README.md ├── packages ├── apollo-server-caching │ ├── .gitignore │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ ├── InMemoryLRUCache.test.ts │ │ │ └── PrefixingKeyValueCache.test.ts │ │ ├── index.ts │ │ ├── KeyValueCache.ts │ │ ├── PrefixingKeyValueCache.ts │ │ └── InMemoryLRUCache.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-plugin-base │ ├── README.md │ ├── CHANGELOG.md │ ├── .npmignore │ ├── jest.config.js │ ├── tsconfig.json │ └── package.json ├── apollo-server-types │ ├── CHANGELOG.md │ ├── .npmignore │ ├── jest.config.js │ ├── README.md │ ├── tsconfig.json │ └── package.json ├── apollo-server-env │ ├── src │ │ ├── polyfills │ │ │ ├── url.js │ │ │ ├── fetch.js │ │ │ ├── Object.values.ts │ │ │ └── Object.entries.ts │ │ ├── index.d.ts │ │ ├── typescript-utility-types.d.ts │ │ ├── index.ts │ │ ├── utils │ │ │ └── runtimeSupportsPromisify.ts │ │ ├── global.d.ts │ │ ├── index.browser.js │ │ └── url.d.ts │ ├── .npmignore │ ├── tsconfig.json │ ├── README.md │ └── package.json ├── apollo-server-plugin-response-cache │ ├── CHANGELOG.md │ ├── .npmignore │ ├── src │ │ ├── index.ts │ │ └── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── ApolloServerPluginResponseCache.test.ts │ ├── jest.config.js │ ├── tsconfig.json │ ├── README.md │ └── package.json ├── apollo-reporting-protobuf │ ├── src │ │ ├── index.d.ts │ │ ├── .editorconfig │ │ └── index.js │ ├── .npmignore │ ├── package.json │ └── README.md ├── apollo-server │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ └── exports.ts │ ├── tsconfig.json │ ├── CHANGELOG.md │ ├── scripts │ │ └── prepare-package.sh │ └── package.json ├── apollo-tracing │ ├── .npmignore │ ├── tsconfig.json │ ├── package.json │ └── README.md ├── apollo-datasource │ ├── .npmignore │ ├── tsconfig.json │ ├── src │ │ └── index.ts │ └── package.json ├── apollo-server-core │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── plugin │ │ │ ├── usageReporting │ │ │ │ ├── __tests__ │ │ │ │ │ ├── tsconfig.json │ │ │ │ │ └── signatureCache.test.ts │ │ │ │ └── index.ts │ │ │ ├── internalPlugin.ts │ │ │ └── schemaReporting │ │ │ │ └── __tests__ │ │ │ │ ├── computeExecutableSchemaId.test.ts │ │ │ │ └── index.test.ts │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ ├── requestPipelineAPI.ts │ │ ├── utils │ │ │ ├── createSHA.ts │ │ │ ├── isNodeLike.ts │ │ │ ├── runtimeSupportsUploads.ts │ │ │ └── isDirectiveDefined.ts │ │ ├── nodeHttpToRequest.ts │ │ └── processFileUploads.ts │ ├── README.md │ ├── tsconfig.json │ └── CHANGELOG.md ├── apollo-server-hapi │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── hapiApollo.test.ts │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-koa │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ ├── index.ts │ │ └── koaApollo.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-micro │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── types.ts │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── microApollo.test.ts │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── graphql-extensions │ ├── .npmignore │ ├── jest.config.js │ ├── README.md │ ├── tsconfig.json │ ├── package.json │ └── CHANGELOG.md ├── apollo-cache-control │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ └── __tests__ │ │ │ ├── tsconfig.json │ │ │ ├── cacheControlSupport.ts │ │ │ └── collectCacheControlHints.ts │ ├── tsconfig.json │ ├── package.json │ └── CHANGELOG.md ├── apollo-datasource-rest │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── index.ts │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ └── types │ │ │ └── http-cache-semantics │ │ │ └── index.d.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-errors │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ └── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── ApolloError.test.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-express │ ├── .npmignore │ ├── src │ │ ├── connectApollo.ts │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ ├── connectApollo.test.ts │ │ │ └── expressApollo.test.ts │ │ └── index.ts │ ├── jest.config.js │ ├── tsconfig.json │ └── package.json ├── apollo-server-fastify │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── fastifyApollo.test.ts │ │ ├── index.ts │ │ └── fastifyApollo.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-lambda │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-azure-functions │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-cache-memcached │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ └── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── Memcached.test.ts │ ├── tsconfig.json │ ├── package.json │ └── README.md ├── apollo-server-cache-redis │ ├── .npmignore │ ├── src │ │ ├── index.ts │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ ├── RedisClusterCache.test.ts │ │ │ └── RedisCache.test.ts │ │ ├── __mocks__ │ │ │ └── ioredis.ts │ │ └── RedisCache.ts │ ├── jest.config.js │ ├── tsconfig.json │ └── package.json ├── apollo-server-cloud-functions │ ├── .npmignore │ ├── jest.config.js │ ├── src │ │ ├── __tests__ │ │ │ ├── tsconfig.json │ │ │ └── googleCloudApollo.test.ts │ │ ├── index.ts │ │ └── googleCloudApollo.ts │ ├── tsconfig.json │ └── package.json ├── apollo-server-integration-testsuite │ ├── .npmignore │ ├── tsconfig.json │ └── package.json ├── apollo-server-testing │ ├── src │ │ ├── index.ts │ │ ├── __tests__ │ │ │ └── tsconfig.json │ │ └── createTestClient.ts │ ├── jest.config.js │ ├── CHANGELOG.md │ ├── tsconfig.json │ ├── README.md │ └── package.json ├── apollo-server-cloudflare │ ├── jest.config.js │ ├── tsconfig.test.json │ ├── tsconfig.json │ ├── src │ │ ├── types │ │ │ └── cloudflare │ │ │ │ └── index.d.ts │ │ ├── index.ts │ │ ├── ApolloServer.ts │ │ └── cloudflareApollo.ts │ └── package.json └── apollo-server-plugin-operation-registry │ ├── src │ ├── index.ts │ ├── __tests__ │ │ ├── tsconfig.json │ │ ├── common.test.ts │ │ └── jestSetup.ts │ ├── schema.ts │ └── common.ts │ ├── img │ └── clients-page.png │ ├── jest.config.js │ ├── tsconfig.json │ └── package.json ├── .prettierignore ├── examples └── acephei │ ├── start.js │ ├── services │ ├── books │ │ ├── schema.graphql │ │ ├── package.json │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── tsconfig.json │ │ └── src │ │ │ └── data.ts │ ├── accounts │ │ ├── schema.graphql │ │ ├── package.json │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── tsconfig.json │ │ └── src │ │ │ └── data.ts │ ├── products │ │ ├── package.json │ │ ├── .vscode │ │ │ └── launch.json │ │ └── tsconfig.json │ └── reviews │ │ ├── package.json │ │ ├── .vscode │ │ └── launch.json │ │ └── tsconfig.json │ ├── tsconfig.json │ ├── .gitignore │ ├── gateway │ ├── package.json │ ├── .vscode │ │ └── launch.json │ └── tsconfig.json │ └── gateway.code-workspace ├── .editorconfig ├── tsconfig.json ├── lerna.json ├── netlify.toml ├── types └── mock-req │ └── index.d.ts ├── tsconfig.test.base.json ├── .gitignore ├── codecov.yml ├── .vscode ├── tasks.json └── settings.json ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── bug.md │ └── feature-request.md ├── APOLLO_RELEASE_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── __mocks__ ├── date.ts └── apollo-server-env.ts ├── tsconfig.base.json ├── .prettierrc.js ├── LICENSE ├── jest.config.base.js ├── tsconfig.test.json └── tsconfig.build.json /docs/.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packages/apollo-server/README.md -------------------------------------------------------------------------------- /packages/apollo-server-caching/.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.json 2 | *.md 3 | *.snap 4 | 5 | dist/ 6 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/README.md: -------------------------------------------------------------------------------- 1 | # `apollo-server-plugin-base` 2 | -------------------------------------------------------------------------------- /packages/apollo-server-types/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ### vNEXT 4 | 5 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ### vNEXT 4 | 5 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/polyfills/url.js: -------------------------------------------------------------------------------- 1 | export { URL, URLSearchParams } from 'url'; 2 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ### vNEXT 4 | 5 | -------------------------------------------------------------------------------- /docs/sketch/APQs.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/sketch/APQs.sketch -------------------------------------------------------------------------------- /docs/source/images/graphql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/graphql.png -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/src/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as protobuf from './protobuf'; 2 | export = protobuf; 3 | -------------------------------------------------------------------------------- /docs/source/images/playground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/playground.png -------------------------------------------------------------------------------- /docs/source/images/selectrep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/selectrep.png -------------------------------------------------------------------------------- /packages/apollo-server/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-tracing/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /docs/source/images/index-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/index-diagram.png -------------------------------------------------------------------------------- /packages/apollo-datasource/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-core/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-env/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/polyfills/fetch.js: -------------------------------------------------------------------------------- 1 | export { default as fetch, Request, Response, Headers } from 'node-fetch'; 2 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-types/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/graphql-extensions/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /docs/source/images/welcometoreact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/welcometoreact.png -------------------------------------------------------------------------------- /packages/apollo-cache-control/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-express/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /docs/source/images/graphql-playground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/graphql-playground.png -------------------------------------------------------------------------------- /docs/source/images/index-get-started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/index-get-started.png -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /docs/source/api/graphql-subscriptions.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: graphql-subscriptions 3 | description: Bringing real-time to your schema 4 | --- 5 | -------------------------------------------------------------------------------- /docs/source/images/composition_schema-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/composition_schema-1.png -------------------------------------------------------------------------------- /docs/source/images/composition_schema-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/composition_schema-2.png -------------------------------------------------------------------------------- /docs/source/images/features/error-code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/features/error-code.png -------------------------------------------------------------------------------- /docs/source/images/graphiql-casual-mocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/graphiql-casual-mocks.png -------------------------------------------------------------------------------- /docs/source/images/sitedeployinprogress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/sitedeployinprogress.png -------------------------------------------------------------------------------- /packages/apollo-server-env/src/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './fetch'; 2 | export * from './url'; 3 | export * from './typescript-utility-types'; 4 | -------------------------------------------------------------------------------- /packages/apollo-server-integration-testsuite/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !src/**/* 3 | !dist/**/* 4 | dist/**/*.test.* 5 | !package.json 6 | !README.md 7 | -------------------------------------------------------------------------------- /docs/source/images/deployment/heroku/new-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/heroku/new-app.png -------------------------------------------------------------------------------- /docs/source/images/features/error-stacktrace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/features/error-stacktrace.png -------------------------------------------------------------------------------- /docs/source/images/features/error-user-input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/features/error-user-input.png -------------------------------------------------------------------------------- /docs/source/images/persistedQueries.newPath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/persistedQueries.newPath.png -------------------------------------------------------------------------------- /docs/source/images/persistedQueries.optPath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/persistedQueries.optPath.png -------------------------------------------------------------------------------- /docs/source/images/willSendResponse-flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/willSendResponse-flowchart.png -------------------------------------------------------------------------------- /docs/source/images/deployment/heroku/create-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/heroku/create-app.png -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/index.ts: -------------------------------------------------------------------------------- 1 | export { RedisCache } from './RedisCache'; 2 | export { RedisClusterCache } from './RedisClusterCache'; 3 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | default as createTestClient, 3 | ApolloServerTestClient, 4 | } from './createTestClient'; 5 | -------------------------------------------------------------------------------- /docs/source/images/deployment/heroku/add-env-vars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/heroku/add-env-vars.png -------------------------------------------------------------------------------- /packages/apollo-server-express/src/connectApollo.ts: -------------------------------------------------------------------------------- 1 | import { graphqlExpress } from './expressApollo'; 2 | 3 | export const graphqlConnect = graphqlExpress; 4 | -------------------------------------------------------------------------------- /packages/apollo-server/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | db.json 4 | *.log 5 | node_modules/ 6 | public/* 7 | .deploy*/ 8 | docs.json 9 | _multiconfig.yml 10 | .cache 11 | -------------------------------------------------------------------------------- /docs/source/images/deployment/heroku/add-integration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/heroku/add-integration.png -------------------------------------------------------------------------------- /packages/apollo-cache-control/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-core/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-types/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/graphql-extensions/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /docs/source/images/deployment/zeit/zeit-apollo-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/zeit/zeit-apollo-server.png -------------------------------------------------------------------------------- /docs/source/images/getting-started/graphql-playground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/getting-started/graphql-playground.png -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-express/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/src/index.ts: -------------------------------------------------------------------------------- 1 | import plugin from './ApolloServerPluginResponseCache'; 2 | export default plugin; 3 | module.exports = plugin; 4 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [] 5 | } 6 | -------------------------------------------------------------------------------- /docs/source/images/deployment/zeit/now-github-permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/zeit/now-github-permissions.png -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /docs/source/images/deployment/azure-functions/apollo-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/azure-functions/apollo-server.png -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/index.ts: -------------------------------------------------------------------------------- 1 | import plugin from './ApolloServerPluginOperationRegistry'; 2 | export default plugin; 3 | module.exports = plugin; 4 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | module.exports = Object.assign(Object.create(null), config); 4 | -------------------------------------------------------------------------------- /docs/source/images/getting-started/graphql-playground-response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/getting-started/graphql-playground-response.png -------------------------------------------------------------------------------- /packages/apollo-server-micro/src/types.ts: -------------------------------------------------------------------------------- 1 | import { IncomingMessage } from 'http'; 2 | 3 | export interface MicroRequest extends IncomingMessage { 4 | filePayload?: object; 5 | } 6 | -------------------------------------------------------------------------------- /docs/source/images/deployment/heroku/heroku-github-instructions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/heroku/heroku-github-instructions.png -------------------------------------------------------------------------------- /packages/apollo-server-env/src/typescript-utility-types.d.ts: -------------------------------------------------------------------------------- 1 | export type ValueOrPromise = T | Promise; 2 | export type WithRequired = T & Required>; 3 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/img/clients-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/packages/apollo-server-plugin-operation-registry/img/clients-page.png -------------------------------------------------------------------------------- /packages/apollo-server-types/README.md: -------------------------------------------------------------------------------- 1 | # `apollo-server-types` 2 | 3 | These are types which are shared across Apollo Server packages, but kept here 4 | to avoid circular dependencies. 5 | -------------------------------------------------------------------------------- /examples/acephei/start.js: -------------------------------------------------------------------------------- 1 | require("./services/accounts"); 2 | require("./services/books"); 3 | require("./services/products"); 4 | require("./services/reviews"); 5 | require("./gateway"); 6 | 7 | -------------------------------------------------------------------------------- /docs/source/images/deployment/azure-functions/apollo-server-on-azure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/azure-functions/apollo-server-on-azure.png -------------------------------------------------------------------------------- /packages/apollo-server/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-cache-control/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" } 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /docs/source/images/deployment/azure-functions/apollo-server-on-azure-sucess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/apollo-server/main/docs/source/images/deployment/azure-functions/apollo-server-on-azure-sucess.png -------------------------------------------------------------------------------- /packages/apollo-server-env/src/polyfills/Object.values.ts: -------------------------------------------------------------------------------- 1 | if (!global.Object.values) { 2 | global.Object.values = function(object: any) { 3 | return Object.keys(object).map(key => object[key]); 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/src/index.ts: -------------------------------------------------------------------------------- 1 | export { RESTDataSource, RequestOptions } from './RESTDataSource'; 2 | export { HTTPCache } from './HTTPCache'; 3 | export { Request, Response } from 'apollo-server-env'; 4 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | max_line_length = 80 11 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*", "../../../../__mocks__"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*", "../../../../__mocks__"], 4 | "references": [ 5 | { "path": "../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/usageReporting/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../../../" }, 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/polyfills/Object.entries.ts: -------------------------------------------------------------------------------- 1 | if (!global.Object.entries) { 2 | global.Object.entries = function(object: any) { 3 | return Object.keys(object).map(key => [key, object[key]] as [string, any]); 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | }, 5 | "files": [], 6 | "include": [], 7 | "references": [ 8 | { "path": "./tsconfig.build.json" }, 9 | { "path": "./tsconfig.test.json" }, 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*"], 3 | "version": "independent", 4 | "command": { 5 | "version": { 6 | "message": "Release", 7 | "ignoreChanges": ["**/*.md"], 8 | "includeMergedTags": true 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | base = "docs/" 3 | publish = "docs/public/" 4 | command = "gatsby build --prefix-paths && mkdir -p docs/apollo-server && mv public/* docs/apollo-server && mv docs public/ && mv public/docs/apollo-server/_redirects public" 5 | 6 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/apollo-server-express/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-caching/src/__tests__/" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-caching/src/__tests__/" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.test.base", 3 | "include": ["src/**/__tests__", "src/**/__mocks__"], 4 | "references": [ 5 | { "path": "./" }, 6 | { "path": "../apollo-server-integration-testsuite" }, 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/__tests__/common.test.ts: -------------------------------------------------------------------------------- 1 | import * as common from '../common'; 2 | 3 | describe('common', () => { 4 | it('uses the correct cache prefix', () => { 5 | expect(common.getStoreKey('abc123')).toStrictEqual('abc123'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | KeyValueCache, 3 | TestableKeyValueCache, 4 | KeyValueCacheSetOptions, 5 | } from './KeyValueCache'; 6 | export { InMemoryLRUCache } from './InMemoryLRUCache'; 7 | export { PrefixingKeyValueCache } from './PrefixingKeyValueCache'; 8 | -------------------------------------------------------------------------------- /types/mock-req/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Request, Headers } from 'apollo-server-env'; 2 | 3 | declare class MockReq implements Pick { 4 | constructor(); 5 | method: string; 6 | url: string; 7 | headers: Headers; 8 | } 9 | 10 | export = MockReq; 11 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "noImplicitAny": false 7 | }, 8 | "include": ["src/**/*"], 9 | "exclude": ["**/__tests__", "**/__mocks__"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/__tests__/RedisClusterCache.test.ts: -------------------------------------------------------------------------------- 1 | jest.mock('ioredis'); 2 | 3 | import { RedisClusterCache } from '../index'; 4 | import { testKeyValueCache } from '../../../apollo-server-caching/src/__tests__/testsuite'; 5 | 6 | testKeyValueCache(new RedisClusterCache([{ host: 'localhost' }])); 7 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/__tests__/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../tsconfig.test.base", 3 | "include": ["**/*"], 4 | "references": [ 5 | { "path": "../../" }, 6 | { "path": "../../../apollo-server-types" }, 7 | { "path": "../../../apollo-server-integration-testsuite" }, 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/graphql-extensions/README.md: -------------------------------------------------------------------------------- 1 | # graphql-extensions 2 | 3 | [![npm version](https://badge.fury.io/js/graphql-extensions.svg)](https://badge.fury.io/js/graphql-extensions) 4 | [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server) 5 | -------------------------------------------------------------------------------- /packages/apollo-datasource/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-caching" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/src/__tests__/ApolloServerPluginResponseCache.test.ts: -------------------------------------------------------------------------------- 1 | import plugin from '../ApolloServerPluginResponseCache'; 2 | 3 | describe('Response cache plugin', () => { 4 | it('will instantiate when not called with options', () => { 5 | expect(plugin()).toHaveProperty('requestDidStart'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /packages/apollo-tracing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-plugin-base" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/graphql-extensions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-types" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-cache-control/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-plugin-base" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-types" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-server-types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-caching/" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-datasource/src/index.ts: -------------------------------------------------------------------------------- 1 | import { KeyValueCache } from 'apollo-server-caching'; 2 | 3 | export interface DataSourceConfig { 4 | context: TContext; 5 | cache: KeyValueCache; 6 | } 7 | 8 | export abstract class DataSource { 9 | initialize?(config: DataSourceConfig): void | Promise; 10 | } 11 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-caching" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-caching" }, 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "prestart": "gatsby clean", 4 | "start": "gatsby develop", 5 | "build": "gatsby build", 6 | "serve": "gatsby serve" 7 | }, 8 | "dependencies": { 9 | "gatsby": "2.29.3", 10 | "gatsby-theme-apollo-docs": "4.5.5", 11 | "react": "16.14.0", 12 | "react-dom": "16.14.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/src/.editorconfig: -------------------------------------------------------------------------------- 1 | # reports.proto is copied from an internal Apollo repository which applies these 2 | # editorconfig standards. 3 | 4 | root = true 5 | 6 | [reports.proto] 7 | charset = utf-8 8 | end_of_line = lf 9 | indent_size = 2 10 | indent_style = tab 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/requestPipelineAPI.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLServiceContext, 3 | GraphQLRequest, 4 | VariableValues, 5 | GraphQLResponse, 6 | GraphQLRequestMetrics, 7 | GraphQLRequestContext, 8 | ValidationRule, 9 | InvalidGraphQLRequestError, 10 | GraphQLExecutor, 11 | GraphQLExecutionResult, 12 | } from 'apollo-server-types'; 13 | -------------------------------------------------------------------------------- /tsconfig.test.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "lib": ["es2017", "es2019.array", "esnext.asynciterable"], 6 | "types": ["node", "jest", "apollo-server-env/dist/global"], 7 | "paths": { 8 | "__mocks__/*" : ["__mocks__/*"], 9 | "*" : ["types/*"] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/index.ts: -------------------------------------------------------------------------------- 1 | import './polyfills/Object.values'; 2 | import './polyfills/Object.entries'; 3 | 4 | import runtimeSupportsPromisify from './utils/runtimeSupportsPromisify'; 5 | 6 | if (!runtimeSupportsPromisify) { 7 | require('util.promisify').shim(); 8 | } 9 | 10 | export * from './polyfills/fetch'; 11 | export * from './polyfills/url'; 12 | -------------------------------------------------------------------------------- /examples/acephei/services/books/schema.graphql: -------------------------------------------------------------------------------- 1 | "The basic book in the graph" 2 | type Book @key(fields: "isbn") { 3 | "All books can be found by an isbn" 4 | isbn: String! 5 | "The title of the book" 6 | title: String 7 | "The year the book was published" 8 | year: Int 9 | "A simple list of similar books" 10 | similarBooks: [Book] 11 | } -------------------------------------------------------------------------------- /packages/apollo-server-env/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "composite": false, 5 | "rootDir": "./src", 6 | "outDir": "./dist", 7 | "allowJs": true, 8 | "declaration": false, 9 | "declarationMap": false 10 | }, 11 | "include": ["src/**/*"], 12 | "exclude": ["**/__tests__", "**/__mocks__"] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### vNEXT 4 | 5 | * `apollo-server-testing`: Add `variables` and `operationName` prop to `Query` and `Mutation` types. [PR #2307](https://github.com/apollographql/apollo-server/pull/2307) [Issue #2172](https://github.com/apollographql/apollo-server/issue/2172) 6 | * `apollo-server-testing`: Added `createTestClient` function. 7 | -------------------------------------------------------------------------------- /packages/apollo-server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-express" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-express/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-core" }, 11 | { "path": "../apollo-server-types" }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /docs/source/deployment/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Deployment Basics 3 | sidebar_title: Basics 4 | description: Deploying your new Apollo Server to the world 5 | --- 6 | 7 | 14 | -------------------------------------------------------------------------------- /examples/acephei/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | }, 5 | "files": [], 6 | "include": [], 7 | "references": [ 8 | { "path": "./services/accounts" }, 9 | { "path": "./services/books" }, 10 | { "path": "./services/products" }, 11 | { "path": "./services/reviews" }, 12 | { "path": "./gateway" } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/jest.config.js: -------------------------------------------------------------------------------- 1 | const config = require('../../jest.config.base'); 2 | 3 | const packageSpecificSetupFiles = ['/src/__tests__/jestSetup.ts']; 4 | 5 | const setupFiles = (Array.isArray(config.setupFiles) 6 | ? config.setupFiles 7 | : [] 8 | ).concat(packageSpecificSetupFiles); 9 | 10 | module.exports = Object.assign(Object.create(null), config, { setupFiles }); 11 | -------------------------------------------------------------------------------- /packages/apollo-server-env/README.md: -------------------------------------------------------------------------------- 1 | # `apollo-server-env` 2 | 3 | This package is used internally by Apollo Server and not meant to be consumed 4 | directly. 5 | 6 | Its primary function is to provide polyfills (e.g. via 7 | [`core-js`](https://npm.im/core-js)) for newer language features which might 8 | not be available in the underlying JavaScript Engine (i.e. more bare-bones V8 9 | environments, older versions of Node.js, etc.). 10 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/utils/createSHA.ts: -------------------------------------------------------------------------------- 1 | import isNodeLike from './isNodeLike'; 2 | 3 | export default function(kind: string): import('crypto').Hash { 4 | if (isNodeLike) { 5 | // Use module.require instead of just require to avoid bundling whatever 6 | // crypto polyfills a non-Node bundler might fall back to. 7 | return module.require('crypto').createHash(kind); 8 | } 9 | return require('sha.js')(kind); 10 | } 11 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/src/types/cloudflare/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Request, Response } from 'apollo-server-env'; 2 | 3 | declare global { 4 | interface FetchEvent { 5 | readonly request: Request; 6 | respondWith(response: Promise): void; 7 | waitUntil(task: Promise): void; 8 | } 9 | 10 | function addEventListener( 11 | type: 'fetch', 12 | listener: (event: FetchEvent) => void, 13 | ): void; 14 | } 15 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/__tests__/InMemoryLRUCache.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | testKeyValueCache_Basics, 3 | testKeyValueCache_Expiration, 4 | } from '../../../apollo-server-caching/src/__tests__/testsuite'; 5 | import { InMemoryLRUCache } from '../InMemoryLRUCache'; 6 | 7 | describe('InMemoryLRUCache', () => { 8 | const cache = new InMemoryLRUCache(); 9 | testKeyValueCache_Basics(cache); 10 | testKeyValueCache_Expiration(cache); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "noImplicitAny": false, 7 | "strictNullChecks": false 8 | }, 9 | "include": ["src/**/*"], 10 | "exclude": ["**/__tests__", "**/__mocks__"], 11 | "references": [ 12 | { "path": "../apollo-server-core" }, 13 | { "path": "../apollo-server-types" }, 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-server-caching" }, 11 | { "path": "../apollo-server-errors" }, 12 | { "path": "../apollo-server-plugin-base" }, 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/__tests__/RedisCache.test.ts: -------------------------------------------------------------------------------- 1 | jest.mock('ioredis'); 2 | 3 | import { RedisCache } from '../index'; 4 | import { 5 | testKeyValueCache_Basics, 6 | testKeyValueCache_Expiration, 7 | } from '../../../apollo-server-caching/src/__tests__/testsuite'; 8 | 9 | describe('Redis', () => { 10 | const cache = new RedisCache({ host: 'localhost' }); 11 | testKeyValueCache_Basics(cache); 12 | testKeyValueCache_Expiration(cache); 13 | }); 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore the compiled output. 2 | dist/ 3 | 4 | # TypeScript incremental compilation cache 5 | *.tsbuildinfo 6 | 7 | # Logs 8 | logs 9 | *.log 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Coverage (from Jest) 15 | coverage/ 16 | 17 | # JUnit Reports (used mainly in CircleCI) 18 | reports/ 19 | junit.xml 20 | 21 | # Node modules 22 | node_modules/ 23 | 24 | # Mac OS 25 | .DS_Store 26 | 27 | # Intellij Configuration Files 28 | .idea/ 29 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-datasource" }, 11 | { "path": "../apollo-server-caching" }, 12 | { "path": "../apollo-server-errors" }, 13 | { "path": "../apollo-server-types" }, 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "noImplicitAny": false, 7 | "noImplicitThis": false, 8 | "strictNullChecks": false 9 | }, 10 | "include": ["src/**/*"], 11 | "exclude": ["**/__tests__", "**/__mocks__"], 12 | "references": [ 13 | { "path": "../apollo-server-core" }, 14 | { "path": "../apollo-server-types" }, 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "noImplicitAny": false, 7 | "strictNullChecks": false, 8 | "noImplicitReturns": false 9 | }, 10 | "include": ["src/**/*"], 11 | "exclude": ["**/__tests__", "**/__mocks__"], 12 | "references": [ 13 | { "path": "../apollo-server-core" }, 14 | { "path": "../apollo-server-types" }, 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/usageReporting/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | ApolloServerPluginUsageReporting, 3 | ApolloServerPluginUsageReportingDisabled, 4 | } from './plugin'; 5 | export { 6 | ApolloServerPluginUsageReportingOptions, 7 | SendValuesBaseOptions, 8 | VariableValueOptions, 9 | ClientInfo, 10 | GenerateClientInfo, 11 | } from './options'; 12 | export { 13 | ApolloServerPluginUsageReportingFromLegacyOptions, 14 | EngineReportingOptions, 15 | } from './legacyOptions'; 16 | -------------------------------------------------------------------------------- /packages/apollo-server-integration-testsuite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "noImplicitAny": false, 7 | "strictNullChecks": false, 8 | "types": ["node", "jest"] 9 | }, 10 | "include": ["src/**/*"], 11 | "exclude": ["**/__tests__", "**/__mocks__"], 12 | "references": [ 13 | { "path": "../apollo-server-core" }, 14 | { "path": "../apollo-server-types" }, 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-cache-control" }, 11 | { "path": "../apollo-server-plugin-base" }, 12 | { "path": "../apollo-server-caching" }, 13 | { "path": "../apollo-server-types" }, 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/usageReporting/__tests__/signatureCache.test.ts: -------------------------------------------------------------------------------- 1 | import { signatureCacheKey } from '../signatureCache'; 2 | 3 | describe('signature cache key', () => { 4 | it('generates without the operationName', () => { 5 | expect(signatureCacheKey('abc123', '')).toEqual('abc123'); 6 | }); 7 | 8 | it('generates with the operationName', () => { 9 | expect(signatureCacheKey('abc123', 'myOperation')).toEqual( 10 | 'abc123:myOperation', 11 | ); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | threshold: 1% 6 | patch: 7 | default: 8 | # We should raise this, but we want to evaluate how 9 | # this looks in practice, first. We can do that for now 10 | # by observing the status checks on the PRs themselves. 11 | target: 0% 12 | 13 | # The charts can still be viewed by clicking on the status 14 | # checks, but they create a fair amount of noise by default. 15 | comment: off 16 | 17 | -------------------------------------------------------------------------------- /examples/acephei/services/accounts/schema.graphql: -------------------------------------------------------------------------------- 1 | extend type Query { 2 | """ 3 | The currently authenticated user root. All nodes off of this 4 | root will be authenticated as the current user 5 | """ 6 | me: User 7 | } 8 | 9 | """ 10 | The base User in Acephei 11 | """ 12 | type User @key(fields: "id") { 13 | "A globally unique id for the user" 14 | id: ID! 15 | "The users full name as provided" 16 | name: String 17 | "The account username of the user" 18 | username: String 19 | } 20 | -------------------------------------------------------------------------------- /examples/acephei/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore the compiled output. 2 | dist/ 3 | 4 | # TypeScript incremental compilation cache 5 | *.tsbuildinfo 6 | 7 | # Logs 8 | logs 9 | *.log 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Coverage (from Jest) 15 | coverage/ 16 | 17 | # JUnit Reports (used mainly in CircleCI) 18 | reports/ 19 | junit.xml 20 | 21 | # Node modules 22 | node_modules/ 23 | 24 | # Mac OS 25 | .DS_Store 26 | 27 | # Intellij Configuration Files 28 | .idea/ 29 | 30 | # API Key files 31 | .env 32 | 33 | package-lock.json -------------------------------------------------------------------------------- /packages/apollo-server-core/README.md: -------------------------------------------------------------------------------- 1 | # apollo-server-core 2 | 3 | [![npm version](https://badge.fury.io/js/apollo-server-core.svg)](https://badge.fury.io/js/apollo-server-core) 4 | [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server) 5 | 6 | This is the core module of the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/) 7 | [Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md) 8 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "TypeScript watch", 6 | "type": "shell", 7 | "command": "./node_modules/.bin/tsc", 8 | "args": [ 9 | "--build", 10 | "tsconfig.build.json", 11 | "--watch" 12 | ], 13 | "isBackground": true, 14 | "problemMatcher": [ 15 | "$tsc-watch" 16 | ], 17 | "group": { 18 | "kind": "build", 19 | "isDefault": true 20 | }, 21 | "presentation": { 22 | "reveal": "never", 23 | "panel": "dedicated" 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/README.md: -------------------------------------------------------------------------------- 1 | # Response Cache plugin 2 | 3 | This Apollo server plugin implements a full GraphQL query response cache. 4 | 5 | - Add the plugin to your ApolloServer's plugins list 6 | - Set `@cacheControl` hints on your schema or call `info.cacheControl.setCacheHint` in your resolvers 7 | - If the entire GraphQL response is covered by cache hints with non-zero maxAge, 8 | the whole response will be cached. 9 | 10 | This cache is a full query cache: cached responses are only used for identical requests. 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/src/__tests__/Memcached.test.ts: -------------------------------------------------------------------------------- 1 | // use mock implementations for underlying databases 2 | jest.mock('memcached', () => require('memcached-mock')); 3 | 4 | import { MemcachedCache } from '../index'; 5 | import { 6 | testKeyValueCache_Basics, 7 | testKeyValueCache_Expiration, 8 | } from '../../../apollo-server-caching/src/__tests__/testsuite'; 9 | 10 | describe('Memcached', () => { 11 | const cache = new MemcachedCache('localhost'); 12 | testKeyValueCache_Basics(cache); 13 | testKeyValueCache_Expiration(cache); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export { ApolloServer } from './ApolloServer'; 22 | 23 | export * from 'graphql-tools'; 24 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/README.md: -------------------------------------------------------------------------------- 1 | # apollo-server-testing 2 | 3 | [![npm version](https://badge.fury.io/js/apollo-server-testing.svg)](https://badge.fury.io/js/apollo-server-testing) 4 | [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server) 5 | 6 | This is the testing module of the Apollo community GraphQL Server. [Read the docs.](https://www.apollographql.com/docs/apollo-server/) 7 | [Read the CHANGELOG.](https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md) 8 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # The renovate-approve bot is allowed to merge its own PRs. As it's not 2 | # a regular GitHub user (but rather, an app!), its username is indicated 3 | # as such, using the `app/` prefix. https://github.com/apps/renovate-approve 4 | /docs/ app/renovate-approve @stephenbarlow @abernix @trevor-scheer 5 | 6 | # Changes to the federation specification should be further reviewed. 7 | # Most importantly because they require messaging and awareness to 8 | # other implementations other than our own. 9 | /docs/source/federation/federation-spec.md @jbaxleyiii 10 | -------------------------------------------------------------------------------- /examples/acephei/services/books/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "books", 3 | "private": true, 4 | "scripts": { 5 | "heroku-postbuild": "tsc --build tsconfig.json" 6 | }, 7 | "main": "dist/index.js", 8 | "types": "dist/index.d.ts", 9 | "peerDependencies": { 10 | "apollo-datasource": "*", 11 | "apollo-server": "*" 12 | }, 13 | "dependencies": { 14 | "@apollo/federation": "^0.21.0", 15 | "dataloader": "^1.4.0" 16 | }, 17 | "engines": { 18 | "node": "12.x" 19 | }, 20 | "devDependencies": { 21 | "typescript": "3.9.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/acephei/services/accounts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "accounts", 3 | "private": true, 4 | "scripts": { 5 | "heroku-postbuild": "tsc --build tsconfig.json" 6 | }, 7 | "main": "dist/index.js", 8 | "types": "dist/index.d.ts", 9 | "peerDependencies": { 10 | "apollo-datasource": "*", 11 | "apollo-server": "*" 12 | }, 13 | "dependencies": { 14 | "@apollo/federation": "^0.21.0", 15 | "dataloader": "^1.4.0" 16 | }, 17 | "engines": { 18 | "node": "12.x" 19 | }, 20 | "devDependencies": { 21 | "typescript": "3.9.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/acephei/services/products/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "products", 3 | "private": true, 4 | "scripts": { 5 | "heroku-postbuild": "tsc --build tsconfig.json" 6 | }, 7 | "main": "dist/index.js", 8 | "types": "dist/index.d.ts", 9 | "peerDependencies": { 10 | "apollo-datasource": "*", 11 | "apollo-server": "*" 12 | }, 13 | "dependencies": { 14 | "@apollo/federation": "^0.21.0", 15 | "dataloader": "^1.4.0" 16 | }, 17 | "engines": { 18 | "node": "12.x" 19 | }, 20 | "devDependencies": { 21 | "typescript": "3.9.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/acephei/services/reviews/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reviews", 3 | "private": true, 4 | "scripts": { 5 | "heroku-postbuild": "tsc --build tsconfig.json" 6 | }, 7 | "main": "dist/index.js", 8 | "types": "dist/index.d.ts", 9 | "peerDependencies": { 10 | "apollo-datasource": "*", 11 | "apollo-server": "*" 12 | }, 13 | "dependencies": { 14 | "@apollo/federation": "^0.21.0", 15 | "dataloader": "^1.4.0" 16 | }, 17 | "engines": { 18 | "node": "12.x" 19 | }, 20 | "devDependencies": { 21 | "typescript": "3.9.7" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | 23 | // ApolloServer integration. 24 | export { ApolloServer } from './ApolloServer'; 25 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-base/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-plugin-base", 3 | "version": "0.10.4", 4 | "description": "Apollo Server plugin base classes", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "keywords": [], 8 | "author": "Apollo ", 9 | "license": "MIT", 10 | "engines": { 11 | "node": ">=6" 12 | }, 13 | "dependencies": { 14 | "apollo-server-types": "file:../apollo-server-types" 15 | }, 16 | "peerDependencies": { 17 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/acephei/gateway/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gateway", 3 | "private": true, 4 | "files": [ 5 | "/dist" 6 | ], 7 | "scripts": { 8 | "heroku-postbuild": "tsc --build tsconfig.json" 9 | }, 10 | "main": "dist/index.js", 11 | "types": "dist/index.d.ts", 12 | "peerDependencies": { 13 | "apollo-server": "*", 14 | "apollo-server-plugin-operation-registry": "*" 15 | }, 16 | "dependencies": { 17 | "@apollo/gateway": "^0.22.0" 18 | }, 19 | "engines": { 20 | "node": "12.x" 21 | }, 22 | "devDependencies": { 23 | "typescript": "3.9.7" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: "📚 Questions: Stack Overflow tagged \"apollo\"" 4 | url: https://stackoverflow.com/questions/tagged/apollo 5 | about: >- 6 | Many questions are already answered on Stack Overflow! 7 | We suggest starting here! 8 | - name: "💬 Questions: Spectrum Community Support" 9 | url: https://spectrum.chat/apollo/apollo-server 10 | about: >- 11 | If you're unable to find an answer on Stack Overflow, the Apollo 12 | Server channel on our Apollo Community Spectrum is the next best place. 13 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | 23 | // ApolloServer integration. 24 | export { ApolloServer, CreateHandlerOptions } from './ApolloServer'; 25 | -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | 23 | // ApolloServer integration. 24 | export { ApolloServer, CreateHandlerOptions } from './ApolloServer'; 25 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | 23 | // ApolloServer integration. 24 | export { ApolloServer, CreateHandlerOptions } from './ApolloServer'; 25 | -------------------------------------------------------------------------------- /examples/acephei/services/books/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Books", 11 | "program": "${workspaceFolder}/src/index.ts", 12 | "outFiles": [ 13 | "${workspaceFolder}/dist/**/*.js" 14 | ], 15 | "preLaunchTask": "tsc: build - tsconfig.json" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/apollo-server/src/exports.ts: -------------------------------------------------------------------------------- 1 | export * from 'graphql-tools'; 2 | export * from 'graphql-subscriptions'; 3 | 4 | export { 5 | gql, 6 | GraphQLUpload, 7 | GraphQLOptions, 8 | GraphQLExtension, 9 | Config, 10 | GraphQLSchemaModule, 11 | // Errors 12 | ApolloError, 13 | toApolloError, 14 | SyntaxError, 15 | ValidationError, 16 | AuthenticationError, 17 | ForbiddenError, 18 | UserInputError, 19 | // playground 20 | defaultPlaygroundOptions, 21 | PlaygroundConfig, 22 | PlaygroundRenderPageOptions, 23 | } from 'apollo-server-core'; 24 | 25 | export { CorsOptions } from 'apollo-server-express'; 26 | -------------------------------------------------------------------------------- /examples/acephei/services/reviews/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Reviews", 11 | "program": "${workspaceFolder}/src/index.ts", 12 | "outFiles": [ 13 | "${workspaceFolder}/dist/**/*.js" 14 | ], 15 | "preLaunchTask": "tsc: build - tsconfig.json" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /examples/acephei/services/accounts/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Accounts", 11 | "program": "${workspaceFolder}/src/index.ts", 12 | "outFiles": [ 13 | "${workspaceFolder}/dist/**/*.js" 14 | ], 15 | "preLaunchTask": "tsc: build - tsconfig.json" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /examples/acephei/services/products/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Products", 11 | "program": "${workspaceFolder}/src/index.ts", 12 | "outFiles": [ 13 | "${workspaceFolder}/dist/**/*.js" 14 | ], 15 | "preLaunchTask": "tsc: build - tsconfig.json" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/apollo-server-core/src/nodeHttpToRequest.ts: -------------------------------------------------------------------------------- 1 | import { IncomingMessage } from 'http'; 2 | import { Request, Headers } from 'apollo-server-env'; 3 | 4 | export function convertNodeHttpToRequest(req: IncomingMessage): Request { 5 | const headers = new Headers(); 6 | Object.keys(req.headers).forEach(key => { 7 | const values = req.headers[key]!; 8 | if (Array.isArray(values)) { 9 | values.forEach(value => headers.append(key, value)); 10 | } else { 11 | headers.append(key, values); 12 | } 13 | }); 14 | 15 | return new Request(req.url!, { 16 | headers, 17 | method: req.method, 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/utils/isNodeLike.ts: -------------------------------------------------------------------------------- 1 | export default typeof process === 'object' && 2 | process && 3 | // We used to check `process.release.name === "node"`, however that doesn't 4 | // account for certain forks of Node.js which are otherwise identical to 5 | // Node.js. For example, NodeSource's N|Solid reports itself as "nsolid", 6 | // though it's mostly the same build of Node.js with an extra addon. 7 | process.release && 8 | process.versions && 9 | // The one thing which is present on both Node.js and N|Solid (a fork of 10 | // Node.js), is `process.versions.node` being defined. 11 | typeof process.versions.node === 'string'; 12 | -------------------------------------------------------------------------------- /packages/apollo-server-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist" 6 | }, 7 | "include": ["src/**/*"], 8 | "exclude": ["**/__tests__", "**/__mocks__"], 9 | "references": [ 10 | { "path": "../apollo-cache-control" }, 11 | { "path": "../apollo-datasource" }, 12 | { "path": "../apollo-server-caching" }, 13 | { "path": "../apollo-server-errors" }, 14 | { "path": "../apollo-server-plugin-base" }, 15 | { "path": "../apollo-server-types" }, 16 | { "path": "../apollo-tracing" }, 17 | { "path": "../graphql-extensions" }, 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/processFileUploads.ts: -------------------------------------------------------------------------------- 1 | import runtimeSupportsUploads from './utils/runtimeSupportsUploads'; 2 | 3 | // We'll memoize this function once at module load time since it should never 4 | // change during runtime. In the event that we're using a version of Node.js 5 | // less than 8.5.0, we'll 6 | const processFileUploads: 7 | | typeof import('graphql-upload').processRequest 8 | | undefined = (() => { 9 | if (runtimeSupportsUploads) { 10 | return require('graphql-upload') 11 | .processRequest as typeof import('graphql-upload').processRequest; 12 | } 13 | return undefined; 14 | })(); 15 | 16 | export default processFileUploads; 17 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | export * from 'graphql-subscriptions'; 23 | 24 | // ApolloServer integration. 25 | export { 26 | ApolloServer, 27 | ServerRegistration, 28 | } from './ApolloServer'; 29 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | export * from 'graphql-subscriptions'; 23 | 24 | // ApolloServer integration. 25 | export { 26 | ApolloServer, 27 | ServerRegistration, 28 | } from './ApolloServer'; 29 | -------------------------------------------------------------------------------- /packages/apollo-server/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### vNEXT 4 | 5 | * `apollo-server`: move non-schema related options into listen [PR#1059](https://github.com/apollographql/apollo-server/pull/1059) 6 | * `apollo-server`: add `bodyParserConfig` options [PR#1059](https://github.com/apollographql/apollo-server/pull/1059) 7 | * `apollo-server`: add `/.well-known/apollo/server-health` endpoint with async callback for additional checks, ie database poke [PR#992](https://github.com/apollographql/apollo-server/pull/992) 8 | * `apollo-server`: collocate graphql gui with endpoint and provide gui when accessed from browser [PR#987](https://github.com/apollographql/apollo-server/pull/987) 9 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/__tests__/PrefixingKeyValueCache.test.ts: -------------------------------------------------------------------------------- 1 | import { InMemoryLRUCache } from '../InMemoryLRUCache'; 2 | import { PrefixingKeyValueCache } from '../PrefixingKeyValueCache'; 3 | 4 | describe('PrefixingKeyValueCache', () => { 5 | it('prefixes', async () => { 6 | const inner = new InMemoryLRUCache(); 7 | const prefixing = new PrefixingKeyValueCache(inner, 'prefix:'); 8 | await prefixing.set('foo', 'bar'); 9 | expect(await prefixing.get('foo')).toBe('bar'); 10 | expect(await inner.get('prefix:foo')).toBe('bar'); 11 | await prefixing.delete('foo'); 12 | expect(await prefixing.get('foo')).toBe(undefined); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | export * from 'graphql-subscriptions'; 23 | 24 | // ApolloServer integration. 25 | export { 26 | ApolloServer, 27 | ServerRegistration, 28 | } from './ApolloServer'; 29 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/utils/runtimeSupportsUploads.ts: -------------------------------------------------------------------------------- 1 | import isNodeLike from './isNodeLike'; 2 | 3 | const runtimeSupportsUploads = (() => { 4 | if (isNodeLike) { 5 | const [nodeMajor, nodeMinor] = process.versions.node 6 | .split('.', 2) 7 | .map(segment => parseInt(segment, 10)); 8 | 9 | if (nodeMajor < 8 || (nodeMajor === 8 && nodeMinor < 5)) { 10 | return false; 11 | } 12 | return true; 13 | } 14 | 15 | // If we haven't matched any of the above criteria, we'll remain unsupported 16 | // for this mysterious environment until a pull-request proves us otherwise. 17 | return false; 18 | })(); 19 | 20 | export default runtimeSupportsUploads; 21 | -------------------------------------------------------------------------------- /packages/apollo-tracing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-tracing", 3 | "version": "0.12.2", 4 | "description": "Collect and expose trace data for GraphQL requests", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "license": "MIT", 8 | "repository": "apollographql/apollo-tracing-js", 9 | "author": "Apollo ", 10 | "engines": { 11 | "node": ">=4.0" 12 | }, 13 | "dependencies": { 14 | "apollo-server-env": "file:../apollo-server-env", 15 | "apollo-server-plugin-base": "file:../apollo-server-plugin-base" 16 | }, 17 | "peerDependencies": { 18 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/apollo-cache-control/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-cache-control", 3 | "version": "0.11.6", 4 | "description": "A GraphQL extension for cache control", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "license": "MIT", 8 | "repository": "apollographql/apollo-cache-control-js", 9 | "author": "Apollo ", 10 | "engines": { 11 | "node": ">=6.0" 12 | }, 13 | "dependencies": { 14 | "apollo-server-env": "file:../apollo-server-env", 15 | "apollo-server-plugin-base": "file:../apollo-server-plugin-base" 16 | }, 17 | "peerDependencies": { 18 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/acephei/gateway/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Gateway", 11 | "program": "${workspaceFolder}/src/index.ts", 12 | "outFiles": ["${workspaceFolder}/dist/**/*.js"], 13 | "preLaunchTask": "tsc: build - tsconfig.json", 14 | "env": { 15 | "APOLLO_KEY": "", 16 | "APOLLO_GRAPH_VARIANT": "" 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/apollo-server-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-types", 3 | "version": "0.6.3", 4 | "description": "Apollo Server shared types", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "keywords": [], 8 | "author": "Apollo ", 9 | "license": "MIT", 10 | "engines": { 11 | "node": ">=6" 12 | }, 13 | "dependencies": { 14 | "apollo-reporting-protobuf": "file:../apollo-reporting-protobuf", 15 | "apollo-server-caching": "file:../apollo-server-caching", 16 | "apollo-server-env": "file:../apollo-server-env" 17 | }, 18 | "peerDependencies": { 19 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /__mocks__/date.ts: -------------------------------------------------------------------------------- 1 | const RealDate = global.Date; 2 | 3 | export function mockDate() { 4 | global.Date = new Proxy(RealDate, handler); 5 | } 6 | 7 | export function unmockDate() { 8 | global.Date = RealDate; 9 | } 10 | 11 | let now = Date.now(); 12 | 13 | export function advanceTimeBy(ms: number) { 14 | now += ms; 15 | } 16 | 17 | const handler: ProxyHandler = { 18 | construct(target, args) { 19 | if (args.length === 0) { 20 | return new Date(now); 21 | } else { 22 | return new target(...args); 23 | } 24 | }, 25 | get(target, propKey) { 26 | if (propKey === 'now') { 27 | return () => now; 28 | } else { 29 | return target[propKey]; 30 | } 31 | }, 32 | }; 33 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-caching", 3 | "version": "0.5.3", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-server-caching" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=6" 19 | }, 20 | "dependencies": { 21 | "lru-cache": "^6.0.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "target": "es2016", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "esModuleInterop": true, 8 | "sourceMap": true, 9 | "declaration": true, 10 | "declarationMap": true, 11 | "removeComments": true, 12 | "strict": true, 13 | "noImplicitAny": true, 14 | "noImplicitReturns": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "noUnusedParameters": true, 17 | "noUnusedLocals": true, 18 | "forceConsistentCasingInFileNames": true, 19 | "lib": ["es2017", "esnext.asynciterable"], 20 | "types": ["node"], 21 | "baseUrl": ".", 22 | "paths": { 23 | "*" : ["types/*"] 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-errors", 3 | "version": "2.4.2", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-server-errors" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=6" 19 | }, 20 | "peerDependencies": { 21 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/utils/isDirectiveDefined.ts: -------------------------------------------------------------------------------- 1 | import { DocumentNode, Kind } from 'graphql/language'; 2 | import { gql } from '../'; 3 | 4 | export const isDirectiveDefined = ( 5 | typeDefs: (DocumentNode | string)[], 6 | directiveName: string, 7 | ): boolean => { 8 | // If we didn't receive an array of what we want, ensure it's an array. 9 | typeDefs = Array.isArray(typeDefs) ? typeDefs : [typeDefs]; 10 | 11 | return typeDefs.some(typeDef => { 12 | if (typeof typeDef === 'string') { 13 | typeDef = gql(typeDef); 14 | } 15 | 16 | return typeDef.definitions.some( 17 | definition => 18 | definition.kind === Kind.DIRECTIVE_DEFINITION && 19 | definition.name.value === directiveName, 20 | ); 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/utils/runtimeSupportsPromisify.ts: -------------------------------------------------------------------------------- 1 | const runtimeSupportsPromisify = (() => { 2 | if ( 3 | process && 4 | process.release && 5 | process.release.name === 'node' && 6 | process.versions && 7 | typeof process.versions.node === 'string' 8 | ) { 9 | const [nodeMajor] = process.versions.node 10 | .split('.', 1) 11 | .map(segment => parseInt(segment, 10)); 12 | 13 | if (nodeMajor >= 8) { 14 | return true; 15 | } 16 | return false; 17 | } 18 | 19 | // If we haven't matched any of the above criteria, we'll remain unsupported 20 | // for this mysterious environment until a pull-request proves us otherwise. 21 | return false; 22 | })(); 23 | 24 | export default runtimeSupportsPromisify; 25 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "editor.tabSize": 2, 4 | // You're welcome to use Prettier on code hunks that are directly related to 5 | // your changes but we ask that, rather than using "Format Document" or 6 | // `editor.formatOnSave`, you instead highlight your changes and choose 7 | // "Format Selection" (Windows: Ctrl-K Ctrl-F; Mac: Cmd-K Cmd-F) to avoid 8 | // destructive formatting changes to entire files. Thanks for understanding! 9 | "editor.formatOnSave": false, 10 | "editor.rulers": [80], 11 | "editor.wordWrapColumn": 80, 12 | "files.trimTrailingWhitespace": true, 13 | "files.insertFinalNewline": true, 14 | "typescript.tsdk": "./node_modules/typescript/lib" 15 | } 16 | -------------------------------------------------------------------------------- /packages/apollo-datasource/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-datasource", 3 | "version": "0.7.3", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-datasource" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=6" 19 | }, 20 | "dependencies": { 21 | "apollo-server-caching": "file:../apollo-server-caching", 22 | "apollo-server-env": "file:../apollo-server-env" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/graphql-extensions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphql-extensions", 3 | "version": "0.12.8", 4 | "description": "Add extensions to GraphQL servers", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "apollographql/apollo-server", 10 | "directory": "packages/graphql-extensions" 11 | }, 12 | "author": "Apollo ", 13 | "license": "MIT", 14 | "engines": { 15 | "node": ">=6.0" 16 | }, 17 | "dependencies": { 18 | "@apollographql/apollo-tools": "^0.4.3", 19 | "apollo-server-env": "file:../apollo-server-env", 20 | "apollo-server-types": "file:../apollo-server-types" 21 | }, 22 | "peerDependencies": { 23 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/apollo-server-express/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | GraphQLUpload, 3 | GraphQLOptions, 4 | GraphQLExtension, 5 | Config, 6 | gql, 7 | // Errors 8 | ApolloError, 9 | toApolloError, 10 | SyntaxError, 11 | ValidationError, 12 | AuthenticationError, 13 | ForbiddenError, 14 | UserInputError, 15 | // playground 16 | defaultPlaygroundOptions, 17 | PlaygroundConfig, 18 | PlaygroundRenderPageOptions, 19 | } from 'apollo-server-core'; 20 | 21 | export * from 'graphql-tools'; 22 | export * from 'graphql-subscriptions'; 23 | 24 | // ApolloServer integration. 25 | export { 26 | ApolloServer, 27 | ServerRegistration, 28 | GetMiddlewareOptions, 29 | ApolloServerExpressConfig, 30 | ExpressContext, 31 | } from './ApolloServer'; 32 | 33 | export { CorsOptions } from 'cors'; 34 | export { OptionsJson } from 'body-parser'; 35 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-cache-memcached", 3 | "version": "0.6.7", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-server-cache-memcached" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=6" 19 | }, 20 | "dependencies": { 21 | "apollo-server-caching": "file:../apollo-server-caching", 22 | "apollo-server-env": "file:../apollo-server-env", 23 | "memcached": "^2.2.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-cache-redis", 3 | "version": "1.2.3", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-server-cache-redis" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=8" 19 | }, 20 | "dependencies": { 21 | "apollo-server-caching": "file:../apollo-server-caching", 22 | "apollo-server-env": "file:../apollo-server-env", 23 | "dataloader": "^2.0.0", 24 | "ioredis": "^4.0.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/acephei/gateway/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "./src", 4 | "outDir": "./dist", 5 | "composite": true, 6 | "target": "es2017", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "removeComments": true, 14 | "strict": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | "noUnusedParameters": false, 19 | "noUnusedLocals": false, 20 | "forceConsistentCasingInFileNames": true, 21 | "lib": ["es2017", "esnext.asynciterable", "dom"], 22 | "types": ["node"], 23 | "jsx": "react", 24 | "baseUrl": "." 25 | }, 26 | "include": ["./src/**/*"], 27 | "exclude": ["**/__tests__/*", "**/__mocks__/*"] 28 | } 29 | -------------------------------------------------------------------------------- /examples/acephei/services/reviews/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "./src", 4 | "outDir": "./dist", 5 | "composite": true, 6 | "target": "es2017", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "removeComments": true, 14 | "strict": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | "noUnusedParameters": false, 19 | "noUnusedLocals": false, 20 | "forceConsistentCasingInFileNames": true, 21 | "lib": ["es2017", "esnext.asynciterable", "dom"], 22 | "types": ["node"], 23 | "jsx": "react", 24 | "baseUrl": "." 25 | }, 26 | "include": ["./src/**/*"], 27 | "exclude": ["**/__tests__/*", "**/__mocks__/*"] 28 | } 29 | -------------------------------------------------------------------------------- /examples/acephei/gateway.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "name": "Server - Accounts", 5 | "path": "services/accounts" 6 | }, 7 | { 8 | "name": "Server - Books", 9 | "path": "services/books" 10 | }, 11 | { 12 | "name": "Server - Products", 13 | "path": "services/products" 14 | }, 15 | { 16 | "name": "Server - Reviews", 17 | "path": "services/reviews" 18 | }, 19 | { 20 | "name": "Gateway", 21 | "path": "gateway" 22 | } 23 | ], 24 | "launch": { 25 | "configurations": [], 26 | "compounds": [ 27 | { 28 | "name": "Launch All", 29 | "configurations": [ 30 | "Launch Accounts", 31 | "Launch Books", 32 | "Launch Products", 33 | "Launch Reviews", 34 | "Launch Gateway" 35 | ] 36 | } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/acephei/services/products/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "./src", 4 | "outDir": "./dist", 5 | "composite": true, 6 | "target": "es2017", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "removeComments": true, 14 | "strict": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | "noUnusedParameters": false, 19 | "noUnusedLocals": false, 20 | "forceConsistentCasingInFileNames": true, 21 | "lib": ["es2017", "esnext.asynciterable", "dom"], 22 | "types": ["node"], 23 | "jsx": "react", 24 | "baseUrl": "." 25 | }, 26 | "include": ["./src/**/*"], 27 | "exclude": ["**/__tests__/*", "**/__mocks__/*"] 28 | } 29 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/src/__tests__/microApollo.test.ts: -------------------------------------------------------------------------------- 1 | import micro from 'micro'; 2 | import testSuite, { 3 | schema as Schema, 4 | CreateAppOptions, 5 | } from 'apollo-server-integration-testsuite'; 6 | import { GraphQLOptions, Config } from 'apollo-server-core'; 7 | 8 | import { ApolloServer } from '../ApolloServer'; 9 | 10 | function createApp(options: CreateAppOptions = {}) { 11 | const server = new ApolloServer( 12 | (options.graphqlOptions as Config) || { schema: Schema }, 13 | ); 14 | return micro(server.createHandler()); 15 | } 16 | 17 | describe('microApollo', function() { 18 | it('should throw an error if called without a schema', function() { 19 | expect(() => new ApolloServer(undefined as GraphQLOptions)).toThrow( 20 | 'ApolloServer requires options.', 21 | ); 22 | }); 23 | }); 24 | 25 | describe('integration:Micro', function() { 26 | testSuite(createApp); 27 | }); 28 | -------------------------------------------------------------------------------- /examples/acephei/services/accounts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "./src", 4 | "outDir": "./dist", 5 | "composite": true, 6 | "target": "es2017", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "removeComments": true, 14 | "strict": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | "noUnusedParameters": false, 19 | "noUnusedLocals": false, 20 | "forceConsistentCasingInFileNames": true, 21 | "lib": ["es2017", "esnext.asynciterable", "dom"], 22 | "types": ["node"], 23 | "jsx": "react", 24 | "baseUrl": "." 25 | }, 26 | "include": ["./src/**/*"], 27 | "exclude": ["**/__tests__/*", "**/__mocks__/*"] 28 | } 29 | -------------------------------------------------------------------------------- /examples/acephei/services/books/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "./src", 4 | "outDir": "./dist", 5 | "composite": true, 6 | "target": "es2017", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "esModuleInterop": true, 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "removeComments": true, 14 | "strict": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | "noUnusedParameters": false, 19 | "noUnusedLocals": false, 20 | "forceConsistentCasingInFileNames": true, 21 | "lib": ["es2017", "esnext.asynciterable", "dom"], 22 | "types": ["node"], 23 | "jsx": "react", 24 | "baseUrl": "." 25 | }, 26 | "include": ["./src/**/*"], 27 | "exclude": ["**/__tests__/*", "**/__mocks__/*"] 28 | } 29 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/__tests__/jestSetup.ts: -------------------------------------------------------------------------------- 1 | // This environment variable is meant to change the behavior of our own tests 2 | // against the operation registry, allowing us to short-circuit live checks 3 | // entirely. 4 | 5 | // Since we memoize the environment variables which are used to control the 6 | // override variables for the manifest location it's difficult to temporarily 7 | // override those in Jest mocks without needing to carefully call 8 | // `jest.resetModules` on anything they might have touched. While we could 9 | // special case tests with a check against the common `process.env.NODE_ENV === 10 | // 'test' variable, this is problematic because customer's tests would also have 11 | // that set. Using this environment variable allows us to make sure we're only 12 | // running in the test suite for this plugin, and not implementors' tests. 13 | process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] = 'true'; 14 | -------------------------------------------------------------------------------- /packages/apollo-server-env/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-env", 3 | "version": "3.0.0", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-server-env" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "browser": "dist/index.browser.js", 17 | "types": "dist/index.d.ts", 18 | "scripts": { 19 | "clean": "git clean -fdX -- dist", 20 | "compile": "tsc && cp src/*.d.ts dist", 21 | "prepare": "npm run clean && npm run compile" 22 | }, 23 | "engines": { 24 | "node": ">=6" 25 | }, 26 | "dependencies": { 27 | "node-fetch": "^2.1.2", 28 | "util.promisify": "^1.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/apollo-server-integration-testsuite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-integration-testsuite", 3 | "private": true, 4 | "version": "2.19.2", 5 | "description": "Apollo Server Integrations testsuite", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/apollographql/apollo-server", 11 | "directory": "packages/apollo-server-integration-testsuite" 12 | }, 13 | "keywords": [], 14 | "author": "Apollo ", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/apollographql/apollo-server/issues" 18 | }, 19 | "homepage": "https://github.com/apollographql/apollo-server#readme", 20 | "engines": { 21 | "node": ">=6" 22 | }, 23 | "dependencies": { 24 | "apollo-server-core": "file:../apollo-server-core", 25 | "apollo-server-types": "file:../apollo-server-types" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/apollo-server/scripts/prepare-package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # When we publish to npm, the published files are available in the root 4 | # directory, which allows for a clean include or require of sub-modules. 5 | # 6 | # var language = require('apollo-server/express'); 7 | # 8 | 9 | # Ensure a vanilla package.json before deploying so other tools do not interpret 10 | # The built output as requiring any further transformation. 11 | node -e "var package = require('./package.json'); \ 12 | delete package.scripts; \ 13 | delete package.private; \ 14 | delete package.devDependencies; \ 15 | package.main = 'index.js'; \ 16 | package.module = 'index.js'; \ 17 | package.typings = 'index.d.ts'; \ 18 | var origVersion = 'local'; 19 | var fs = require('fs'); \ 20 | fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2)); \ 21 | " 22 | 23 | 24 | # Copy few more files to ./npm 25 | cp README.md npm/ 26 | cp ../../LICENSE npm/ 27 | -------------------------------------------------------------------------------- /docs/source/images/index-get-started.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Group 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | GET STARTED! 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/graphql-extensions/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | > This package is deprecated. Please use the [Apollo Server Plugin API](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) (specified on the `plugins` property, rather than `extensions`), which provides the same functionality (and more). 4 | 5 | ### 0.1.0-beta 6 | - *Backwards-incompatible change*: `fooDidStart` handlers (where foo is `request`, `parsing`, `validation`, and `execution`) now return their end handler; the `fooDidEnd` handlers no longer exist. The end handlers now take errors. There is a new `willSendResponse` handler. The `fooDidStart` handlers take extra options (eg, the `ExecutionArgs` for `executionDidStart`). 7 | - *Backwards-incompatible change*: Previously, the `GraphQLExtensionStack` constructor took either `GraphQLExtension` objects or their constructors. Now you may only pass in `GraphQLExtension` objects. 8 | 9 | ### 0.0.10 10 | - Fix lifecycle method invocations on extensions 11 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/__mocks__/ioredis.ts: -------------------------------------------------------------------------------- 1 | const IORedis = jest.genMockFromModule('ioredis'); 2 | 3 | const keyValue = {}; 4 | 5 | const deleteKey = key => { 6 | delete keyValue[key]; 7 | return Promise.resolve(true); 8 | }; 9 | 10 | const getKey = key => { 11 | if (keyValue[key]) { 12 | return Promise.resolve(keyValue[key].value); 13 | } 14 | 15 | return Promise.resolve(undefined); 16 | }; 17 | 18 | const mGetKey = (key, cb) => getKey(key).then(val => [val]); 19 | 20 | const setKey = (key, value, type, ttl) => { 21 | keyValue[key] = { 22 | value, 23 | ttl, 24 | }; 25 | if (ttl) { 26 | setTimeout(() => { 27 | delete keyValue[key]; 28 | }, ttl * 1000); 29 | } 30 | return Promise.resolve(true); 31 | }; 32 | 33 | IORedis.prototype.del.mockImplementation(deleteKey); 34 | IORedis.prototype.get.mockImplementation(getKey); 35 | IORedis.prototype.mget.mockImplementation(mGetKey); 36 | IORedis.prototype.set.mockImplementation(setKey); 37 | 38 | export default IORedis; 39 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/KeyValueCache.ts: -------------------------------------------------------------------------------- 1 | /** Options for {@link KeyValueCache.set} */ 2 | export interface KeyValueCacheSetOptions { 3 | /** 4 | * Specified in **seconds**, the time-to-live (TTL) value limits the lifespan 5 | * of the data being stored in the cache. 6 | */ 7 | ttl?: number | null 8 | }; 9 | 10 | export interface KeyValueCache { 11 | get(key: string): Promise; 12 | set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise; 13 | delete(key: string): Promise; 14 | } 15 | 16 | export interface TestableKeyValueCache extends KeyValueCache { 17 | // Drops all data from the cache. This should only be used by test suites --- 18 | // production code should never drop all data from an end user cache (and 19 | // notably, PrefixingKeyValueCache intentionally doesn't implement this). 20 | flush?(): Promise; 21 | // Close connections associated with this cache. 22 | close?(): Promise; 23 | } 24 | -------------------------------------------------------------------------------- /packages/apollo-cache-control/src/__tests__/cacheControlSupport.ts: -------------------------------------------------------------------------------- 1 | import { buildSchema } from 'graphql'; 2 | import { makeExecutableSchema } from 'graphql-tools'; 3 | 4 | type FirstArg = F extends (arg: infer A) => any ? A : never; 5 | 6 | export function augmentTypeDefsWithCacheControlSupport(typeDefs: string) { 7 | return ( 8 | ` 9 | enum CacheControlScope { 10 | PUBLIC 11 | PRIVATE 12 | } 13 | 14 | directive @cacheControl( 15 | maxAge: Int 16 | scope: CacheControlScope 17 | ) on FIELD_DEFINITION | OBJECT | INTERFACE 18 | ` + typeDefs 19 | ); 20 | } 21 | 22 | export function buildSchemaWithCacheControlSupport(source: string) { 23 | return buildSchema(augmentTypeDefsWithCacheControlSupport(source)); 24 | } 25 | 26 | export function makeExecutableSchemaWithCacheControlSupport( 27 | options: FirstArg & { typeDefs: string }, 28 | ) { 29 | return makeExecutableSchema({ 30 | ...options, 31 | typeDefs: augmentTypeDefsWithCacheControlSupport(options.typeDefs), 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-datasource-rest", 3 | "version": "0.9.7", 4 | "author": "Apollo ", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/apollographql/apollo-server", 9 | "directory": "packages/apollo-datasource-rest" 10 | }, 11 | "homepage": "https://github.com/apollographql/apollo-server#readme", 12 | "bugs": { 13 | "url": "https://github.com/apollographql/apollo-server/issues" 14 | }, 15 | "main": "dist/index.js", 16 | "types": "dist/index.d.ts", 17 | "engines": { 18 | "node": ">=6" 19 | }, 20 | "dependencies": { 21 | "apollo-datasource": "file:../apollo-datasource", 22 | "apollo-server-caching": "file:../apollo-server-caching", 23 | "apollo-server-env": "file:../apollo-server-env", 24 | "apollo-server-errors": "file:../apollo-server-errors", 25 | "http-cache-semantics": "^4.0.0" 26 | }, 27 | "devDependencies": { 28 | "apollo-server-types": "file:../apollo-server-types" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/acephei/services/accounts/src/data.ts: -------------------------------------------------------------------------------- 1 | import { DataSource } from "apollo-datasource"; 2 | import DataLoader from "dataloader"; 3 | 4 | export interface User { 5 | id: string; 6 | username: string; 7 | birthDate: string; 8 | name: string; 9 | } 10 | 11 | export class UsersDataSource implements DataSource { 12 | private loader?: DataLoader; 13 | initialize() { 14 | this.loader = new DataLoader((keys: string[]) => 15 | Promise.resolve( 16 | users.filter(({ id }) => { 17 | return keys.indexOf(id) > -1; 18 | }) 19 | ) 20 | ); 21 | } // where you can get access to context and cache 22 | find(id?: string) { 23 | if (!id) throw new Error("Can not find user without id") 24 | return this.loader!.load(id); 25 | } 26 | } 27 | 28 | const users = [ 29 | { 30 | id: "1", 31 | name: "Ada Lovelace", 32 | birthDate: "1815-12-10", 33 | username: "@ada" 34 | }, 35 | { 36 | id: "2", 37 | name: "Alan Turing", 38 | birthDate: "1912-06-23", 39 | username: "@complete" 40 | } 41 | ]; 42 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-cloudflare", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Cloudflare workers", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-cloudflare-workers" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Server", 16 | "Cloudflare", 17 | "Javascript" 18 | ], 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "homepage": "https://github.com/apollographql/apollo-server#readme", 24 | "dependencies": { 25 | "apollo-server-core": "file:../apollo-server-core", 26 | "apollo-server-env": "file:../apollo-server-env", 27 | "apollo-server-types": "file:../apollo-server-types" 28 | }, 29 | "peerDependencies": { 30 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/apollo-datasource-rest/src/types/http-cache-semantics/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'http-cache-semantics' { 2 | interface Request { 3 | url: string; 4 | method: string; 5 | headers: Headers; 6 | } 7 | 8 | interface Response { 9 | status: number; 10 | headers: Headers; 11 | } 12 | 13 | type Headers = { [name: string]: string }; 14 | 15 | class CachePolicy { 16 | constructor(request: Request, response: Response); 17 | 18 | storable(): boolean; 19 | 20 | satisfiesWithoutRevalidation(request: Request): boolean; 21 | responseHeaders(): Headers; 22 | 23 | age(): number; 24 | timeToLive(): number; 25 | 26 | revalidationHeaders(request: Request): Headers; 27 | revalidatedPolicy( 28 | request: Request, 29 | response: Response, 30 | ): { policy: CachePolicy; modified: boolean }; 31 | 32 | static fromObject(object: object): CachePolicy; 33 | toObject(): object; 34 | 35 | _url: string | undefined; 36 | _status: number; 37 | _rescc: { [key: string]: any }; 38 | } 39 | 40 | export = CachePolicy; 41 | } 42 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-testing", 3 | "version": "2.19.2", 4 | "description": "Test utils for apollo-server", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-testing" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Server", 16 | "Javascript" 17 | ], 18 | "author": "Apollo ", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "homepage": "https://github.com/apollographql/apollo-server#readme", 24 | "engines": { 25 | "node": ">=6" 26 | }, 27 | "dependencies": { 28 | "apollo-server-core": "file:../apollo-server-core" 29 | }, 30 | "devDependencies": { 31 | "apollo-server-types": "file:../apollo-server-types" 32 | }, 33 | "peerDependencies": { 34 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/apollo-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server", 3 | "version": "2.19.2", 4 | "description": "Production ready GraphQL Server", 5 | "author": "Apollo ", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/apollographql/apollo-server", 11 | "directory": "packages/apollo-server" 12 | }, 13 | "keywords": [ 14 | "GraphQL", 15 | "Apollo", 16 | "Server", 17 | "Javascript" 18 | ], 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "homepage": "https://github.com/apollographql/apollo-server#readme", 24 | "dependencies": { 25 | "apollo-server-core": "file:../apollo-server-core", 26 | "apollo-server-express": "file:../apollo-server-express", 27 | "express": "^4.0.0", 28 | "graphql-subscriptions": "^1.0.0", 29 | "graphql-tools": "^4.0.0" 30 | }, 31 | "peerDependencies": { 32 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-plugin-operation-registry", 3 | "version": "0.7.4", 4 | "description": "Apollo Server operation registry", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "keywords": [], 8 | "author": "Apollo ", 9 | "repository": { 10 | "type": "git", 11 | "url": "apollographql/apollo-server", 12 | "directory": "packages/apollo-server-plugin-operation-registry" 13 | }, 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">=8" 17 | }, 18 | "dependencies": { 19 | "apollo-graphql": "0.6.0", 20 | "apollo-server-caching": "file:../apollo-server-caching", 21 | "apollo-server-env": "file:../apollo-server-env", 22 | "apollo-server-errors": "file:../apollo-server-errors", 23 | "apollo-server-plugin-base": "file:../apollo-server-plugin-base", 24 | "fast-json-stable-stringify": "^2.0.0", 25 | "loglevel": "^1.6.1", 26 | "make-fetch-happen": "^8.0.7" 27 | }, 28 | "peerDependencies": { 29 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/src/ApolloServer.ts: -------------------------------------------------------------------------------- 1 | import { graphqlCloudflare } from './cloudflareApollo'; 2 | 3 | import { ApolloServerBase } from 'apollo-server-core'; 4 | export { GraphQLOptions, GraphQLExtension } from 'apollo-server-core'; 5 | import { GraphQLOptions } from 'apollo-server-core'; 6 | import { Request } from 'apollo-server-env'; 7 | 8 | export class ApolloServer extends ApolloServerBase { 9 | // This translates the arguments from the middleware into graphQL options It 10 | // provides typings for the integration specific behavior, ideally this would 11 | // be propagated with a generic to the super class 12 | async createGraphQLServerOptions(request: Request): Promise { 13 | return super.graphQLServerOptions({ request }); 14 | } 15 | 16 | public async listen() { 17 | await this.willStart(); 18 | addEventListener('fetch', (event: FetchEvent) => { 19 | event.respondWith( 20 | graphqlCloudflare(() => { 21 | return this.createGraphQLServerOptions(event.request); 22 | })(event.request), 23 | ); 24 | }); 25 | return await { url: '', port: null }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // Unfortunately, prettierrc doesn't support explicitly enumerating the files 3 | // we wish to "prettify", instead relying on them being passed as a glob on 4 | // the CLI. See https://github.com/prettier/prettier/issues/3764. 5 | // 6 | // Unfortunately, that complicates the `package.json` scripts since it 7 | // requires duplicating globs in multiple places, and also prevents 8 | // Prettier-enabled editors from knowing what files are to be covered. 9 | // 10 | // We can DRY this up a bit by leveraging "requirePragma", an instruction 11 | // that tells prettier to only prettify files which contain `@prettier` 12 | // (which none of the files in this repository have) and then specifying the 13 | // exact files to be prettified. As the issue above notes, this should become 14 | // more succinct in Prettier 2.x. 15 | requirePragma: true, 16 | overrides: [ 17 | { 18 | files: '{docs/{,source/**},.,packages/**,test}/{*.js,*.ts}', 19 | options: { 20 | requirePragma: false, 21 | trailingComma: 'all', 22 | singleQuote: true, 23 | }, 24 | }, 25 | ], 26 | }; 27 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-memcached/README.md: -------------------------------------------------------------------------------- 1 | ## MemcachedCache 2 | 3 | [![npm version](https://badge.fury.io/js/apollo-server-cache-memcached.svg)](https://badge.fury.io/js/apollo-server-cache-memcached) 4 | [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server) 5 | 6 | This package exports an implementation of `KeyValueCache` that allows using Memcached as a backing store for resource caching in [Data Sources](https://www.apollographql.com/docs/apollo-server/v2/features/data-sources.html). 7 | 8 | ## Usage 9 | 10 | ```js 11 | const { MemcachedCache } = require('apollo-server-cache-memcached'); 12 | 13 | const server = new ApolloServer({ 14 | typeDefs, 15 | resolvers, 16 | cache: new MemcachedCache( 17 | ['memcached-server-1', 'memcached-server-2', 'memcached-server-3'], 18 | { retries: 10, retry: 10000 }, // Options 19 | ), 20 | dataSources: () => ({ 21 | moviesAPI: new MoviesAPI(), 22 | }), 23 | }); 24 | ``` 25 | 26 | For documentation of the options you can pass to the underlying memcached client, look [here](https://github.com/3rd-Eden/memcached). 27 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/src/__tests__/hapiApollo.test.ts: -------------------------------------------------------------------------------- 1 | import { ApolloServer } from '../ApolloServer'; 2 | import { Config } from 'apollo-server-core'; 3 | 4 | import testSuite, { 5 | schema as Schema, 6 | CreateAppOptions, 7 | NODE_MAJOR_VERSION, 8 | } from 'apollo-server-integration-testsuite'; 9 | 10 | // NODE: Intentionally skip on Node.js < 8 since Hapi 17 doesn't support less 11 | (NODE_MAJOR_VERSION < 8 ? describe.skip : describe)('integration:Hapi', () => { 12 | async function createApp(options: CreateAppOptions = {}) { 13 | const { Server } = require('hapi'); 14 | 15 | const app: import('hapi').Server = new Server({ 16 | host: 'localhost', 17 | }); 18 | 19 | const server = new ApolloServer( 20 | (options.graphqlOptions as Config) || { schema: Schema }, 21 | ); 22 | await server.applyMiddleware({ 23 | app, 24 | }); 25 | 26 | await app.start(); 27 | 28 | return app.listener; 29 | } 30 | 31 | async function destroyApp(app) { 32 | if (!app || !app.close) { 33 | return; 34 | } 35 | await new Promise(resolve => app.close(resolve)); 36 | } 37 | 38 | testSuite(createApp, destroyApp); 39 | }); 40 | -------------------------------------------------------------------------------- /packages/apollo-tracing/README.md: -------------------------------------------------------------------------------- 1 | # Apollo Tracing (for Node.js) 2 | 3 | This package is used to collect and expose trace data in the [Apollo Tracing](https://github.com/apollographql/apollo-tracing) format. 4 | 5 | It relies on instrumenting a GraphQL schema to collect resolver timings, and exposes trace data for an individual request under `extensions` as part of the GraphQL response. 6 | 7 | This data can be consumed by [Apollo Studio](https://www.apollographql.com/docs/studio/) (previously, Apollo Engine and Apollo Graph Manager) or any other tool to provide visualization and history of field-by-field execution performance. 8 | 9 | ## Usage 10 | 11 | ### Apollo Server 12 | 13 | Apollo Server includes built-in support for tracing from version 1.1.0 onwards. 14 | 15 | The only code change required is to add `tracing: true` to the options passed to the `ApolloServer` constructor options for your integration of choice. For example, for [`apollo-server-express`](https://npm.im/apollo-server-express): 16 | 17 | ```javascript 18 | const { ApolloServer } = require('apollo-server-express'); 19 | 20 | const server = new ApolloServer({ 21 | schema, 22 | tracing: true, 23 | }); 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/global.d.ts: -------------------------------------------------------------------------------- 1 | declare function fetch( 2 | input: RequestInfo, 3 | init?: RequestInit, 4 | ): Promise; 5 | 6 | declare interface GlobalFetch { 7 | fetch(input: RequestInfo, init?: RequestInit): Promise; 8 | } 9 | 10 | type RequestInfo = import('./fetch').RequestInfo; 11 | type Headers = import('./fetch').Headers; 12 | type HeadersInit = import('./fetch').HeadersInit; 13 | type Body = import('./fetch').Body; 14 | type Request = import('./fetch').Request; 15 | type RequestAgent = import('./fetch').RequestAgent; 16 | type RequestInit = import('./fetch').RequestInit; 17 | type RequestMode = import('./fetch').RequestMode; 18 | type RequestCredentials = import('./fetch').RequestCredentials; 19 | type RequestCache = import('./fetch').RequestCache; 20 | type RequestRedirect = import('./fetch').RequestRedirect; 21 | type ReferrerPolicy = import('./fetch').ReferrerPolicy; 22 | type Response = import('./fetch').Response; 23 | type ResponseInit = import('./fetch').ResponseInit; 24 | type BodyInit = import('./fetch').BodyInit; 25 | type URLSearchParams = import('./url').URLSearchParams; 26 | type URLSearchParamsInit = import('./url').URLSearchParamsInit; 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/apollo-server-micro/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-micro", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Micro", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-micro" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Micro", 16 | "Server", 17 | "Javascript", 18 | "ZEIT" 19 | ], 20 | "author": "Apollo ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/apollographql/apollo-server/issues" 24 | }, 25 | "homepage": "https://github.com/apollographql/apollo-server#readme", 26 | "dependencies": { 27 | "@apollographql/graphql-playground-html": "1.6.26", 28 | "accept": "^3.0.2", 29 | "apollo-server-core": "file:../apollo-server-core", 30 | "apollo-server-types": "file:../apollo-server-types", 31 | "micro": "^9.3.2" 32 | }, 33 | "devDependencies": { 34 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-response-cache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-plugin-response-cache", 3 | "version": "0.5.8", 4 | "description": "Apollo Server full query response cache", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-plugin-response-cache" 11 | }, 12 | "keywords": [], 13 | "author": "Apollo ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/apollographql/apollo-server/issues" 17 | }, 18 | "homepage": "https://github.com/apollographql/apollo-server#readme", 19 | "engines": { 20 | "node": ">=6" 21 | }, 22 | "dependencies": { 23 | "apollo-cache-control": "file:../apollo-cache-control", 24 | "apollo-server-caching": "file:../apollo-server-caching", 25 | "apollo-server-plugin-base": "file:../apollo-server-plugin-base" 26 | }, 27 | "devDependencies": { 28 | "apollo-server-types": "file:../apollo-server-types" 29 | }, 30 | "peerDependencies": { 31 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/apollo-server-express/src/__tests__/connectApollo.test.ts: -------------------------------------------------------------------------------- 1 | import connect from 'connect'; 2 | import query from 'qs-middleware'; 3 | import { ApolloServer, ApolloServerExpressConfig } from '../ApolloServer'; 4 | 5 | import testSuite, { 6 | schema as Schema, 7 | CreateAppOptions, 8 | } from 'apollo-server-integration-testsuite'; 9 | 10 | function createConnectApp(options: CreateAppOptions = {}) { 11 | const app = connect(); 12 | // We do require users of ApolloServer with connect to use a query middleware 13 | // first. The alternative is to add a 'isConnect' bool to ServerRegistration 14 | // and make qs-middleware be a dependency of this package. However, we don't 15 | // think many folks use connect outside of Meteor anyway, and anyone using 16 | // connect is probably already using connect-query or qs-middleware. 17 | app.use(query()); 18 | const server = new ApolloServer( 19 | (options.graphqlOptions as ApolloServerExpressConfig) || { schema: Schema }, 20 | ); 21 | // See comment on ServerRegistration.app for its typing. 22 | server.applyMiddleware({ app: app as any }); 23 | return app; 24 | } 25 | 26 | describe('integration:Connect', () => { 27 | testSuite(createConnectApp); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/src/__tests__/fastifyApollo.test.ts: -------------------------------------------------------------------------------- 1 | import fastify from 'fastify'; 2 | import { Server } from 'http'; 3 | import { ApolloServer } from '../ApolloServer'; 4 | import testSuite, { 5 | schema as Schema, 6 | CreateAppOptions, 7 | } from 'apollo-server-integration-testsuite'; 8 | import { GraphQLOptions, Config } from 'apollo-server-core'; 9 | 10 | async function createApp(options: CreateAppOptions = {}) { 11 | const app = fastify(); 12 | 13 | const server = new ApolloServer( 14 | (options.graphqlOptions as Config) || { schema: Schema }, 15 | ); 16 | 17 | app.register(server.createHandler()); 18 | await app.listen(); 19 | 20 | return app.server; 21 | } 22 | 23 | async function destroyApp(app: Server) { 24 | if (!app || !app.close) { 25 | return; 26 | } 27 | await new Promise(resolve => app.close(resolve)); 28 | } 29 | 30 | describe('fastifyApollo', () => { 31 | it('throws error if called without schema', function() { 32 | expect(() => new ApolloServer(undefined as GraphQLOptions)).toThrow( 33 | 'ApolloServer requires options.', 34 | ); 35 | }); 36 | }); 37 | 38 | describe('integration:Fastify', () => { 39 | testSuite(createApp, destroyApp); 40 | }); 41 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/internalPlugin.ts: -------------------------------------------------------------------------------- 1 | import type { BaseContext } from 'apollo-server-types'; 2 | import type { ApolloServerPlugin } from 'apollo-server-plugin-base'; 3 | 4 | // This file's exports should not be exported from the overall 5 | // apollo-server-core module. 6 | 7 | // The internal plugins implement this interface which 8 | // ApolloServer.ensurePluginInstantiation uses to figure out if the plugins have 9 | // already been installed (or explicitly disabled via the matching Disable 10 | // plugins). 11 | export interface InternalApolloServerPlugin< 12 | TContext extends BaseContext = BaseContext 13 | > extends ApolloServerPlugin { 14 | // Used to identify a few specific plugins that are instantiated 15 | // by default if not explicitly used or disabled. 16 | __internal_plugin_id__(): InternalPluginId; 17 | } 18 | 19 | export type InternalPluginId = 20 | | 'SchemaReporting' 21 | | 'InlineTrace' 22 | | 'UsageReporting'; 23 | 24 | export function pluginIsInternal( 25 | plugin: ApolloServerPlugin, 26 | ): plugin is InternalApolloServerPlugin { 27 | // We could call the function and compare it to the list above, but this seems 28 | // good enough. 29 | return '__internal_plugin_id__' in plugin; 30 | } 31 | -------------------------------------------------------------------------------- /packages/apollo-server-express/src/__tests__/expressApollo.test.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { ApolloServer, ApolloServerExpressConfig } from '../ApolloServer'; 3 | import { graphqlExpress } from '../expressApollo'; 4 | import testSuite, { 5 | schema as Schema, 6 | CreateAppOptions, 7 | } from 'apollo-server-integration-testsuite'; 8 | import { GraphQLOptions } from 'apollo-server-core'; 9 | 10 | function createApp(options: CreateAppOptions = {}) { 11 | const app = express(); 12 | 13 | const server = new ApolloServer( 14 | (options.graphqlOptions as ApolloServerExpressConfig) || { schema: Schema }, 15 | ); 16 | server.applyMiddleware({ app }); 17 | return app; 18 | } 19 | 20 | describe('expressApollo', () => { 21 | it('throws error if called without schema', function() { 22 | expect(() => new ApolloServer(undefined as GraphQLOptions)).toThrow( 23 | 'ApolloServer requires options.', 24 | ); 25 | }); 26 | 27 | it('throws error if called with more than one argument', function() { 28 | expect(() => graphqlExpress({ schema: Schema }, 1)).toThrow( 29 | 'Apollo Server expects exactly one argument, got 2', 30 | ); 31 | }); 32 | }); 33 | 34 | describe('integration:Express', () => { 35 | testSuite(createApp); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/PrefixingKeyValueCache.ts: -------------------------------------------------------------------------------- 1 | import { KeyValueCache, KeyValueCacheSetOptions } from './KeyValueCache'; 2 | 3 | // PrefixingKeyValueCache wraps another cache and adds a prefix to all keys used 4 | // by all operations. This allows multiple features to share the same 5 | // underlying cache without conflicts. 6 | // 7 | // Note that PrefixingKeyValueCache explicitly does not implement 8 | // TestableKeyValueCache, and notably does not implement the flush() 9 | // method. Most implementations of TestableKeyValueCache.flush() send a simple 10 | // command that wipes the entire backend cache system, which wouldn't support 11 | // "only wipe the part of the cache with this prefix", so trying to provide a 12 | // flush() method here could be confusingly dangerous. 13 | export class PrefixingKeyValueCache implements KeyValueCache { 14 | constructor(private wrapped: KeyValueCache, private prefix: string) {} 15 | 16 | get(key: string) { 17 | return this.wrapped.get(this.prefix + key); 18 | } 19 | set(key: string, value: V, options?: KeyValueCacheSetOptions) { 20 | return this.wrapped.set(this.prefix + key, value, options); 21 | } 22 | delete(key: string) { 23 | return this.wrapped.delete(this.prefix + key); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/apollo-cache-control/src/__tests__/collectCacheControlHints.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLSchema, graphql } from 'graphql'; 2 | import { 3 | CacheHint, 4 | CacheControlExtensionOptions, 5 | plugin, 6 | } from '../'; 7 | import pluginTestHarness from 'apollo-server-core/dist/utils/pluginTestHarness'; 8 | 9 | export async function collectCacheControlHints( 10 | schema: GraphQLSchema, 11 | source: string, 12 | options?: CacheControlExtensionOptions, 13 | ): Promise { 14 | 15 | // Because this test helper looks at the formatted extensions, we always want 16 | // to include them in the response rather than allow them to be stripped 17 | // out. 18 | const pluginInstance = plugin({ 19 | ...options, 20 | stripFormattedExtensions: false, 21 | }); 22 | 23 | const requestContext = await pluginTestHarness({ 24 | pluginInstance, 25 | schema, 26 | graphqlRequest: { 27 | query: source, 28 | }, 29 | executor: async (requestContext) => { 30 | return await graphql({ 31 | schema, 32 | source: requestContext.request.query, 33 | contextValue: requestContext.context, 34 | }); 35 | } 36 | }); 37 | 38 | expect(requestContext.response.errors).toBeUndefined(); 39 | 40 | return requestContext.response.extensions!.cacheControl.hints; 41 | } 42 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/index.browser.js: -------------------------------------------------------------------------------- 1 | if (!global) { 2 | global = self; 3 | } 4 | 5 | let { fetch, Request, Response, Headers, URL, URLSearchParams } = global; 6 | fetch = fetch.bind(global); 7 | export { fetch, Request, Response, Headers, URL, URLSearchParams }; 8 | 9 | if (!global.process) { 10 | global.process = {}; 11 | } 12 | 13 | if (!global.process.env) { 14 | global.process.env = { 15 | // app is a global available on fly.io 16 | NODE_ENV: typeof app !== 'undefined' ? app.env : 'production', 17 | }; 18 | } 19 | 20 | if (!global.process.version) { 21 | global.process.version = ''; 22 | } 23 | 24 | if (!global.process.hrtime) { 25 | // Adapted from https://github.com/kumavis/browser-process-hrtime 26 | global.process.hrtime = function hrtime(previousTimestamp) { 27 | var clocktime = Date.now() * 1e-3; 28 | var seconds = Math.floor(clocktime); 29 | var nanoseconds = Math.floor((clocktime % 1) * 1e9); 30 | if (previousTimestamp) { 31 | seconds = seconds - previousTimestamp[0]; 32 | nanoseconds = nanoseconds - previousTimestamp[1]; 33 | if (nanoseconds < 0) { 34 | seconds--; 35 | nanoseconds += 1e9; 36 | } 37 | } 38 | return [seconds, nanoseconds]; 39 | }; 40 | } 41 | 42 | if (!global.os) { 43 | // FIXME: Add some sensible values 44 | global.os = {}; 45 | } 46 | -------------------------------------------------------------------------------- /jest.config.base.js: -------------------------------------------------------------------------------- 1 | const { defaults } = require("jest-config"); 2 | 3 | module.exports = { 4 | testEnvironment: "node", 5 | setupFiles: [ 6 | "/../apollo-server-env/dist/index.js" 7 | ], 8 | preset: "ts-jest", 9 | testMatch: null, 10 | testRegex: "/__tests__/.*\\.test\\.(js|ts)$", 11 | testPathIgnorePatterns: [ 12 | "/node_modules/", 13 | "/dist/" 14 | ], 15 | moduleFileExtensions: [...defaults.moduleFileExtensions, "ts", "tsx"], 16 | moduleNameMapper: { 17 | '^__mocks__/(.*)$': '/../../__mocks__/$1', 18 | // This regex should match the packages that we want compiled from source 19 | // through `ts-jest`, as opposed to loaded from their output files in 20 | // `dist`. 21 | // We don't want to match `apollo-server-env` and 22 | // `apollo-reporting-protobuf`, because these don't depend on 23 | // compilation but need to be initialized from as parto of `prepare`. 24 | '^(?!apollo-server-env|apollo-reporting-protobuf)(apollo-(?:server|datasource|cache-control|tracing)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '/../../packages/$1/src$2' 25 | }, 26 | clearMocks: true, 27 | globals: { 28 | "ts-jest": { 29 | tsConfig: "/src/__tests__/tsconfig.json", 30 | diagnostics: false 31 | } 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /packages/apollo-server-env/src/url.d.ts: -------------------------------------------------------------------------------- 1 | export declare class URL { 2 | constructor(input: string, base?: string | URL); 3 | hash: string; 4 | host: string; 5 | hostname: string; 6 | href: string; 7 | readonly origin: string; 8 | password: string; 9 | pathname: string; 10 | port: string; 11 | protocol: string; 12 | search: string; 13 | readonly searchParams: URLSearchParams; 14 | username: string; 15 | toString(): string; 16 | toJSON(): string; 17 | } 18 | 19 | export declare class URLSearchParams implements Iterable<[string, string]> { 20 | constructor(init?: URLSearchParamsInit); 21 | append(name: string, value: string): void; 22 | delete(name: string): void; 23 | entries(): IterableIterator<[string, string]>; 24 | forEach(callback: (value: string, name: string) => void): void; 25 | get(name: string): string | null; 26 | getAll(name: string): string[]; 27 | has(name: string): boolean; 28 | keys(): IterableIterator; 29 | set(name: string, value: string): void; 30 | sort(): void; 31 | toString(): string; 32 | values(): IterableIterator; 33 | [Symbol.iterator](): IterableIterator<[string, string]>; 34 | } 35 | 36 | export type URLSearchParamsInit = 37 | | URLSearchParams 38 | | string 39 | | { [key: string]: Object | Object[] | undefined } 40 | | Iterable<[string, Object]> 41 | | Array<[string, Object]>; 42 | -------------------------------------------------------------------------------- /packages/apollo-server-azure-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-azure-functions", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Azure Functions", 5 | "keywords": [ 6 | "GraphQL", 7 | "Apollo", 8 | "Server", 9 | "Azure", 10 | "Javascript" 11 | ], 12 | "author": "Apollo ", 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/apollographql/apollo-server", 17 | "directory": "packages/apollo-server-azure-functions" 18 | }, 19 | "homepage": "https://github.com/apollographql/apollo-server#readme", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "main": "dist/index.js", 24 | "types": "dist/index.d.ts", 25 | "engines": { 26 | "node": ">=6" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "@azure/functions": "1.2.2", 31 | "apollo-server-core": "file:../apollo-server-core", 32 | "apollo-server-env": "file:../apollo-server-env", 33 | "apollo-server-types": "file:../apollo-server-types", 34 | "graphql-tools": "^4.0.0" 35 | }, 36 | "devDependencies": { 37 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 38 | }, 39 | "peerDependencies": { 40 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/schema.ts: -------------------------------------------------------------------------------- 1 | import { pluginName } from './common'; 2 | import { parse } from 'graphql/language'; 3 | import { execute, ExecutionResult } from 'graphql/execution'; 4 | import { getIntrospectionQuery, IntrospectionSchema } from 'graphql/utilities'; 5 | import stableStringify from 'fast-json-stable-stringify'; 6 | import { GraphQLSchema } from 'graphql/type'; 7 | import { createHash } from 'crypto'; 8 | 9 | export async function generateSchemaHash( 10 | schema: GraphQLSchema, 11 | ): Promise { 12 | const introspectionQuery = getIntrospectionQuery(); 13 | const documentAST = parse(introspectionQuery); 14 | const result: ExecutionResult = await execute(schema, documentAST); 15 | 16 | if (!result || !result.data || !result.data.__schema) { 17 | throw new Error( 18 | `${pluginName}: Unable to generate server introspection document.`, 19 | ); 20 | } 21 | 22 | const introspectionSchema: IntrospectionSchema = result.data.__schema; 23 | 24 | // It's important that we perform a deterministic stringification here 25 | // since, depending on changes in the underlying `graphql-js` execution 26 | // layer, varying orders of the properties in the introspection 27 | const stringifiedSchema = stableStringify(introspectionSchema); 28 | 29 | return createHash('sha512') 30 | .update(stringifiedSchema) 31 | .digest('hex'); 32 | } 33 | -------------------------------------------------------------------------------- /packages/apollo-server-hapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-hapi", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Hapi", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-hapi" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Hapi", 16 | "Server", 17 | "Javascript" 18 | ], 19 | "author": "Apollo ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/apollographql/apollo-server/issues" 23 | }, 24 | "homepage": "https://github.com/apollographql/apollo-server#readme", 25 | "engines": { 26 | "node": ">=8" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "accept": "^3.0.2", 31 | "apollo-server-core": "file:../apollo-server-core", 32 | "apollo-server-types": "file:../apollo-server-types", 33 | "boom": "^7.1.0", 34 | "graphql-subscriptions": "^1.0.0", 35 | "graphql-tools": "^4.0.0" 36 | }, 37 | "devDependencies": { 38 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 39 | }, 40 | "peerDependencies": { 41 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /__mocks__/apollo-server-env.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { 4 | fetch, 5 | Request, 6 | RequestInit, 7 | Response, 8 | Body, 9 | BodyInit, 10 | Headers, 11 | HeadersInit, 12 | URL, 13 | URLSearchParams, 14 | URLSearchParamsInit, 15 | } from '../packages/apollo-server-env'; 16 | 17 | interface FetchMock extends jest.Mock { 18 | mockResponseOnce(data?: any, headers?: HeadersInit, status?: number): this; 19 | mockJSONResponseOnce(data?: object, headers?: HeadersInit): this; 20 | } 21 | 22 | const mockFetch = jest.fn(fetch) as FetchMock; 23 | 24 | mockFetch.mockResponseOnce = ( 25 | data?: BodyInit, 26 | headers?: Headers, 27 | status: number = 200, 28 | ) => { 29 | return mockFetch.mockImplementationOnce(async () => { 30 | return new Response(data, { 31 | status, 32 | headers, 33 | }); 34 | }); 35 | }; 36 | 37 | mockFetch.mockJSONResponseOnce = ( 38 | data = {}, 39 | headers?: Headers, 40 | status?: number, 41 | ) => { 42 | return mockFetch.mockResponseOnce( 43 | JSON.stringify(data), 44 | Object.assign({ 'Content-Type': 'application/json' }, headers), 45 | status, 46 | ); 47 | }; 48 | 49 | const env = { 50 | fetch: mockFetch, 51 | Request, 52 | Response, 53 | Body, 54 | Headers, 55 | URL, 56 | URLSearchParams, 57 | }; 58 | 59 | jest.doMock('apollo-server-env', () => env); 60 | 61 | export = env; 62 | -------------------------------------------------------------------------------- /packages/apollo-server-lambda/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-lambda", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for AWS Lambda", 5 | "keywords": [ 6 | "GraphQL", 7 | "Apollo", 8 | "Server", 9 | "Lambda", 10 | "Javascript" 11 | ], 12 | "author": "Apollo ", 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/apollographql/apollo-server", 17 | "directory": "packages/apollo-server-lambda" 18 | }, 19 | "homepage": "https://github.com/apollographql/apollo-server#readme", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "main": "dist/index.js", 24 | "types": "dist/index.d.ts", 25 | "engines": { 26 | "node": ">=6" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "@types/aws-lambda": "^8.10.31", 31 | "apollo-server-core": "file:../apollo-server-core", 32 | "apollo-server-env": "file:../apollo-server-env", 33 | "apollo-server-types": "file:../apollo-server-types", 34 | "graphql-tools": "^4.0.0" 35 | }, 36 | "devDependencies": { 37 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 38 | }, 39 | "peerDependencies": { 40 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-cloud-functions", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Google Cloud Functions", 5 | "keywords": [ 6 | "GraphQL", 7 | "Apollo", 8 | "Server", 9 | "Google Cloud Functions", 10 | "Javascript" 11 | ], 12 | "author": "Apollo ", 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/apollographql/apollo-server", 17 | "directory": "packages/apollo-server-cloud-functions" 18 | }, 19 | "homepage": "https://github.com/apollographql/apollo-server#readme", 20 | "bugs": { 21 | "url": "https://github.com/apollographql/apollo-server/issues" 22 | }, 23 | "main": "dist/index.js", 24 | "types": "dist/index.d.ts", 25 | "engines": { 26 | "node": ">=6" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "apollo-server-core": "file:../apollo-server-core", 31 | "apollo-server-env": "file:../apollo-server-env", 32 | "apollo-server-types": "file:../apollo-server-types", 33 | "graphql-tools": "^4.0.0" 34 | }, 35 | "devDependencies": { 36 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 37 | }, 38 | "peerDependencies": { 39 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-fastify", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Fastify", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-fastify" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Server", 16 | "Fastify", 17 | "Javascript" 18 | ], 19 | "author": "Apollo ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/apollographql/apollo-server/issues" 23 | }, 24 | "homepage": "https://github.com/apollographql/apollo-server#readme", 25 | "engines": { 26 | "node": ">=6" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "apollo-server-core": "file:../apollo-server-core", 31 | "apollo-server-types": "file:../apollo-server-types", 32 | "fastify-accepts": "^1.0.0", 33 | "fastify-cors": "^0.2.0", 34 | "graphql-subscriptions": "^1.0.0", 35 | "graphql-tools": "^4.0.0" 36 | }, 37 | "devDependencies": { 38 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 39 | }, 40 | "peerDependencies": { 41 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | }, 5 | "files": [], 6 | "include": [], 7 | "references": [ 8 | { "path": "./packages/apollo-cache-control/src/__tests__/" }, 9 | { "path": "./packages/apollo-datasource-rest/src/__tests__/" }, 10 | { "path": "./packages/apollo-server/src/__tests__/" }, 11 | { "path": "./packages/apollo-server-azure-functions/src/__tests__/" }, 12 | { "path": "./packages/apollo-server-cache-memcached/src/__tests__/" }, 13 | { "path": "./packages/apollo-server-cache-redis/src/__tests__/" }, 14 | { "path": "./packages/apollo-server-caching/src/__tests__/" }, 15 | { "path": "./packages/apollo-server-cloud-functions/src/__tests__/" }, 16 | { "path": "./packages/apollo-server-core/src/__tests__/" }, 17 | { "path": "./packages/apollo-server-errors/src/__tests__/" }, 18 | { "path": "./packages/apollo-server-express/src/__tests__/" }, 19 | { "path": "./packages/apollo-server-fastify/src/__tests__/" }, 20 | { "path": "./packages/apollo-server-hapi/src/__tests__/" }, 21 | { "path": "./packages/apollo-server-koa/src/__tests__/" }, 22 | { "path": "./packages/apollo-server-lambda/src/__tests__/" }, 23 | { "path": "./packages/apollo-server-micro/src/__tests__/" }, 24 | { "path": "./packages/apollo-server-plugin-operation-registry/src/__tests__/" }, 25 | { "path": "./packages/apollo-server-plugin-response-cache/src/__tests__/" }, 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /.github/APOLLO_RELEASE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Release X.Y.Z 2 | 3 | As with [release PRs in the past](https://github.com/apollographql/apollo-server/issues?q=label%3A%22%F0%9F%8F%97+release%22+is%3Aclosed), this is a PR tracking a `release-x.y.z` branch for an upcoming release of Apollo Server. 🙌 The version in the title of this PR should correspond to the appropriate branch. 4 | 5 | Check the appropriate milestone (to the right) for more details on what we hope to get into this release! 6 | 7 | The intention of these release branches is to gather changes which are intended to land in a specific version (again, indicated by the subject of this PR). Release branches allow additional clarity into what is being staged, provide a forum for comments from the community pertaining to the release's stability, and to facilitate the creation of pre-releases (e.g. `alpha`, `beta`, `rc`) without affecting the `main` branch. 8 | 9 | PRs for new features might be opened against or re-targeted to this branch by the project maintainers. The `main` branch may be periodically merged into this branch up until the point in time that this branch is being prepared for release. Depending on the size of the release, this may be once it reaches RC (release candidate) stage with an `-rc.x` release suffix. Some less substantial releases may be short-lived and may never have pre-release versions. 10 | 11 | When this version is officially released onto the `latest` npm tag, this PR will be merged into `main`. 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Reporting a Bug 3 | about: Open a new issue here if something isn't working as expected. 4 | --- 5 | 6 | 33 | -------------------------------------------------------------------------------- /docs/source/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction to Apollo Server 3 | sidebar_title: Introduction 4 | --- 5 | 6 | **Apollo Server is an [open-source](https://github.com/apollographql/apollo-server), spec-compliant GraphQL server** that's compatible with any GraphQL client, including [Apollo Client](https://www.apollographql.com/docs/react). It's the best way to build a production-ready, self-documenting GraphQL API that can use data from any source. 7 | 8 | ![diagram](./images/index-diagram.svg) 9 | 10 | #### You can use Apollo Server as: 11 | 12 | * A stand-alone GraphQL server, including in a serverless environment 13 | * An add-on to your application's existing [Node.js middleware](./integrations/middleware/) (such as Express or Fastify) 14 | * A gateway for a [federated data graph](https://www.apollographql.com/docs/federation/) 15 | 16 | #### Apollo Server provides: 17 | 18 | * **Straightforward setup**, so your client developers can start fetching data quickly 19 | * **Incremental adoption**, allowing you to add features as they're needed 20 | * **Universal compatibility** with any data source, any build tool, and any GraphQL client 21 | * **Production readiness**, enabling you to ship features faster 22 | 23 | #### Ready to try it out? 24 | 25 | import {Button} from '@apollo/space-kit/Button'; 26 | import {Link} from 'gatsby'; 27 | 28 |
29 | 32 |
33 | -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/src/index.js: -------------------------------------------------------------------------------- 1 | const protobuf = require('./protobuf'); 2 | const protobufJS = require('@apollo/protobufjs/minimal'); 3 | 4 | // Remove Long support. Our uint64s tend to be small (less 5 | // than 104 days). 6 | // https://github.com/protobufjs/protobuf.js/issues/1253 7 | protobufJS.util.Long = undefined; 8 | protobufJS.configure(); 9 | 10 | // Override the generated protobuf Traces.encode function so that it will look 11 | // for Traces that are already encoded to Buffer as well as unencoded 12 | // Traces. This amortizes the protobuf encoding time over each generated Trace 13 | // instead of bunching it all up at once at sendReport time. In load tests, this 14 | // change improved p99 end-to-end HTTP response times by a factor of 11 without 15 | // a casually noticeable effect on p50 times. This also makes it easier for us 16 | // to implement maxUncompressedReportSize as we know the encoded size of traces 17 | // as we go. 18 | const originalTracesAndStatsEncode = protobuf.TracesAndStats.encode; 19 | protobuf.TracesAndStats.encode = function(message, originalWriter) { 20 | const writer = originalTracesAndStatsEncode(message, originalWriter); 21 | const encodedTraces = message.encodedTraces; 22 | if (encodedTraces != null && encodedTraces.length) { 23 | for (let i = 0; i < encodedTraces.length; ++i) { 24 | writer.uint32(/* id 1, wireType 2 =*/ 10); 25 | writer.bytes(encodedTraces[i]); 26 | } 27 | } 28 | return writer; 29 | }; 30 | 31 | module.exports = protobuf; 32 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | }, 5 | "files": [], 6 | "include": [], 7 | "references": [ 8 | { "path": "./packages/apollo-cache-control" }, 9 | { "path": "./packages/apollo-datasource" }, 10 | { "path": "./packages/apollo-datasource-rest" }, 11 | { "path": "./packages/apollo-server" }, 12 | { "path": "./packages/apollo-server-azure-functions" }, 13 | { "path": "./packages/apollo-server-cache-memcached" }, 14 | { "path": "./packages/apollo-server-cache-redis" }, 15 | { "path": "./packages/apollo-server-caching" }, 16 | { "path": "./packages/apollo-server-cloud-functions" }, 17 | { "path": "./packages/apollo-server-cloudflare" }, 18 | { "path": "./packages/apollo-server-core" }, 19 | { "path": "./packages/apollo-server-errors" }, 20 | { "path": "./packages/apollo-server-express" }, 21 | { "path": "./packages/apollo-server-fastify" }, 22 | { "path": "./packages/apollo-server-hapi" }, 23 | { "path": "./packages/apollo-server-koa" }, 24 | { "path": "./packages/apollo-server-lambda" }, 25 | { "path": "./packages/apollo-server-micro" }, 26 | { "path": "./packages/apollo-server-plugin-base" }, 27 | { "path": "./packages/apollo-server-plugin-operation-registry" }, 28 | { "path": "./packages/apollo-server-plugin-response-cache" }, 29 | { "path": "./packages/apollo-server-testing" }, 30 | { "path": "./packages/apollo-tracing" }, 31 | { "path": "./packages/graphql-extensions" }, 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /examples/acephei/services/books/src/data.ts: -------------------------------------------------------------------------------- 1 | import { DataSource } from "apollo-datasource"; 2 | import DataLoader from "dataloader"; 3 | 4 | export interface Book { 5 | isbn: string 6 | title: string 7 | year: number | null 8 | similarBooks?: string[] 9 | } 10 | 11 | export class BooksDataSource implements DataSource { 12 | private loader?: DataLoader; 13 | initialize() { 14 | this.loader = new DataLoader((keys: string[]) => 15 | Promise.resolve( 16 | books.filter(({ isbn }) => { 17 | return keys.indexOf(isbn) > -1; 18 | }) 19 | ) 20 | ); 21 | } // where you can get access to context and cache 22 | find(isbn?: string) { 23 | if (!isbn) throw new Error("Can not find book without isbn") 24 | return this.loader!.load(isbn); 25 | } 26 | } 27 | 28 | const books = [ 29 | { 30 | isbn: '0262510871', 31 | title: 'Structure and Interpretation of Computer Programs', 32 | year: 1996, 33 | }, 34 | { 35 | isbn: '0136291554', 36 | title: 'Object Oriented Software Construction', 37 | year: 1997, 38 | }, 39 | { 40 | isbn: '0201633612', 41 | title: 'Design Patterns', 42 | year: 1995, 43 | similarBooks: ['0201633612', '0136291554'], 44 | }, 45 | { 46 | isbn: '1234567890', 47 | title: 'The Year Was Null', 48 | year: null, 49 | }, 50 | { 51 | isbn: '404404404', 52 | title: '', 53 | year: 404, 54 | }, 55 | { 56 | isbn: '0987654321', 57 | title: 'No Books Like This Book!', 58 | year: 2019, 59 | }, 60 | ]; -------------------------------------------------------------------------------- /packages/apollo-cache-control/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | > **A note on ommitted versions**: Due to the way that the Apollo Server 4 | > monorepo releases occur (via Lerna with _exact_ version pinning), the 5 | > version of the `apollo-cache-control` package is sometimes bumped and 6 | > published despite having no functional changes in its behavior. We will 7 | > always attempt to specifically mention functional changes to the 8 | > `apollo-cache-control` package within this particular `CHANGELOG.md`. 9 | 10 | ### v0.4.1 11 | 12 | * Fix cache hints of `maxAge: 0` to mean "uncachable". (#2197) 13 | * Apply `defaultMaxAge` to scalar fields on the root object. (#2210) 14 | 15 | ### v0.3.0 16 | 17 | * Support calculating Cache-Control HTTP headers when used by `apollo-server@2.0.0`. 18 | 19 | ### v0.2.0 20 | 21 | Moved to the `apollo-server` git repository. No code changes. (There are a 22 | number of other 0.2.x releases with no code changes due to how the 23 | `apollo-server` release process works.) 24 | 25 | ### v0.1.1 26 | 27 | * Fix `defaultMaxAge` feature (introduced in 0.1.0) so that `maxAge: 0` overrides the default, as previously documented. 28 | 29 | ### v0.1.0 30 | 31 | * **New feature**: New `defaultMaxAge` constructor option. (`apollo-server-*` will be updated to allow you to pass constructor options to the extension.) 32 | 33 | 34 | ### v0.0.10 35 | 36 | * Update peer dependencies to support `graphql@0.13`. 37 | * Expose `context.cacheControl.cacheHint` to resolvers. 38 | 39 | (Older versions exist but have no CHANGELOG entries.) 40 | -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-reporting-protobuf", 3 | "version": "0.6.2", 4 | "description": "Protobuf format for Apollo usage reporting", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "scripts": { 8 | "clean": "git clean -fdX -- dist", 9 | "prepare": "npm run clean && mkdir dist && npm run prepare:proto && npm run pbjs && npm run pbts && cp src/* dist", 10 | "pbjs": "apollo-pbjs --target static-module --out dist/protobuf.js --wrap commonjs --force-number dist/reports.proto", 11 | "pbts": "apollo-pbts -o dist/protobuf.d.ts dist/protobuf.js", 12 | "prepare:proto": "npm run prepare:proto:nix -s || npm run prepare:proto:win -s", 13 | "prepare:proto:nix": "grep -v \"package mdg.engine.proto\" src/reports.proto > dist/reports.proto", 14 | "prepare:proto:win": "type src\\reports.proto | findstr /V \"package mdg.engine.proto\" > dist/reports.proto" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/apollographql/apollo-server", 19 | "directory": "packages/apollo-reporting-protobuf" 20 | }, 21 | "keywords": [ 22 | "GraphQL", 23 | "Apollo", 24 | "Server", 25 | "Javascript" 26 | ], 27 | "author": "Apollo ", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/apollographql/apollo-server/issues" 31 | }, 32 | "homepage": "https://github.com/apollographql/apollo-server#readme", 33 | "dependencies": { 34 | "@apollo/protobufjs": "^1.0.3" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/src/__tests__/googleCloudApollo.test.ts: -------------------------------------------------------------------------------- 1 | import { ApolloServer } from '../ApolloServer'; 2 | import testSuite, { 3 | schema as Schema, 4 | CreateAppOptions, 5 | } from 'apollo-server-integration-testsuite'; 6 | import { Config } from 'apollo-server-core'; 7 | import express = require('express'); 8 | import bodyParser = require('body-parser'); 9 | import request from 'supertest'; 10 | 11 | type GcfRequest = { 12 | path: string | null; 13 | host: string | null; 14 | }; 15 | 16 | const simulateGcfMiddleware = ( 17 | req: express.Request | GcfRequest, 18 | _: express.Response, 19 | next: express.NextFunction, 20 | ) => { 21 | // GCF will pass in a null path when accessing the 22 | // published endpoint directly 23 | if (req.path === '') { 24 | req['path'] = null; 25 | } 26 | next(); 27 | }; 28 | 29 | const createCloudFunction = (options: CreateAppOptions = {}) => { 30 | const handler = new ApolloServer( 31 | (options.graphqlOptions as Config) || { schema: Schema }, 32 | ).createHandler(); 33 | 34 | const app = express(); 35 | app.use(bodyParser.json()); 36 | app.use(simulateGcfMiddleware); 37 | app.use(handler); 38 | return app; 39 | }; 40 | 41 | describe('googleCloudApollo', () => { 42 | it('handles requests with path set to null', async () => { 43 | const app = await createCloudFunction(); 44 | const res = await request(app) 45 | .get('/') 46 | .set('Accept', 'text/html'); 47 | expect(res.statusCode).toEqual(200); 48 | }); 49 | }); 50 | 51 | describe('integration:CloudFunction', () => { 52 | testSuite(createCloudFunction); 53 | }); 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 32 | -------------------------------------------------------------------------------- /packages/apollo-server-core/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### vNEXT 4 | 5 | * `apollo-server-core`: Add persisted queries [PR#1149](https://github.com/apollographql/apollo-server/pull/1149) 6 | * `apollo-server-core`: added `BadUserInputError` 7 | * `apollo-server-core`: **breaking** gql is exported from gql-tag and ApolloServer requires a DocumentNode [PR#1146](https://github.com/apollographql/apollo-server/pull/1146) 8 | * `apollo-server-core`: accept `Request` object in `runQuery` [PR#1108](https://github.com/apollographql/apollo-server/pull/1108) 9 | * `apollo-server-core`: move query parse into runQuery and no longer accept GraphQL AST over the wire [PR#1097](https://github.com/apollographql/apollo-server/pull/1097) 10 | * `apollo-server-core`: custom errors allow instanceof checks [PR#1074](https://github.com/apollographql/apollo-server/pull/1074) 11 | * `apollo-server-core`: move subscriptions options into listen [PR#1059](https://github.com/apollographql/apollo-server/pull/1059) 12 | * `apollo-server-core`: Replace console.error with logFunction for opt-in logging [PR #1024](https://github.com/apollographql/apollo-server/pull/1024) 13 | * `apollo-server-core`: context creation can be async and errors are formatted to include error code [PR #1024](https://github.com/apollographql/apollo-server/pull/1024) 14 | * `apollo-server-core`: add `mocks` parameter to the base constructor(applies to all variants) [PR#1017](https://github.com/apollographql/apollo-server/pull/1017) 15 | * `apollo-server-core`: Remove printing of stack traces with `debug` option and include response in logging function[PR#1018](https://github.com/apollographql/apollo-server/pull/1018) 16 | -------------------------------------------------------------------------------- /packages/apollo-reporting-protobuf/README.md: -------------------------------------------------------------------------------- 1 | # `apollo-reporting-protobuf` 2 | 3 | > **Note:** The Apollo usage reporting API is subject to change. We strongly 4 | > encourage developers to contact Apollo support at `support@apollographql.com` 5 | > to discuss their use case prior to building their own reporting agent using 6 | > this module. 7 | 8 | This module provides JavaScript/TypeScript 9 | [Protocol buffer](https://developers.google.com/protocol-buffers/) definitions 10 | for the Apollo usage reporting API. These definitions are generated for 11 | consumption from the `reports.proto` file which is defined internally within 12 | Apollo. 13 | 14 | ## Development 15 | 16 | > **Note:** Due to a dependency on Unix tools (e.g. `bash`, `grep`, etc.), the 17 | > development of this module requires a Unix system. There is no reason why 18 | > this can't be avoided, the time just hasn't been taken to make those changes. 19 | > We'd happily accept a PR which makes the appropriate changes! 20 | 21 | Currently, this package generates a majority of its code with 22 | [`protobufjs`](https://www.npmjs.com/package/protobufjs) based on the 23 | `reports.proto` file. The output is generated with the `prepare` npm script. 24 | 25 | The root of the repository provides the `devDependencies` necessary to build 26 | these definitions (e.g. `pbjs`, `pbts`, `protobuf`, etc.) and the `prepare` 27 | npm script is invoked programmatically via the monorepo tooling (e.g. Lerna) 28 | thanks to _this_ module's `postinstall` script. Therefore, when making 29 | changes to this module, `npx lerna run prepare` should be run from the **root** 30 | of this monorepo in order to update the definitions in _this_ module. 31 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | This is the documentation **source** for this repository. 4 | 5 | The **deployed** version of the documentation for this repository is available at: 6 | 7 | * https://www.apollographql.com/docs/apollo-server/ 8 | 9 | ## Documentation for the documentation 10 | 11 | This `README.md` is intentionally short since the [documentation for the documentation](https://docs-docs.netlify.com/docs/docs/) provides details for the documentation framework _itself_. Additional information should generally be added to that documentation rather than here in this `README.md`, in order to provide a centralized resource that benefits all documentation deployments. 12 | 13 | ## Running locally 14 | 15 | For more information, consult the documentation for the documentation, referenced above. 16 | 17 | In general though: 18 | 19 | * `npm install` in this directory 20 | * `npm start` in this directory 21 | * Open a browser to the link provided in the console. 22 | 23 | > **Important note:** Changes to the markdown source does not result in an automatic "hot reload" in the browser; it is necessary to reload the page manually in the browser to see it re-rendered. Additionally, changes to `_config.yml` require stopping the server and restarting with `npm start` again. 24 | 25 | ## Deploy previews 26 | 27 | Documentation repositories should be setup with a "deploy preview" feature which automatically provides "preview" links in the _status checks_ section of pull-requests. 28 | 29 | In the event that it's not possible to run the documentation locally, pushing changes to the branch for a pull-request can be a suitable alternative that ensures changes to the documentation are properly rendered. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Feature Request 3 | about: Have a feature that you think is important? Help us understand it. 4 | --- 5 | 6 | 38 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-koa", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Koa", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-koa" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Server", 16 | "Koa", 17 | "Javascript" 18 | ], 19 | "author": "Apollo ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/apollographql/apollo-server/issues" 23 | }, 24 | "homepage": "https://github.com/apollographql/apollo-server#readme", 25 | "engines": { 26 | "node": ">=6" 27 | }, 28 | "dependencies": { 29 | "@apollographql/graphql-playground-html": "1.6.26", 30 | "@koa/cors": "^2.2.1", 31 | "@types/accepts": "^1.3.5", 32 | "@types/cors": "^2.8.4", 33 | "@types/koa": "^2.0.46", 34 | "@types/koa-bodyparser": "^4.2.1", 35 | "@types/koa-compose": "^3.2.2", 36 | "@types/koa__cors": "^2.2.1", 37 | "accepts": "^1.3.5", 38 | "apollo-server-core": "file:../apollo-server-core", 39 | "apollo-server-types": "file:../apollo-server-types", 40 | "graphql-subscriptions": "^1.0.0", 41 | "graphql-tools": "^4.0.0", 42 | "koa": "2.13.1", 43 | "koa-bodyparser": "^4.2.1", 44 | "koa-compose": "^4.1.0", 45 | "type-is": "^1.6.16" 46 | }, 47 | "devDependencies": { 48 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 49 | }, 50 | "peerDependencies": { 51 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/apollo-server-caching/src/InMemoryLRUCache.ts: -------------------------------------------------------------------------------- 1 | import LRUCache from 'lru-cache'; 2 | import { TestableKeyValueCache } from './KeyValueCache'; 3 | 4 | function defaultLengthCalculation(item: any) { 5 | if (Array.isArray(item) || typeof item === 'string') { 6 | return item.length; 7 | } 8 | 9 | // Go with the lru-cache default "naive" size, in lieu anything better: 10 | // https://github.com/isaacs/node-lru-cache/blob/a71be6cd/index.js#L17 11 | return 1; 12 | } 13 | 14 | export class InMemoryLRUCache implements TestableKeyValueCache { 15 | private store: LRUCache; 16 | 17 | // FIXME: Define reasonable default max size of the cache 18 | constructor({ 19 | maxSize = Infinity, 20 | sizeCalculator = defaultLengthCalculation, 21 | onDispose, 22 | }: { 23 | maxSize?: number; 24 | sizeCalculator?: (value: V, key: string) => number; 25 | onDispose?: (key: string, value: V) => void; 26 | } = {}) { 27 | this.store = new LRUCache({ 28 | max: maxSize, 29 | length: sizeCalculator, 30 | dispose: onDispose, 31 | }); 32 | } 33 | 34 | async get(key: string) { 35 | return this.store.get(key); 36 | } 37 | async set(key: string, value: V, options?: { ttl?: number }) { 38 | const maxAge = options && options.ttl && options.ttl * 1000; 39 | this.store.set(key, value, maxAge); 40 | } 41 | async delete(key: string) { 42 | this.store.del(key); 43 | } 44 | 45 | // Drops all data from the cache. This should only be used by test suites --- 46 | // production code should never drop all data from an end user cache. 47 | async flush(): Promise { 48 | this.store.reset(); 49 | } 50 | async getTotalSize() { 51 | return this.store.length; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/apollo-server-express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server-express", 3 | "version": "2.19.2", 4 | "description": "Production-ready Node.js GraphQL server for Express and Connect", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/apollographql/apollo-server", 10 | "directory": "packages/apollo-server-express" 11 | }, 12 | "keywords": [ 13 | "GraphQL", 14 | "Apollo", 15 | "Server", 16 | "Express", 17 | "Connect", 18 | "Javascript" 19 | ], 20 | "author": "Apollo ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/apollographql/apollo-server/issues" 24 | }, 25 | "homepage": "https://github.com/apollographql/apollo-server#readme", 26 | "engines": { 27 | "node": ">=6" 28 | }, 29 | "dependencies": { 30 | "@apollographql/graphql-playground-html": "1.6.26", 31 | "@types/accepts": "^1.3.5", 32 | "@types/body-parser": "1.19.0", 33 | "@types/cors": "2.8.8", 34 | "@types/express": "4.17.7", 35 | "@types/express-serve-static-core": "4.17.18", 36 | "accepts": "^1.3.5", 37 | "apollo-server-core": "file:../apollo-server-core", 38 | "apollo-server-types": "file:../apollo-server-types", 39 | "body-parser": "^1.18.3", 40 | "cors": "^2.8.4", 41 | "express": "^4.17.1", 42 | "graphql-subscriptions": "^1.0.0", 43 | "graphql-tools": "^4.0.0", 44 | "parseurl": "^1.3.2", 45 | "subscriptions-transport-ws": "^0.9.16", 46 | "type-is": "^1.6.16" 47 | }, 48 | "devDependencies": { 49 | "apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite" 50 | }, 51 | "peerDependencies": { 52 | "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /docs/source/data/file-uploads.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: File uploads 3 | description: Enabling file uploads in Apollo Server 4 | --- 5 | 6 | For server integrations that support file uploads (e.g. Express, hapi, Koa), Apollo Server enables file uploads by default. To enable file uploads, reference the `Upload` type in the schema passed to the Apollo Server construction. 7 | 8 | ```js 9 | const { ApolloServer, gql } = require('apollo-server'); 10 | 11 | const typeDefs = gql` 12 | type File { 13 | filename: String! 14 | mimetype: String! 15 | encoding: String! 16 | } 17 | 18 | type Query { 19 | uploads: [File] 20 | } 21 | 22 | type Mutation { 23 | singleUpload(file: Upload!): File! 24 | } 25 | `; 26 | 27 | const resolvers = { 28 | Query: { 29 | uploads: (parent, args) => {}, 30 | }, 31 | Mutation: { 32 | singleUpload: (parent, args) => { 33 | return args.file.then(file => { 34 | //Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload 35 | //file.createReadStream() is a readable node stream that contains the contents of the uploaded file 36 | //node stream api: https://nodejs.org/api/stream.html 37 | return file; 38 | }); 39 | }, 40 | }, 41 | }; 42 | 43 | const server = new ApolloServer({ 44 | typeDefs, 45 | resolvers, 46 | }); 47 | 48 | server.listen().then(({ url }) => { 49 | console.log(`🚀 Server ready at ${url}`); 50 | }); 51 | ``` 52 | 53 | > Note: When using `typeDefs`, Apollo Server adds `scalar Upload` to your schema, so any existing declaration of `scalar Upload` in the type definitions should be removed. If you create your schema with `makeExecutableSchema` and pass it to `ApolloServer` constructor using the `schema` param, make sure to include [`scalar Upload`](https://www.apollographql.com/docs/guides/file-uploads.html#File-upload-with-schema-param). 54 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/schemaReporting/__tests__/computeExecutableSchemaId.test.ts: -------------------------------------------------------------------------------- 1 | import { computeExecutableSchemaId } from '..'; 2 | import { printSchema, buildSchema } from 'graphql'; 3 | 4 | describe('Executable Schema Id', () => { 5 | const unsortedGQLSchemaDocument = ` 6 | directive @example on FIELD 7 | union AccountOrUser = Account | User 8 | type Query { 9 | userOrAccount(name: String, id: String): AccountOrUser 10 | } 11 | 12 | type User { 13 | accounts: [Account!] 14 | email: String 15 | name: String! 16 | } 17 | 18 | type Account { 19 | name: String! 20 | id: ID! 21 | } 22 | `; 23 | 24 | const sortedGQLSchemaDocument = ` 25 | directive @example on FIELD 26 | union AccountOrUser = Account | User 27 | 28 | type Account { 29 | name: String! 30 | id: ID! 31 | } 32 | 33 | type Query { 34 | userOrAccount(id: String, name: String): AccountOrUser 35 | } 36 | 37 | type User { 38 | accounts: [Account!] 39 | email: String 40 | name: String! 41 | } 42 | 43 | `; 44 | it('does not normalize GraphQL schemas', () => { 45 | // This test made a bit more sense back when computeExecutableSchemaId could take 46 | // a GraphQLSchema directly, but maybe it's still vaguely helpful. 47 | expect( 48 | computeExecutableSchemaId( 49 | printSchema(buildSchema(unsortedGQLSchemaDocument)), 50 | ), 51 | ).not.toEqual( 52 | computeExecutableSchemaId( 53 | printSchema(buildSchema(sortedGQLSchemaDocument)), 54 | ), 55 | ); 56 | }); 57 | it('does not normalize strings', () => { 58 | expect(computeExecutableSchemaId(unsortedGQLSchemaDocument)).not.toEqual( 59 | computeExecutableSchemaId(sortedGQLSchemaDocument), 60 | ); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /docs/source/requests.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: POST and GET format 3 | description: How to send requests to Apollo Server over HTTP. 4 | --- 5 | 6 | Apollo Server accepts both GET and POST requests. 7 | 8 | ## POST requests 9 | 10 | Apollo Server accepts POST requests with a JSON body. A valid request must contain either a `query` or an `operationName` (or both, in case of a named query), and may include `variables.` Here's an example for a valid body of a post request: 11 | 12 | ```js 13 | { 14 | "query": "query aTest($arg1: String!) { test(who: $arg1) }", 15 | "operationName": "aTest", 16 | "variables": { "arg1": "me" } 17 | } 18 | ``` 19 | 20 | Variables can be an object or a JSON-encoded string. I.e. the following is equivalent to the previous query: 21 | 22 | ```js 23 | { 24 | "query": "query aTest($arg1: String!) { test(who: $arg1) }", 25 | "operationName": "aTest", 26 | "variables": "{ \"arg1\": \"me\" }" 27 | } 28 | ``` 29 | 30 | ### Batching 31 | 32 | A batch of queries can be sent by simply sending a JSON-encoded array of queries, e.g. 33 | 34 | ```js 35 | [{ query: '{ testString }' }, { query: 'query q2{ test(who: "you" ) }' }]; 36 | ``` 37 | 38 | If a batch of queries is sent, the response will be an array of GraphQL responses. 39 | 40 | If Apollo Server is running under a different origin than your client, you will need to enable CORS support on the server, or proxy the GraphQL requests through a web server under the main origin. 41 | 42 | ## GET requests 43 | 44 | Apollo Server also accepts GET requests. A GET request must pass query and optionally variables and operationName in the URL. 45 | 46 | Here is the same query from above in a well-formatted GET request to Apollo Server: 47 | 48 | ``` 49 | GET /graphql?query=query%20aTest(%24arg1%3A%20String!)%20%7B%20test(who%3A%20%24arg1)%20%7D&operationName=aTest&variables=me 50 | ``` 51 | 52 | caveat: Mutations cannot be executed via GET requests. 53 | -------------------------------------------------------------------------------- /packages/apollo-server-errors/src/__tests__/ApolloError.test.ts: -------------------------------------------------------------------------------- 1 | import { ApolloError } from '..'; 2 | 3 | describe('ApolloError', () => { 4 | it("doesn't overwrite extensions when provided in the constructor", () => { 5 | const error = new ApolloError('My message', 'A_CODE', { 6 | arbitrary: 'user_data', 7 | }); 8 | 9 | expect(error.extensions).toEqual({ 10 | code: 'A_CODE', 11 | arbitrary: 'user_data', 12 | }); 13 | }); 14 | 15 | it("a code property doesn't overwrite the code provided to the constructor", () => { 16 | const error = new ApolloError('My message', 'A_CODE', { 17 | code: 'CANT_OVERWRITE', 18 | }); 19 | 20 | expect(error.extensions).toEqual({ 21 | code: 'A_CODE', 22 | }); 23 | }); 24 | 25 | // This is a byproduct of how we currently assign properties from the 3rd constructor 26 | // argument onto properties of the class itself. This is expected, but deprecated behavior 27 | // and as such this test should be deleted in the future when we make that breaking change. 28 | it("a message property doesn't overwrite the message provided to the constructor", () => { 29 | const error = new ApolloError('My original message', 'A_CODE', { 30 | message: 31 | "This message can't overwrite the original message, but it does end up in extensions", 32 | }); 33 | 34 | expect(error.message).toEqual('My original message'); 35 | expect(error.extensions.message).toEqual( 36 | "This message can't overwrite the original message, but it does end up in extensions", 37 | ); 38 | }); 39 | 40 | it('(back-compat) sets extensions correctly for users who use an extensions key in the third constructor argument', () => { 41 | const error = new ApolloError('My original message', 'A_CODE', { 42 | extensions: { 43 | arbitrary: 'user_data', 44 | }, 45 | }); 46 | 47 | expect(error.extensions.arbitrary).toEqual('user_data'); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /packages/apollo-server-testing/src/createTestClient.ts: -------------------------------------------------------------------------------- 1 | import { ApolloServerBase } from 'apollo-server-core'; 2 | import { GraphQLResponse as GraphQLResponseType } from 'apollo-server-types'; 3 | import { print, DocumentNode } from 'graphql'; 4 | 5 | type StringOrAst = string | DocumentNode; 6 | 7 | // A query must not come with a mutation (and vice versa). 8 | type Query> = { 9 | query: StringOrAst; 10 | mutation?: undefined; 11 | variables?: TVariables; 12 | operationName?: string; 13 | }; 14 | type Mutation> = { 15 | mutation: StringOrAst; 16 | query?: undefined; 17 | variables?: TVariables; 18 | operationName?: string; 19 | }; 20 | 21 | type GraphQLResponse = Omit & { 22 | data?: TData; 23 | }; 24 | 25 | export interface ApolloServerTestClient { 26 | query>(query: Query): Promise>; 27 | mutate>(mutation: Mutation): Promise>; 28 | } 29 | 30 | export default (server: ApolloServerBase): ApolloServerTestClient => { 31 | const executeOperation = server.executeOperation.bind(server); 32 | const test = ({ query, mutation, ...args }: Query | Mutation) => { 33 | const operation = query || mutation; 34 | 35 | if (!operation || (query && mutation)) { 36 | throw new Error( 37 | 'Either `query` or `mutation` must be passed, but not both.', 38 | ); 39 | } 40 | 41 | return executeOperation({ 42 | // Convert ASTs, which are produced by `graphql-tag` but not currently 43 | // used by `executeOperation`, to a String using `graphql/language/print`. 44 | query: typeof operation === 'string' ? operation : print(operation), 45 | ...args, 46 | }); 47 | }; 48 | 49 | return { query: test, mutate: test } as ApolloServerTestClient; 50 | }; 51 | -------------------------------------------------------------------------------- /packages/apollo-server-cache-redis/src/RedisCache.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TestableKeyValueCache, 3 | KeyValueCacheSetOptions, 4 | } from 'apollo-server-caching'; 5 | import Redis, { RedisOptions } from 'ioredis'; 6 | import DataLoader from 'dataloader'; 7 | 8 | export class RedisCache implements TestableKeyValueCache { 9 | readonly client: any; 10 | readonly defaultSetOptions: KeyValueCacheSetOptions = { 11 | ttl: 300, 12 | }; 13 | 14 | private loader: DataLoader; 15 | 16 | constructor(options?: RedisOptions) { 17 | const client = new Redis(options); 18 | this.client = client; 19 | 20 | this.loader = new DataLoader(keys => client.mget(...keys), { 21 | cache: false, 22 | }); 23 | } 24 | 25 | async set( 26 | key: string, 27 | value: string, 28 | options?: KeyValueCacheSetOptions, 29 | ): Promise { 30 | const { ttl } = Object.assign({}, this.defaultSetOptions, options); 31 | if (typeof ttl === 'number') { 32 | await this.client.set(key, value, 'EX', ttl); 33 | } else { 34 | // We'll leave out the EXpiration when no value is specified. Of course, 35 | // it may be purged from the cache for other reasons as deemed necessary. 36 | await this.client.set(key, value); 37 | } 38 | } 39 | 40 | async get(key: string): Promise { 41 | const reply = await this.loader.load(key); 42 | if (reply !== null) { 43 | return reply; 44 | } 45 | return; 46 | } 47 | 48 | async delete(key: string): Promise { 49 | return await this.client.del(key); 50 | } 51 | 52 | // Drops all data from Redis. This should only be used by test suites --- 53 | // production code should never drop all data from an end user Redis cache! 54 | async flush(): Promise { 55 | await this.client.flushdb(); 56 | } 57 | 58 | async close(): Promise { 59 | await this.client.quit(); 60 | return; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /docs/source/monitoring/health-checks.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Health checks 3 | description: Determining the health status of the Apollo Server 4 | --- 5 | 6 | Health checks are often used by load balancers to determine if a server is available and ready to start serving traffic. By default, Apollo Server provides a health check endpoint at `/.well-known/apollo/server-health` which returns a 200 status code if the server has started. 7 | 8 | This basic health check may not be comprehensive enough for some applications and depending on individual circumstances, it may be beneficial to provide a more thorough implementation by defining an `onHealthCheck` function to the `ApolloServer` constructor options. If defined, this `onHealthCheck` function should return a `Promise` which _rejects_ if there is an error, or _resolves_ if the server is deemed _ready_. A `Promise` _rejection_ will result in an HTTP status code of 503, and a _resolution_ will result in an HTTP status code of 200, which is generally desired by most health-check tooling (e.g. Kubernetes, AWS, etc.). 9 | 10 | > **Note:** Alternatively, the `onHealthCheck` can be defined as an `async` function which `throw`s if it encounters an error and returns when conditions are considered normal. 11 | 12 | ```js{10-19} 13 | const { ApolloServer, gql } = require('apollo-server'); 14 | 15 | // Undefined for brevity. 16 | const typeDefs = gql``; 17 | const resolvers = {}; 18 | 19 | const server = new ApolloServer({ 20 | typeDefs, 21 | resolvers, 22 | onHealthCheck: () => { 23 | return new Promise((resolve, reject) => { 24 | // Replace the `true` in this conditional with more specific checks! 25 | if (true) { 26 | resolve(); 27 | } else { 28 | reject(); 29 | } 30 | }); 31 | }, 32 | }); 33 | 34 | server.listen().then(({ url }) => { 35 | console.log(`🚀 Server ready at ${url}`); 36 | console.log( 37 | `Try your health check at: ${url}.well-known/apollo/server-health`, 38 | ); 39 | }); 40 | ``` 41 | -------------------------------------------------------------------------------- /packages/apollo-server-core/src/plugin/schemaReporting/__tests__/index.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ApolloServerPluginSchemaReporting, 3 | ApolloServerPluginSchemaReportingOptions, 4 | } from '..'; 5 | import pluginTestHarness from 'apollo-server-core/dist/utils/pluginTestHarness'; 6 | import { makeExecutableSchema } from 'graphql-tools'; 7 | import { graphql } from 'graphql'; 8 | 9 | describe('end-to-end', () => { 10 | async function runTest({ 11 | pluginOptions = {}, 12 | }: { 13 | pluginOptions?: ApolloServerPluginSchemaReportingOptions; 14 | }) { 15 | return await pluginTestHarness({ 16 | pluginInstance: ApolloServerPluginSchemaReporting(pluginOptions), 17 | graphqlRequest: { 18 | query: 'query { __typename }', 19 | }, 20 | executor: async ({ request: { query }, context }) => { 21 | return await graphql({ 22 | schema: makeExecutableSchema({ typeDefs: 'type Query { foo: Int }' }), 23 | source: query, 24 | // context is needed for schema instrumentation to find plugins. 25 | contextValue: context, 26 | }); 27 | }, 28 | }); 29 | } 30 | 31 | it('fails for unparsable overrideReportedSchema', async () => { 32 | await expect( 33 | runTest({ 34 | pluginOptions: { 35 | overrideReportedSchema: 'type Query {', 36 | }, 37 | }), 38 | ).rejects.toThrowErrorMatchingInlineSnapshot( 39 | `"The schema provided to overrideReportedSchema failed to parse or validate: Syntax Error: Expected Name, found "`, 40 | ); 41 | }); 42 | 43 | it('fails for invalid overrideReportedSchema', async () => { 44 | await expect( 45 | runTest({ 46 | pluginOptions: { 47 | overrideReportedSchema: 'type Query', 48 | }, 49 | }), 50 | ).rejects.toThrowErrorMatchingInlineSnapshot( 51 | `"The schema provided to overrideReportedSchema failed to parse or validate: Type Query must define one or more fields."`, 52 | ); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /packages/apollo-server-cloudflare/src/cloudflareApollo.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLOptions, 3 | HttpQueryError, 4 | runHttpQuery, 5 | } from 'apollo-server-core'; 6 | 7 | import { Request, Response, URL } from 'apollo-server-env'; 8 | import { ValueOrPromise } from 'apollo-server-types'; 9 | 10 | // Design principles: 11 | // - You can issue a GET or POST with your query. 12 | // - simple, fast and secure 13 | // 14 | 15 | export interface CloudflareOptionsFunction { 16 | (req?: Request): ValueOrPromise; 17 | } 18 | 19 | export function graphqlCloudflare( 20 | options: GraphQLOptions | CloudflareOptionsFunction, 21 | ) { 22 | if (!options) { 23 | throw new Error('Apollo Server requires options.'); 24 | } 25 | 26 | if (arguments.length > 1) { 27 | throw new Error( 28 | `Apollo Server expects exactly one argument, got ${arguments.length}`, 29 | ); 30 | } 31 | 32 | const graphqlHandler = async (req: Request): Promise => { 33 | const url = new URL(req.url); 34 | const query = 35 | req.method === 'POST' 36 | ? await req.json() 37 | : { 38 | query: url.searchParams.get('query'), 39 | variables: url.searchParams.get('variables'), 40 | operationName: url.searchParams.get('operationName'), 41 | extensions: url.searchParams.get('extensions'), 42 | }; 43 | 44 | return runHttpQuery([req], { 45 | method: req.method, 46 | options: options, 47 | query, 48 | request: req as Request, 49 | }).then( 50 | ({ graphqlResponse, responseInit }) => 51 | new Response(graphqlResponse, responseInit), 52 | (error: HttpQueryError) => { 53 | if ('HttpQueryError' !== error.name) throw error; 54 | 55 | const res = new Response(error.message, { 56 | status: error.statusCode, 57 | headers: error.headers, 58 | }); 59 | 60 | return res; 61 | }, 62 | ); 63 | }; 64 | 65 | return graphqlHandler; 66 | } 67 | -------------------------------------------------------------------------------- /packages/apollo-server-fastify/src/fastifyApollo.ts: -------------------------------------------------------------------------------- 1 | import { 2 | convertNodeHttpToRequest, 3 | GraphQLOptions, 4 | runHttpQuery, 5 | } from 'apollo-server-core'; 6 | import { FastifyReply, FastifyRequest, RequestHandler } from 'fastify'; 7 | import { IncomingMessage, OutgoingMessage } from 'http'; 8 | import { ValueOrPromise } from 'apollo-server-types'; 9 | 10 | export async function graphqlFastify( 11 | options: ( 12 | req?: FastifyRequest, 13 | res?: FastifyReply, 14 | ) => ValueOrPromise, 15 | ): Promise> { 16 | if (!options) { 17 | throw new Error('Apollo Server requires options.'); 18 | } 19 | 20 | return async ( 21 | request: FastifyRequest, 22 | reply: FastifyReply, 23 | ) => { 24 | try { 25 | const { graphqlResponse, responseInit } = await runHttpQuery( 26 | [request, reply], 27 | { 28 | method: request.req.method as string, 29 | options, 30 | query: request.req.method === 'POST' ? request.body : request.query, 31 | request: convertNodeHttpToRequest(request.raw), 32 | }, 33 | ); 34 | 35 | if (responseInit.headers) { 36 | for (const [name, value] of Object.entries( 37 | responseInit.headers, 38 | )) { 39 | reply.header(name, value); 40 | } 41 | } 42 | reply.serializer((payload: string) => payload); 43 | reply.send(graphqlResponse); 44 | } catch (error) { 45 | if ('HttpQueryError' !== error.name) { 46 | throw error; 47 | } 48 | 49 | if (error.headers) { 50 | Object.keys(error.headers).forEach(header => { 51 | reply.header(header, error.headers[header]); 52 | }); 53 | } 54 | 55 | reply.code(error.statusCode); 56 | reply.serializer((payload: string) => payload); 57 | reply.send(error.message); 58 | } 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /docs/source/security/terminating-ssl.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Terminating SSL 3 | --- 4 | 5 | Most production environments include a load balancer or HTTP proxy (such as nginx) 6 | that performs SSL termination on behalf of web applications that it serves. 7 | 8 | If you are using Apollo Server in an application that must perform its _own_ SSL 9 | termination, you can use the `https` module with the `apollo-server-express` [middleware 10 | library](/integrations/middleware/). 11 | 12 | Here's an example that uses HTTPS in production and HTTP in development: 13 | 14 | ```javascript 15 | import express from 'express' 16 | import { ApolloServer } from 'apollo-server-express' 17 | import typeDefs from './graphql/schema' 18 | import resolvers from './graphql/resolvers' 19 | import fs from 'fs' 20 | import https from 'https' 21 | import http from 'http' 22 | 23 | const configurations = { 24 | // Note: You may need sudo to run on port 443 25 | production: { ssl: true, port: 443, hostname: 'example.com' }, 26 | development: { ssl: false, port: 4000, hostname: 'localhost' } 27 | } 28 | 29 | const environment = process.env.NODE_ENV || 'production' 30 | const config = configurations[environment] 31 | 32 | const apollo = new ApolloServer({ typeDefs, resolvers }) 33 | 34 | const app = express() 35 | apollo.applyMiddleware({ app }) 36 | 37 | // Create the HTTPS or HTTP server, per configuration 38 | var server 39 | if (config.ssl) { 40 | // Assumes certificates are in a .ssl folder off of the package root. Make sure 41 | // these files are secured. 42 | server = https.createServer( 43 | { 44 | key: fs.readFileSync(`./ssl/${environment}/server.key`), 45 | cert: fs.readFileSync(`./ssl/${environment}/server.crt`) 46 | }, 47 | app 48 | ) 49 | } else { 50 | server = http.createServer(app) 51 | } 52 | 53 | server.listen({ port: config.port }, () => 54 | console.log( 55 | '🚀 Server ready at', 56 | `http${config.ssl ? 's' : ''}://${config.hostname}:${config.port}${apollo.graphqlPath}` 57 | ) 58 | ) 59 | ``` 60 | -------------------------------------------------------------------------------- /packages/apollo-server-plugin-operation-registry/src/common.ts: -------------------------------------------------------------------------------- 1 | export const pluginName: string = require('../package.json').name; 2 | 3 | export const envOverrideOperationManifest = 4 | 'APOLLO_OPERATION_MANIFEST_BASE_URL'; 5 | 6 | export const envOverrideStorageSecretBaseUrl = 'APOLLO_STORAGE_SECRET_BASE_URL'; 7 | 8 | export const fakeTestBaseUrl = 'https://fake-host-for-apollo-op-reg-tests'; 9 | 10 | // Generate and cache our desired operation manifest URL. 11 | export const urlOperationManifestBase: string = 12 | // Remove trailing slash if any. 13 | process.env[envOverrideOperationManifest]?.replace(/\/$/, '') || 14 | // See src/__tests__/jestSetup.ts for more details on this env. variable. 15 | process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] === 'true' 16 | ? fakeTestBaseUrl 17 | : 'https://operations.api.apollographql.com'; 18 | 19 | // Generate and cache our desired storage secret URL. 20 | export const urlStorageSecretBase: string = 21 | // Remove trailing slash if any. 22 | process.env[envOverrideStorageSecretBaseUrl]?.replace(/\/$/, '') || 23 | // See src/__tests__/jestSetup.ts for more details on this env. variable. 24 | process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] === 'true' 25 | ? fakeTestBaseUrl 26 | : 'https://storage-secrets.api.apollographql.com'; 27 | 28 | export const getStoreKey = (signature: string) => `${signature}`; 29 | 30 | export function getStorageSecretUrl( 31 | graphId: string, 32 | apiKeyHash: string, 33 | ): string { 34 | return `${urlStorageSecretBase}/${graphId}/storage-secret/${apiKeyHash}.json`; 35 | } 36 | 37 | export function getOperationManifestUrl( 38 | graphId: string, 39 | storageSecret: string, 40 | graphVariant: string, 41 | ): string { 42 | return `${urlOperationManifestBase}/${graphId}/${storageSecret}/${graphVariant}/manifest.v2.json`; 43 | } 44 | 45 | export function signatureForLogging(signature: string): string { 46 | if (typeof signature !== 'string') { 47 | return ''; 48 | } 49 | return signature.substring(0, 8); 50 | } 51 | -------------------------------------------------------------------------------- /packages/apollo-server-cloud-functions/src/googleCloudApollo.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLOptions, 3 | HttpQueryError, 4 | runHttpQuery, 5 | } from 'apollo-server-core'; 6 | import { Headers } from 'apollo-server-env'; 7 | import { Request, Response } from 'express'; 8 | import { ValueOrPromise } from 'apollo-server-types'; 9 | 10 | export interface CloudFunctionGraphQLOptionsFunction { 11 | (req?: Request, res?: Response): ValueOrPromise; 12 | } 13 | 14 | export function graphqlCloudFunction( 15 | options: GraphQLOptions | CloudFunctionGraphQLOptionsFunction, 16 | ): any { 17 | if (!options) { 18 | throw new Error('Apollo Server requires options.'); 19 | } 20 | 21 | if (arguments.length > 1) { 22 | throw new Error( 23 | `Apollo Server expects exactly one argument, got ${arguments.length}`, 24 | ); 25 | } 26 | 27 | const graphqlHandler: any = (req: Request, res: Response): void => { 28 | const hasPostBody = req.body && Object.keys(req.body).length > 0; 29 | if (req.method === 'POST' && !hasPostBody) { 30 | res.status(500).send('POST body missing.'); 31 | return; 32 | } 33 | 34 | runHttpQuery([req, res], { 35 | method: req.method, 36 | options: options, 37 | query: hasPostBody ? req.body : (req.query as any), 38 | request: { 39 | url: req.url, 40 | method: req.method, 41 | headers: new Headers(req.headers as any), // ? Check if this actually works 42 | }, 43 | }).then( 44 | ({ graphqlResponse, responseInit }) => { 45 | res 46 | .status(200) 47 | .set(responseInit.headers) 48 | .send(graphqlResponse); 49 | }, 50 | (error: HttpQueryError) => { 51 | if ('HttpQueryError' !== error.name) { 52 | res.status(500).send(error); 53 | return; 54 | } 55 | res 56 | .status(error.statusCode) 57 | .set(error.headers) 58 | .send(error.message); 59 | }, 60 | ); 61 | }; 62 | 63 | return graphqlHandler; 64 | } 65 | -------------------------------------------------------------------------------- /packages/apollo-server-koa/src/koaApollo.ts: -------------------------------------------------------------------------------- 1 | import Koa from 'koa'; 2 | import { 3 | GraphQLOptions, 4 | HttpQueryError, 5 | runHttpQuery, 6 | convertNodeHttpToRequest, 7 | } from 'apollo-server-core'; 8 | import { ValueOrPromise } from 'apollo-server-types'; 9 | 10 | export interface KoaGraphQLOptionsFunction { 11 | (ctx: Koa.Context): ValueOrPromise; 12 | } 13 | 14 | export interface KoaHandler { 15 | (ctx: Koa.Context, next): void; 16 | } 17 | 18 | export function graphqlKoa( 19 | options: GraphQLOptions | KoaGraphQLOptionsFunction, 20 | ): KoaHandler { 21 | if (!options) { 22 | throw new Error('Apollo Server requires options.'); 23 | } 24 | 25 | if (arguments.length > 1) { 26 | // TODO: test this 27 | throw new Error( 28 | `Apollo Server expects exactly one argument, got ${arguments.length}`, 29 | ); 30 | } 31 | 32 | const graphqlHandler = (ctx: Koa.Context): Promise => { 33 | return runHttpQuery([ctx], { 34 | method: ctx.request.method, 35 | options: options, 36 | query: 37 | ctx.request.method === 'POST' 38 | ? // fallback to ctx.req.body for koa-multer support 39 | ctx.request.body || (ctx.req as any).body 40 | : ctx.request.query, 41 | request: convertNodeHttpToRequest(ctx.req), 42 | }).then( 43 | ({ graphqlResponse, responseInit }) => { 44 | Object.keys(responseInit.headers).forEach(key => 45 | ctx.set(key, responseInit.headers[key]), 46 | ); 47 | ctx.body = graphqlResponse; 48 | }, 49 | (error: HttpQueryError) => { 50 | if ('HttpQueryError' !== error.name) { 51 | throw error; 52 | } 53 | 54 | if (error.headers) { 55 | Object.keys(error.headers).forEach(header => { 56 | ctx.set(header, error.headers[header]); 57 | }); 58 | } 59 | 60 | ctx.status = error.statusCode; 61 | ctx.body = error.message; 62 | }, 63 | ); 64 | }; 65 | 66 | return graphqlHandler; 67 | } 68 | --------------------------------------------------------------------------------