Skip to content

Commit 3f7f5e3

Browse files
author
Sashko Stubailo
committed
Formatting
1 parent da796bb commit 3f7f5e3

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

docs/source/apollo-server/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: GraphQL server tutorial
33
order: 202
4-
description: These are Apollo Docs!!
4+
description: A step-by-step guide for setting up a basic GraphQL server with Apollo.
55
---
66

77
This guide will explain all the parts required for a simple GraphQL Blog server. If you're looking for a tutorial, check out this Medium post or our GraphQL server tutorial video on Youtube.

docs/source/apollo-server/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Overview
33
order: 201
4-
description: These are Apollo Docs!!
4+
description: How to install the Apollo GraphQL server tools.
55
---
66

77
Apollo GraphQL Tools is a collection of functions and an opinionated guide for how to build a GraphQL server in JavaScript.
@@ -10,4 +10,5 @@ Apollo GraphQL Tools is a collection of functions and an opinionated guide for h
1010
```txt
1111
npm install graphql-tools
1212
```
13+
1314
The Apollo GraphQL tools are not just useful for building servers, they can also be used in the browser, for example to mock a backend during development or testing. Even though our guide recommends a specific way of building GraphQL servers, you can use these tools even if you don't follow our guide; they work with any GraphQL-JS schema, and each tool can be useful on its own. Information on how to use individual tools with GraphQL-JS can be found in the Tools section of this guide.

docs/source/apollo-server/tools.md

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: Documentation for graphql-tools
33
order: 203
4-
description: These are Apollo Docs!!
4+
description: API documentation for the Apollo GraphQL tools.
55
---
66

77
While `apolloServer` can be used as an express middleware, graphql-tools exports all the functions that `apolloServer` uses internally, so they can be used separately with any GraphQL-JS schema. This section documents all the functions that graphql-tools exports, and explains how they can be used.
88

99
## Express middleware
1010

11-
### apolloServer(schema, [...])
11+
<h3 id="apolloServer" title="apolloServer">apolloServer(schema, [...])</h3>
1212

1313
`apolloServer` is a convenient function that generates an express middleware (it uses express-graphql under the hood). It combines all of the tools in graphql-tools and has a simple to use interface:
1414

@@ -20,8 +20,8 @@ var app = express();
2020
app.use('/graphql', apolloServer({ schema: typeDefinitionArray, graphiql: true }));
2121
```
2222

23-
2423
**Function signature**
24+
2525
```
2626
apolloServer({
2727
// options in common with graphqlHTTP from express-graphql
@@ -139,7 +139,8 @@ If execution should not continue, resolve functions should return `null` and not
139139
140140
The graphql-tools package allows you to create a GraphQLSchema instance from GraphQL schema language by using the function `createSchema`.
141141
142-
### createSchema(typeDefinitions)
142+
<h3 id="createSchema" title="createSchema">createSchema(typeDefinitions)</h3>
143+
143144
**Function signature**
144145
```
145146
import { createSchema } from 'graphql-tools';
@@ -212,7 +213,9 @@ This [GraphQL schema language cheat sheet](https://raw.githubusercontent.com/sog
212213
## Resolve functions
213214
In order to respond to queries, a schema needs to have resolve functions. Resolve functions cannot be included in the GraphQL schema language, so they must be added separately.
214215
215-
### addResolveFunctionsToSchema(schema, resolveFunctions)
216+
<h3 id="addResolveFunctionsToSchema" title="addResolveFunctionsToSchema">
217+
addResolveFunctionsToSchema(schema, resolveFunctions)
218+
</h3>
216219
217220
`addResolveFunctionsToSchema` takes two arguments, a GraphQLSchema and an object defining resolve functions, and modifies the schema in place to. The `resolveFunctions` object should have one property for each type that has fields which need a resolve function. The following is an example of a valid resolveFunctions object:
218221
```js
@@ -248,16 +251,23 @@ const resolveFunctions = {
248251
```
249252
Note that if the types were defined in GraphQL schema language, the `info` argument to `resolveType` must be used to get a reference to the actual type, eg. `return info.schema.getType("Person")`. This may be changed in the future to support returning just the name of the type, eg. `return "Person"`.
250253
251-
### addSchemaLevelResolver(schema, rootResolveFunction)
254+
<h3 id="addSchemaLevelResolver" title="addSchemaLevelResolver">
255+
addSchemaLevelResolver(schema, rootResolveFunction)
256+
</h3>
257+
252258
Some operations, such as authentication, need to be done only once per query. Logically, these operations belong in a root resolve function, but unfortunately GraphQL-JS does not let you define one. `addSchemaLevelResolver` solves this by modifying the GraphQLSchema that is passed as the first argument.
253259
254260
## Mocking
255261
256-
### mockServer(schema, mocks = {}, preserveResolvers = false)
262+
<h3 id="mockServer" title="mockServer">
263+
mockServer(schema, mocks = {}, preserveResolvers = false)
264+
</h3>
257265
258266
For more information about how to use the `mockServer` function, see the [Medium Post about mocking](https://medium.com/apollo-stack/mocking-your-server-with-just-one-line-of-code-692feda6e9cd).
259267
260-
### addMocksToSchema(schema, mocks = {}, preserveResolvers = false)
268+
<h3 id="addMocksToSchema" title="addMocksToSchema">
269+
addMocksToSchema(schema, mocks = {}, preserveResolvers = false)
270+
</h3>
261271
262272
`addMocksToSchema` is the function that `mockServer` uses under the hood. Given an instance of GraphQLSchema and a mock object, it modifies the schema in place to return mock data for any valid query that is sent to the server. If `mocks` is not passed, the defaults will be used for each of the scalar types. If `preserveResolvers` is set to `true`, existing resolve functions will not be overwritten to provide mock data. This can be used to mock some parts of the server and not others.
263273
@@ -278,7 +288,10 @@ Connectors are the parts that connect the GraphQL server to various backends, su
278288
279289
Resolve functions act as a sort of switchboard, defining which connector should be used for which GraphQL types, and what arguments should be passed to it. While resolve functions should be stateless, connectors need to be stateful in many cases, for example to store information about the currently logged in user, or manage connections with the backend store. Because the same connector may be used in many resolve function, it has to be attached to the context, where all the resolve functions easily have access to it.
280290
281-
### attachConnectorsToContext(schema, connectors)
291+
<h3 id="attachConnectorsToContext" title="attachConnectorsToContext">
292+
attachConnectorsToContext(schema, connectors)
293+
</h3>
294+
282295
`attachConnectorsToContext` takes two arguments: a GraphQLSchema and a `connectors` object that has connector classes as its named properties. The schema is modified in place such that for each query an instance of each connector will be constructed and attached to the context at the beginning of query execution, effectively making it a singleton that can keep state.
283296
284297
```js
@@ -315,7 +328,10 @@ resolveAuthor(obj, args, context){
315328
## Error handling + error logging
316329
GraphQL servers can be tricky to debug. The following functions can help find error faster in many cases.
317330
318-
### forbidUndefinedInResolve(schema)
331+
<h3 id="forbidUndefinedInResolve" title="forbidUndefinedInResolve">
332+
forbidUndefinedInResolve(schema)
333+
</h3>
334+
319335
ForbidUndefinedInResolve can be used during debugging to find mistakes in resolve functions faster. Usually, resolve functions only return undefined due to programmer error. `forbidUndefinedInResolve` takes a GraphQLSchema as input, and modifies it in place to throw an error when a resolve function returns undefined, telling you exactly which resolver returned undefined.
320336
```js
321337
import { forbidUndefinedInResolve } from 'graphql-tools';
@@ -324,7 +340,10 @@ forbidUndefinedInResolve(schema);
324340
```
325341
326342
327-
### addErrorLoggingToSchema(schema, logger)
343+
<h3 id="addErrorLoggingToSchema" title="addErrorLoggingToSchema">
344+
addErrorLoggingToSchema(schema, logger)
345+
</h3>
346+
328347
This function may be deprecated in the near future. Instead of using addErrorLoggingToSchema, the `formatError` option of `apolloServer` or `graphqlHTTP` should be used, which was recently added in graphql-js v0.5.0
329348
330349
`addErorrLoggingToSchema` takes two arguments: `schema` and `logger`. `schema` must be an instance of `GraphQLSchema`, `logger` must be an Object with a callable property `log`. Every time an error occurs, `logger.log(e)` will be called.

0 commit comments

Comments
 (0)