Skip to content

Commit

Permalink
Merge branch 'version-2' into defer-support
Browse files Browse the repository at this point in the history
  • Loading branch information
clarencenpy authored Jul 16, 2018
2 parents 6965c25 + 5d7a1eb commit d0cefaa
Show file tree
Hide file tree
Showing 137 changed files with 5,435 additions and 1,782 deletions.
Binary file removed .DS_Store
Binary file not shown.
92 changes: 91 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,100 @@ All of the packages in the `apollo-server` repo are released with the same versi

### vNEXT

* Upgrade `subscription-transport-ws` to 0.9.9 for Graphiql
### rc.7

- enable engine reporting from lambda [#1313](https://github.com/apollographql/apollo-server/pull/1313)
- remove flattening of errors [#1288](https://github.com/apollographql/apollo-server/pull/1288)
- dynamic url in datasourece ([#1277](https://github.com/apollographql/apollo-server/pull/1277))

### rc.6

- BREAKING: errors are passed to user extensions, then engine reporting, and finally `formatError` ([#1272](https://github.com/apollographql/apollo-server/pull/1272))
- `formatError` only called once on validation errors ([#1272](https://github.com/apollographql/apollo-server/pull/1272))
- BREAKING: apollo-server-env does place types in global namespace ([#1259](https://github.com/apollographql/apollo-server/pull/1259))
- export Request from apollo-datasource-rest and graphql-extensions (53d7a75 c525818)
- Use scoped graphql-playground and centralize version (8ea36d8, 84233d2)
- fix dependencies + exports ([#1257](https://github.com/apollographql/apollo-server/pull/1257))
- fix data source + context cloning (7e35305)
- use fetch instead of Node request for engine-reporting ([#1274](https://github.com/apollographql/apollo-server/pull/1274))

### rc.5

- fix formatError to keep prototype of Error ([#1235](https://github.com/apollographql/apollo-server/pull/1235))

### rc.4

- Add trailing slash to data source
- allow body passed to data source
- new apollo-engine-reporting agent

### rc.3

- graphql as peerDependency ([#1232](https://github.com/apollographql/apollo-server/pull/1232))
- APQ in batches ([#1234](https://github.com/apollographql/apollo-server/pull/1234))
- APQ hits/misses in traces

### rc.2

- Missing apollo-upload-server dependency ([#1221](https://github.com/apollographql/apollo-server/pull/1221))
- encode trace report over each request in apollo-engine-reporting

### rc.1

- BREAKING: remove logFunction ([71a403d](https://github.com/apollographql/apollo-server/pull/1125/commits/71a403dfa38ee050606d3fa32630005e0a98016f)), see [this commit](https://github.com/apollographql/apollo-server/blob/8914b135df9840051fe81cc9224b444cfc5b61ab/packages/apollo-server-core/src/logging.ts) for an implementation
- move upload option to constructor ([#1204](https://github.com/apollographql/apollo-server/pull/1204))
- fixed hapi gui bugs ([#1211](https://github.com/apollographql/apollo-server/pull/1211))
- remove requirement for exModuleInterop ([#1210](https://github.com/apollographql/apollo-server/pull/1210))
- change BadUserInputError to UserInputError ([#1208](https://github.com/apollographql/apollo-server/pull/1208))
- add cache-control headers for CDN integration ([#1138](https://github.com/apollographql/apollo-server/pull/1138))
- Lambda support (thanks to @adnsio, @bwlt, and @gragio [#1138](https://github.com/apollographql/apollo-server/pull/1138))

Data sources

- add memcache and redis support ([#1191](https://github.com/apollographql/apollo-server/pull/1191))
- add patch method ([#1190](https://github.com/apollographql/apollo-server/pull/1190))

### rc.0

- Breaking: `registerServer` changed to `server.applyMiddleware` ([3279991](https://github.com/apollographql/apollo-server/pull/1125/commits/327999174cfbcecaa4e401ffd7b2d7148ba0fd65))
- Breaking: subscriptions enabled with `installSubscriptionHandlers`
- Add Data Sources ([#1163](https://github.com/apollographql/apollo-server/pull/1163))

### beta.4

* Bug fix to allow async context ([#1129](https://github.com/apollographql/apollo-server/pull/1129))
* logFunction is now an extension ([#1128](https://github.com/apollographql/apollo-server/pull/1128))
* Allow user defined extensions and include engine reporting ([#1105](https://github.com/apollographql/apollo-server/pull/#105))

### beta.3

* remove registerServer configuration from `apollo-server`'s listen ([#1090](https://github.com/apollographql/apollo-server/pull/1090))
* move healthcheck into variants ([#1086](https://github.com/apollographql/apollo-server/pull/1086))
* Add file uploads, **breaking** requires removing `scalar Upload` from the typeDefs ([#1071](https://github.com/apollographql/apollo-server/pull/1071))
* Add reporting to Engine as apollo-engine-reporting ([#1105](https://github.com/apollographql/apollo-server/pull/1105))
* Allow users to define extensions ([#1105](https://github.com/apollographql/apollo-server/pull/1105))

### beta.2

ListenOptions:
* `engine` -> `engineProxy`
* `port`, `host`, and other http options moved under `http` key ([#1080](https://github.com/apollographql/apollo-server/pull/1080))

* `subscriptions` moved to `server.listen` ([#1059](https://github.com/apollographql/apollo-server/pull/1059))
* Add mocks to server constructor ([#1017](https://github.com/apollographql/apollo-server/pull/1017))
* Add `bodyParserConfig` parameter to `registerServer` in apollo-server ([#1059](https://github.com/apollographql/apollo-server/pull/1059)) [commit](https://github.com/apollographql/apollo-server/pull/1063/commits/d08f862063b60f35d92f903c9ac52702150c10f6)
* Hapi variant ([#1058](https://github.com/apollographql/apollo-server/pull/1058)) ([#1082](https://github.com/apollographql/apollo-server/pull/1082))
* Remove tests and guaranteed support for Node 4 [PR #1024](https://github.com/apollographql/apollo-server/pull/1024)
* Cleanup docs [PR #1233](https://github.com/apollographql/apollo-server/pull/1233/files)

### 1.4.0

* [Issue #626] Integrate apollo-fastify plugin. [PR #1013](https://github.com/apollographql/apollo-server/pull/1013)
* add hapi 16 next() invocation [PR #743](https://github.com/apollographql/apollo-server/pull/743)
* Add skipValidation option [PR #839](https://github.com/apollographql/apollo-server/pull/839)
* `apollo-server-module-graphiql`: adds an option to the constructor to disable url rewriting when editing a query [PR #1047](https://github.com/apollographql/apollo-server/pull/1047)
* Upgrade `subscription-transport-ws` to 0.9.9 for Graphiql

### v1.3.6

* Recognize requests with Apollo Persisted Queries and return `PersistedQueryNotSupported` to the client instead of a confusing error. [PR #982](https://github.com/apollographql/apollo-server/pull/982)
Expand Down
23 changes: 16 additions & 7 deletions __mocks__/apollo-server-env.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/// <reference types="jest" />

import {
fetch,
Request,
RequestInit,
Response,
Body,
BodyInit,
Headers,
HeadersInit,
URL,
URLSearchParams,
} from 'apollo-server-env';

type Headers = { [name: string]: string };
URLSearchParamsInit,
} from '../packages/apollo-server-env';

interface FetchMock extends jest.Mock<typeof fetch> {
mockResponseOnce(data?: any, headers?: Headers, status?: number);
mockJSONResponseOnce(data?: object, headers?: Headers);
mockResponseOnce(data?: any, headers?: HeadersInit, status?: number);
mockJSONResponseOnce(data?: object, headers?: HeadersInit);
}

const mockFetch = jest.fn<typeof fetch>() as FetchMock;
Expand Down Expand Up @@ -42,11 +46,16 @@ mockFetch.mockJSONResponseOnce = (
);
};

export = {
fetch: mockFetch,
export {
mockFetch as fetch,
Request,
RequestInit,
Response,
Body,
BodyInit,
Headers,
HeadersInit,
URL,
URLSearchParams,
URLSearchParamsInit,
};
33 changes: 26 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# Apollo Server docs
# Documentation

Read the docs at [apollographql.com/docs/apollo-server](https://www.apollographql.com/docs/apollo-server/).
This is the documentation **source** for this repository.

To run the docs app locally:
The **deployed** version of the documentation for this repository is available at:

```bash
npm install
npm start
```
* https://www.apollographql.com/docs/apollo-server/

## Documentation for the documentation

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.

## Running locally

For more information, consult the documentation for the documentation, referenced above.

In general though:

* `npm install` in this directory
* `npm start` in this directory
* Open a browser to the link provided in the console.

> **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.
## Deploy previews

Documentation repositories should be setup with a "deploy preview" feature which automatically provides "preview" links in the _status checks_ section of pull-requests.

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.
21 changes: 18 additions & 3 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ sidebar_categories:
Features:
- features/mocking
- features/errors
- features/apq
- features/data-sources
- features/cdn
- features/subscriptions
- features/file-uploads
- features/metrics
- features/graphql-playground
- features/scalars-enums
- features/unions-interfaces
- features/directives
Expand All @@ -38,6 +36,15 @@ sidebar_categories:
- deployment/heroku
- deployment/lambda
- deployment/now
Related Guides:
- title: Monitoring
href: https://www.apollographql.com/docs/guides/monitoring.html
- title: Versioning
href: https://www.apollographql.com/docs/guides/versioning.html
- title: Access Control
href: https://www.apollographql.com/docs/guides/access-control.html
- title: Security
href: https://www.apollographql.com/docs/guides/security.html
API Reference:
- api/apollo-server
- title: graphql-subscriptions
Expand All @@ -58,5 +65,13 @@ root: /docs/apollo-server/

public_dir: public/docs/apollo-server

redirects:
/docs/apollo-server/v2/features/cdn.html:
docs/guides/performance
/docs/apollo-server/v2/features/apq.html:
docs/guides/performance
/docs/apollo-server/v2/features/file-uploads.html:
docs/guides/file-uploads

versioned-netlify-redirects:
netlify_site_id: apollo-server-docs
7 changes: 4 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"version": "3.7.1"
},
"devDependencies": {
"apollo-hexo-config": "1.0.7",
"apollo-hexo-config": "1.0.8",
"chexo": "1.0.5",
"hexo": "3.7.1",
"hexo-browsersync": "0.3.0",
"hexo-prism-plus": "1.0.0",
"hexo-renderer-ejs": "0.3.1",
"hexo-renderer-less": "0.2.0",
"hexo-renderer-marked": "0.3.2",
"hexo-server": "0.3.2",
"meteor-theme-hexo": "1.0.15"
"meteor-theme-hexo": "1.0.16"
},
"scripts": {
"start": "npm run build && chexo apollo-hexo-config -- server",
Expand All @@ -23,6 +24,6 @@
"test": "npm run clean; npm run build"
},
"dependencies": {
"hexo-versioned-netlify-redirects": "^1.0.7"
"hexo-versioned-netlify-redirects": "1.0.7"
}
}
20 changes: 16 additions & 4 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ new ApolloServer({

Enables and disables schema introspection

* `playground`: <`Boolean`> | <`Object`>

Enables and disables playground and allows configuration of GraphQL Playground. The options can be found on GraphQL Playground's [documentation](https://github.com/prismagraphql/graphql-playground/#usage)

* `debug`: <`Boolean`>

Enables and disables development mode helpers. Defaults to `true`
Expand All @@ -61,13 +65,13 @@ new ApolloServer({

Add tracing or cacheControl meta data to the GraphQL response

* `formatError`, `formatResponse`, `formatParams`: <`Function`>
* `formatError`, `formatResponse`: <`Function`>

Functions to format the errors and response returned from the server, as well as the parameters to graphql execution(`runQuery`)

* `schema`: <`Object`>

An executable GraphQL schema that will override the `typeDefs` and `resolvers` provided
An executable GraphQL schema that will override the `typeDefs` and `resolvers` provided. If you are using [file uploads](https://www.apollographql.com/docs/guides/file-uploads.html), you will have to add the `Upload` scalar to the schema, as it is not automatically added in case of setting the `schema` manually.

* `subscriptions`: <`Object`> | <`String`> | false

Expand All @@ -78,9 +82,17 @@ new ApolloServer({
* `onConnect`: <`Function`>
* `onDisconnect`: <`Function`>

* `engine`: <`EngineReportingOptions`> | boolean _(required)_
* `engine`: <`EngineReportingOptions`> | boolean

Provided the `ENGINE_API_KEY` environment variable is set, the engine reporting agent will be started automatically. The API key can also be provided as the `apiKey` field in an object passed as the `engine` field. See the [EngineReportingOptions](#EngineReportingOptions) section for a full description of how to configure the reporting agent, including how to blacklist variables. When using the Engine proxy, this option should be set to false.

* `persistedQueries`: <`Object`> | false

The persisted queries option can be set to an object containing a `cache` field, which will be used to store the mapping between hash and query string.

* `cors`: <`Object` | `boolean`> ([apollo-server](https://github.com/expressjs/cors#cors))

Provided the `ENGINE_API_KEY` environment variable is set, the engine reporting agent will be started. The API key can also be provided as the `apiKey` field in an object passed as the `engine` field. See the [EngineReportingOptions](#EngineReportingOptions) section for a full description of how to configure the reporting agent, including how to blacklist variables
Pass the integration-specific CORS options. `false` removes the CORS middleware and `true` uses the defaults. This option is only available to `apollo-server`. For other server integrations, place `cors` inside of `applyMiddleware`.

#### Returns

Expand Down
2 changes: 1 addition & 1 deletion docs/source/best-practices/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ If our application has a lot of public data that doesn’t change very frequentl
A CDN will store our API result close to the “edge” of the network — that is, close to the region the user is in — and deliver a cached result much faster than it would have required to do a full round-trip to our actual server. As an added benefit, we get to save on server load since that query doesn’t actually hit our API.

- Setting up CDN caching with Apollo Server is incredibly easy, simply setup Apollo Engine then follow this [guide](https://www.apollographql.com/docs/engine/cdn.html)
- For more information about using a CDN with Apollo Engine, check out this [article](https://dev-blog.apollodata.com/caching-graphql-results-in-your-cdn-54299832b8e2)
- For more information about using a CDN with Apollo Engine, check out this [article](https://blog.apollographql.com/caching-graphql-results-in-your-cdn-54299832b8e2)

2 changes: 1 addition & 1 deletion docs/source/best-practices/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ There are two common techniques to mitigate CDoS risks, and can be enabled toget

We suggest implementing complexity limits using community-provided packages like [graphql-depth-limit](https://github.com/stems/graphql-depth-limit) and [graphql-validation-complexity](https://github.com/4Catalyzer/graphql-validation-complexity).

> For additional information on securing a GraphQL server deployment, check out [Securing your GraphQL API from malicious queries](https://dev-blog.apollodata.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b) by Spectrum co-founder, Max Stoiber.
> For additional information on securing a GraphQL server deployment, check out [Securing your GraphQL API from malicious queries](https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b) by Spectrum co-founder, Max Stoiber.
8 changes: 6 additions & 2 deletions docs/source/deployment/now.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ Deployment to Now for Node.js apps simply requires a `package.json` file to be p
{
"name": "graphqlservice",
"version": "1.0.0",
"scripts": {
"start": "nodemon index.js"
},
"dependencies": {
"apollo-server": "^2.0.0-rc.5",
"graphql": "^0.13.2"
"graphql": "^0.13.2",
"nodemon": "^1.17.5"
}
}
```
Expand Down Expand Up @@ -50,4 +54,4 @@ $ now -e ENGINE_API_KEY=xxxxxxxxx apollographql/graphql-server-example
<div style="text-align:center">
![Deployed GraphQL Server](../images/deployment/zeit/zeit-apollo-server.png)
<br></br>
</div>
</div>
4 changes: 2 additions & 2 deletions docs/source/essentials/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ Every GraphQL query is a tree of function calls in the server. So the `obj` cont
3. `parent` in `Post.title` and `Post.author` will be one item from the `posts` result array.
4. `parent` in `Author.name` is the result from the above `Post.author` call.

Every resolver function is called according to the nesting of the query. To understand this transition from query to resolvers from another perspective, read this [blog post](https://dev-blog.apollodata.com/graphql-explained-5844742f195e#.fq5jjdw7t).
Every resolver function is called according to the nesting of the query. To understand this transition from query to resolvers from another perspective, read this [blog post](https://blog.apollographql.com/graphql-explained-5844742f195e#.fq5jjdw7t).

<h3 id="context">Context argument</h3>

The context is how you access your shared connections and fetchers in resolvers to get data.

The `context` is the third argument passed to every resolver. It is useful for passing things that any resolver may need, like [authentication scope](https://dev-blog.apollodata.com/authorization-in-graphql-452b1c402a9), database connections, and custom fetch functions. Additionally, if you're using [dataloaders to batch requests](../best-practices/performance.html#Batching-data-lookups) across resolvers, you can attach them to the `context` as well.
The `context` is the third argument passed to every resolver. It is useful for passing things that any resolver may need, like [authentication scope](https://blog.apollographql.com/authorization-in-graphql-452b1c402a9), database connections, and custom fetch functions. Additionally, if you're using [dataloaders to batch requests](../best-practices/performance.html#Batching-data-lookups) across resolvers, you can attach them to the `context` as well.

As a best practice, `context` should be the same for all resolvers, no matter the particular query or mutation, and resolvers should never modify it. This ensures consistency across resolvers, and helps increase development velocity.

Expand Down
4 changes: 4 additions & 0 deletions docs/source/essentials/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Existing applications generally already have middleware in place and Apollo Serv

> The existing application is frequently already named `app`, especially when using Express. If the application is identified by a different variable, pass the existing variable in place of `app`.
The following code uses the `apollo-server-express` package, which can be installed with `npm install apollo-server-express@rc`.

```js
const { ApolloServer, gql } = require('apollo-server-express');
const { typeDefs, resolvers } = require('./schema');
Expand All @@ -136,6 +138,8 @@ app.listen({ port: 4000 }, () =>

Hapi follows the same pattern with `apollo-server-express` replaced with `apollo-server-hapi` and `app` replaced with Hapi server. `applyMiddleware` registers plugins, so it should be called with `await`.

> When transition from `apollo-server` to an integration package, running `npm uninstall apollo-server` will remove the extra dependency.
<h3 id="serverless">Serverless</h3>

Apollo Server works great in "serverless" environments such as Amazon Lambda and Microsoft Azure Functions. These implementations have some extra considerations which won't be covered in this guide.
Expand Down
Loading

0 comments on commit d0cefaa

Please sign in to comment.