Merge branch 'docs-overhaul' into abernix/docs/api

This commit is contained in:
Jesse Rosenberger 2018-04-27 16:41:43 +03:00
commit 9625c0a7e2
No known key found for this signature in database
GPG key ID: C0CCCF81AA6C08D8
3 changed files with 37 additions and 2 deletions

View file

@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.7.0"
"version": "3.7.1"
},
"devDependencies": {
"apollo-hexo-config": "1.0.7",

View file

@ -1,4 +1,4 @@
---
title: Apollo Engine
title: `apollo-engine`
description: Combining Apollo Engine and Apollo Server
---

View file

@ -11,3 +11,38 @@ ApolloServer 2.0 is a new effort targeted in making the most powerful and produc
TODO code example
This is just the beginning. We have published a [roadmap]() for all of the features we will be bringing to ApolloServer soon and we would love your help! If you have any interest, you can get involved on [Github]() or by joining the [Apollo Slack]() and going to the #apollo-server channel.
## Errors
Apollo Server provides the ability to add error codes to categorize errors that occur within resolvers. In addition to an error code, Apollo Server 2 passes error stack traces in development mode to enable a smoother getting started experience.
This code snippet shows how the new error could be used. For more information, take a look at [this section]()
```js
const { ApolloError, ForbiddenError, AuthenticationError } = require("apollo-server");
const resolvers = {
Query: {
allTodos: (_, _, context) => {
if (!context.scope) {
throw AuthenticationError("You must be logged in to see all todos");
}
if (context.scope !== "ADMIN") {
throw ForbiddenError("You must be an administrator to see all todos");
}
return context.Todos.getAllTodos();
},
}
Mutation: {
addTodo: (_, args, context) => {
if(!context.Todos.idAvailable(args.id)) {
throw new ApolloError('The id is already taken', 'DUPLICATE_KEY', {field: 'id'});
}
return context.Todos.addTodo(args.id, args.todo);
}
}
};
```