Skip to content

Commit

Permalink
Merge branch 'version-2' into server-2.0/apq
Browse files Browse the repository at this point in the history
  • Loading branch information
evans committed Jun 11, 2018
2 parents 8cba571 + 1af0577 commit 3ef3e47
Show file tree
Hide file tree
Showing 51 changed files with 243 additions and 200 deletions.
23 changes: 5 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
version: 2

#
# Reusable Snippets!
#
# These are re-used by the various tests below, to avoid repetition.
#
run_install_desired_npm: &run_install_desired_npm
run:
# Due to a bug, npm upgrades from the version of npm that ships with
# Node.js 6 (npm v3.10.10) go poorly and generally causes other problems
# with the environment. Since yarn is already available here we can just
# use that to work-around the issue. It's possible that npm cleanup might
# prevent this from being necessary, but this can be removed once Node 6 is
# no longer being built below.
name: Install npm@5, but with yarn.
command: sudo yarn global add npm@5
name: Install npm@6
command: sudo npm install -g npm@6

# These are the steps used for each version of Node which we're testing
# against. Thanks to YAMLs inability to merge arrays (though it is able
Expand All @@ -36,16 +29,12 @@ jobs:
# Platform tests, each with the same tests but different platform or version.
# The docker tag represents the Node.js version and the full list is available
# at https://hub.docker.com/r/circleci/node/.
Node.js 6:
docker: [ { image: 'circleci/node:6' } ]
<<: *common_test_steps

Node.js 8:
docker: [ { image: 'circleci/node:8' } ]
<<: *common_test_steps

Node.js 9:
docker: [ { image: 'circleci/node:9' } ]
Node.js 10:
docker: [ { image: 'circleci/node:10' } ]
<<: *common_test_steps

# Other tests, unrelated to typical code tests.
Expand Down Expand Up @@ -75,11 +64,9 @@ workflows:
version: 2
Build and Test:
jobs:
- Node.js 6:
<<: *ignore_doc_branches
- Node.js 8:
<<: *ignore_doc_branches
- Node.js 9:
- Node.js 10:
<<: *ignore_doc_branches
- Linting:
<<: *ignore_doc_branches
Expand Down
43 changes: 28 additions & 15 deletions docs/source/features/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ title: Error handling
description: Making errors actionable on the client and server
---

Apollo server provides a couple predefined errors, including `AuthenticationError`, `ForbiddenError`, and a generic `ApolloError`. These errors are designed to enhance errors thrown before and during GraphQL execution. The provided errors focus on debugging a Apollo server as well as enabling the client to take specific action based on an error.
Apollo server provides a couple predefined errors, including
`AuthenticationError`, `ForbiddenError`, `BadUserInputError` and a generic
`ApolloError`. These errors are designed to enhance errors thrown before and during GraphQL execution. The provided errors focus on debugging a Apollo server as well as enabling the client to take specific action based on an error.

When an error occurs in Apollo server both inside and outside of resolvers, each error inside of the `errors` array will contain an object at `extensions` that contains the information added by Apollo server.

Expand All @@ -12,9 +14,9 @@ When an error occurs in Apollo server both inside and outside of resolvers, each
The first step to improving the usability of a server is providing the error stack trace by default. The following example demonstrates the response returned from Apollo server with a resolver that throws a node [`SystemError`](https://nodejs.org/api/errors.html#errors_system_errors).

```js line=14-16
const {
ApolloServer,
gql,
const {
ApolloServer,
gql,
} = require('apollo-server');

const typeDefs = gql`
Expand Down Expand Up @@ -43,10 +45,10 @@ The response will return:
In addition to stacktraces, Apollo Server's exported errors specify a human-readable string in the `code` field of `extensions` that enables the client to perform corrective actions. In addition to improving the client experience, the `code` field allows the server to categorize errors. For example, an `AuthenticationError` sets the code to `UNAUTHENTICATED`, which enables the client to reauthenticate and would generally be ignored as a server anomaly.

```js line=4,15-17
const {
ApolloServer,
gql,
AuthenticationError,
const {
ApolloServer,
gql,
AuthenticationError,
} = require('apollo-server');

const typeDefs = gql`
Expand All @@ -70,12 +72,15 @@ The response will return:

## Augmenting error details

`ApolloError` can be augmented with additional information when the default information requires more context. This information could include a localized message that should be displayed to the user on an error or in the case of bad input a description of the fields that are invalid. The following example demonstrates adding extra information to a user input check.
When clients provide bad input, you may want to return additional information
like a localized message for each field or argument that was invalid. The
following example demonstrates how you can use `BadUserInputError` to augment
your error messages with additional details.

```js line=14-20
const {
```js line=15-21
const {
ApolloServer,
ApolloError,
BadUserInputError,
gql,
} = require('apollo-server');

Expand All @@ -88,8 +93,8 @@ const typeDefs = gql`
const resolvers = {
Mutation: {
userInputError: (parent, args, context, info) => {
if(args.input !== 'expected') {
throw ApolloError('Form Arguments invalid', 'BAD_USER_INPUT', {
if (args.input !== 'expected') {
throw BadUserInputError('Form Arguments invalid', {
invalidArgs: Object.keys(args),
});
}
Expand All @@ -102,12 +107,20 @@ The response will return:

![Screenshot demonstrating augmented error](../images/features/error-user-input.png)

## Other errors

If you need to define other error codes that are specific to your
application, you can use the base `ApolloError` class.

```js
new ApolloError(message, code, additionalProperties);
```

## Masking and logging errors

The Apollo server constructor accepts a `formatError` function that is run on each error passed back to the client. This can be used to mask errors as well as logging.
This example demonstrates masking


```js line=4-7
const server = new ApolloServer({
typeDefs,
Expand Down
20 changes: 10 additions & 10 deletions docs/source/features/scalars-enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ $ npm install --save graphql-type-json
In code, require the type defined by in the npm package and use it :

```js
import { ApolloServer, gql } from 'apollo-server';
import GraphQLJSON from 'graphql-type-json';
const { ApolloServer, gql } = require('apollo-server');
const GraphQLJSON = require('graphql-type-json');

const schemaString = gql`
Expand Down Expand Up @@ -67,8 +67,8 @@ Remark : `GraphQLJSON` is a [`GraphQLScalarType`](http://graphql.org/graphql-js/
Defining a [GraphQLScalarType](http://graphql.org/graphql-js/type/#graphqlscalartype) instance provides more control over the custom scalar and can be added to Apollo server in the following way:

```js
import { ApolloServer, gql } from 'apollo-server';
import { GraphQLScalarType, Kind } from 'graphql';
const { ApolloServer, gql } = require('apollo-server');
const { GraphQLScalarType, Kind } = require('graphql');

const myCustomScalarType = new GraphQLScalarType({
name: 'MyCustomScalar',
Expand Down Expand Up @@ -138,8 +138,8 @@ type MyType {
Next, the resolver:

```js
import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';
const { GraphQLScalarType } = require('graphql');
const { Kind } = require('graphql/language');

const resolvers = {
Date: new GraphQLScalarType({
Expand Down Expand Up @@ -183,9 +183,9 @@ type MyType {
Next, the resolver:

```js
import { ApolloServer, gql } from 'apollo-server';
import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';
const { ApolloServer, gql } = require('apollo-server');
const { GraphQLScalarType } = require('graphql');
const { Kind } = require('graphql/language');

function oddValue(value) {
return value % 2 === 1 ? value : null;
Expand Down Expand Up @@ -261,7 +261,7 @@ query MyAvatar($color: AllowedColor) {
Putting it all together:

```js
import { ApolloServer, gql } from 'apollo-server';
const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
enum AllowedColor {
Expand Down
18 changes: 9 additions & 9 deletions docs/source/migration-two-dot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ While it's possible to migrate an existing server to the 2.0 beta without any ch

> **Note:** In the beta of Apollo Server 2.0 only Express and Hapi are supported. Additional middleware integrations will be implemented in the official 2.0 release.
### The `gql` tag
<h2 id="gql-tag">The `gql` tag</h2>

Apollo Server 2.0 ships with the `gql` tag for **editor syntax highlighting** and **auto-formatting** with Prettier. In the future, we will be using it for statically analyzing GraphQL queries, so Apollo Servers requires wrapping your schema with `gql`.

Expand All @@ -31,7 +31,7 @@ const typeDefs = gql`${IMPORT_FUNCTION('./schema-file')}`;
const typeDefs = gql(IMPORT_FUNCTION('./schema-file'))
```

### Changes to app dependencies
<h2 id="app-deps">Changes to app dependencies</h2>

> Apollo Server 2.0 beta requires Node.js v6 and higher.
Expand All @@ -42,7 +42,7 @@ There is a consideration to be made when following the rest of the guide:
* [**Middleware option**](#Middleware): If the application being migrated implements Apollo Server alongside other middleware, there are some packages which can be removed, but adding the `apollo-server` package and switching to using the new `registerServer` API should still simplify the setup. In this case, check the [Middleware](#Middleware) section.
* [**Stand-alone option**](#Stand-alone): If the application being migrated is only used as a GraphQL server, Apollo Server 2.0 _eliminates the need to run a separate HTTP server_ and allows some dependencies to be removed. In these cases, the [Stand-alone](#Stand-alone) option will reduce the amount of code necessary for running a GraphQL server.

### Simplified usage
<h2 id="simple-use">Simplified usage</h2>

Check out the following changes for Apollo Server 2.0 beta.

Expand All @@ -52,15 +52,15 @@ Check out the following changes for Apollo Server 2.0 beta.
* You should pass in `typeDefs` and resolvers as parameters to an instance of Apollo Server.
* If the server is only functioning as a GraphQL server, it's no longer necessary to run your own HTTP server (like `express`).

### Middleware
<h2 id="Middleware">Middleware</h2>

With the middleware option used by Apollo Server 1.0 users, it is necessary to install the beta version of `apollo-server-express` and also add the new `apollo-server` beta. To do this, use the `beta` tag when installing:

npm install --save apollo-server-express@beta apollo-server@beta

The changes are best shown by comparing the before and after of the application.

#### Apollo Server 1 (old pattern)
<h3 id="apollo-server-1">Apollo Server 1 (old pattern)</h3>

An example of using Apollo Server 1 with the Express framework:

Expand Down Expand Up @@ -97,7 +97,7 @@ app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: myGraphQLSchema
app.listen(PORT);
```

#### Apollo Server 2 (new pattern)
<h3 id="apollo-server-2">Apollo Server 2 (new pattern)</h3>

Now, you can just do this instead:

Expand Down Expand Up @@ -129,7 +129,7 @@ server.listen().then(({ url }) => {
});
```

### Stand-alone
<h2 id="Stand-alone">Stand-alone</h2>

If you are simply focused on running a production-ready GraphQL server quickly, Apollo Server 2.0 ships with a built-in server and starting your own server (e.g. Express, Koa, etc.) is no longer necessary.

Expand Down Expand Up @@ -166,7 +166,7 @@ server.listen().then(({ url }) => {
});
```

### Adding Additional Middleware to Apollo Server 2
<h2 id="add-middleware">Adding Additional Middleware to Apollo Server 2</h2>

For middleware that is collocated with the GraphQL endpoint, Apollo Server 2 allows middleware mounted on the same path before `registerServer` is called. For example, this server runs an authentication middleware before GraphQL execution.

Expand All @@ -191,7 +191,7 @@ server.listen().then(({ url }) => {
});
```

### Using an Existing Schema
<h2 id="existing-schema">Using an Existing Schema</h2>

For many existing instances of Apollo Server, the schema is created at runtime before server startup, using `makeExecutableSchema` or `mergeSchemas`. Apollo Server 2 stays backwards compatible with these more complex schemas, accepting it as the `schema` field in the server constructor options. Additionally, Apollo Server 2 exports all of `graphql-tools`, so `makeExecutableSchema` and other functions can be imported directly from Apollo Server.

Expand Down
6 changes: 4 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.0.0",
"version": "1.3.6",
"version": "2.0.0-beta.5",
"changelog": {
"repo": "apollographql/apollo-server",
"labels": {
Expand All @@ -13,5 +13,7 @@
}
},
"hoist": true,
"packages": ["packages/*"]
"packages": [
"packages/*"
]
}
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@
"git add"
]
},
"engines": {
"node": ">=8"
},
"devDependencies": {
"@types/chai": "4.1.3",
"@types/graphql": "^0.13.1",
"@types/mocha": "5.2.0",
"@types/sinon": "4.3.3",
"@types/mocha": "5.2.1",
"@types/node": "^10.3.2",
"@types/sinon": "5.0.1",
"chai": "4.1.2",
"graphql": "0.13.2",
"husky": "0.14.3",
"istanbul": "1.1.0-alpha.1",
"lerna": "2.11.0",
"lint-staged": "6.1.1",
"mocha": "5.1.1",
"prettier": "1.12.1",
"lint-staged": "7.2.0",
"mocha": "5.2.0",
"prettier": "1.13.5",
"prettier-check": "2.0.0",
"remap-istanbul": "0.11.1",
"sinon": "5.0.7",
"supertest": "3.0.0",
"supertest-as-promised": "4.0.2",
"typescript": "2.8.3"
"sinon": "6.0.0",
"supertest": "3.1.0",
"typescript": "2.9.1"
}
}
10 changes: 6 additions & 4 deletions packages/apollo-server-adonis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-adonis",
"version": "1.3.6",
"version": "2.0.0-beta.5",
"description": "Production-ready Node.js GraphQL server for Adonis Framework",
"main": "dist/index.js",
"scripts": {
Expand All @@ -24,17 +24,19 @@
"url": "https://github.com/apollographql/apollo-server/issues"
},
"homepage": "https://github.com/apollographql/apollo-server#readme",
"engines": {
"node": ">=8"
},
"dependencies": {
"apollo-server-core": "2.0.0-beta.3",
"apollo-server-core": "^2.0.0-beta.5",
"apollo-server-module-graphiql": "^1.3.4"
},
"devDependencies": {
"@adonisjs/bodyparser": "2.0.3",
"@adonisjs/fold": "4.0.8",
"@adonisjs/framework": "4.0.31",
"@adonisjs/sink": "1.0.16",
"@types/node": "^10.1.2",
"apollo-server-integration-testsuite": "^1.3.6"
"apollo-server-integration-testsuite": "^2.0.0-beta.5"
},
"typings": "dist/index.d.ts",
"typescript": {
Expand Down
10 changes: 6 additions & 4 deletions packages/apollo-server-azure-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-azure-functions",
"version": "1.3.6",
"version": "2.0.0-beta.5",
"description": "Node.js GraphQl server for Azure Functions",
"main": "dist/index.js",
"scripts": {
Expand All @@ -24,13 +24,15 @@
"url": "https://github.com/apollographql/apollo-server/issues"
},
"homepage": "https://github.com/apollographql/apollo-server#readme",
"engines": {
"node": ">=8"
},
"dependencies": {
"apollo-server-core": "2.0.0-beta.3",
"apollo-server-core": "^2.0.0-beta.5",
"apollo-server-module-graphiql": "^1.3.4"
},
"devDependencies": {
"@types/node": "^10.1.2",
"apollo-server-integration-testsuite": "^1.3.6",
"apollo-server-integration-testsuite": "^2.0.0-beta.5",
"azure-functions-typescript": "0.0.1"
},
"typings": "dist/index.d.ts",
Expand Down
Loading

0 comments on commit 3ef3e47

Please sign in to comment.