mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
Merge branch 'docs-overhaul' into abernix/docs/api
This commit is contained in:
commit
9625c0a7e2
3 changed files with 37 additions and 2 deletions
|
@ -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",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
---
|
||||
title: Apollo Engine
|
||||
title: `apollo-engine`
|
||||
description: Combining Apollo Engine and Apollo Server
|
||||
---
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue