Skip to content

Commit

Permalink
Updates for new docs infra (v2) (#6210)
Browse files Browse the repository at this point in the history
* Prepare v2 server docs for new infra

* Update code fences

* Use a relative link

* Add algolia filters
  • Loading branch information
trevorblades authored Mar 15, 2022
1 parent 41671ec commit 628fbb7
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 118 deletions.
3 changes: 1 addition & 2 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
title: "API Reference: apollo-server"
sidebar_title: apollo-server
api_reference: true
---

This API reference documents the exports from the `apollo-server` package.

## `class ApolloServer`

The core of an Apollo Server implementation. For an example, see [Get started with Apollo Server](/getting-started/).
The core of an Apollo Server implementation. For an example, see [Get started with Apollo Server](../getting-started/).

### Methods

Expand Down
3 changes: 1 addition & 2 deletions docs/source/api/graphql-tools.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "API Reference: graphql-tools"
sidebar_title: graphql-tools
---

The `graphql-tools` library enables the creation and manipulation of GraphQL schema. Apollo Server is able to accept a `schema` that has been enabled by `graphql-tools`. Apollo server directly exports all the function from `graphql-tools`, enabling a migration path for more complicated use cases.
Expand Down Expand Up @@ -63,7 +62,7 @@ const jsSchema = makeExecutableSchema({

- `typeDefs` is a required argument and should be a GraphQL schema language string or array of GraphQL schema language strings or a function that takes no arguments and returns an array of GraphQL schema language strings. The order of the strings in the array is not important, but it must include a schema definition.

- `resolvers` is an optional argument _(empty object by default)_ and should be an object that follows the pattern explained in the [resolvers documentation](/data/resolvers/).
- `resolvers` is an optional argument _(empty object by default)_ and should be an object that follows the pattern explained in the [resolvers documentation](../data/resolvers/).

- `logger` is an optional argument, which can be used to print errors to the server console that are usually swallowed by GraphQL. The `logger` argument should be an object with a `log` function, eg. `const logger = { log: e => console.log(e) }`

Expand Down
1 change: 0 additions & 1 deletion docs/source/api/plugin/inline-trace.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "API Reference: Inline trace plugin"
sidebar_title: Inline trace plugin
api_reference: true
---

Expand Down
1 change: 0 additions & 1 deletion docs/source/api/plugin/schema-reporting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "API Reference: Schema reporting plugin"
sidebar_title: Schema reporting plugin
api_reference: true
---

Expand Down
1 change: 0 additions & 1 deletion docs/source/api/plugin/usage-reporting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "API Reference: Usage reporting plugin"
sidebar_title: Usage reporting plugin
api_reference: true
---

Expand Down
75 changes: 75 additions & 0 deletions docs/source/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"title": "Apollo Server",
"version": "v2",
"algoliaFilters": [
"docset:server",
[
"docset:react",
"docset:federation"
]
],
"sidebar": {
"Introduction": "/",
"Get started": "/getting-started",
"Changelog": "https://github.com/apollographql/apollo-server/blob/main/CHANGELOG.md",
"Apollo Federation": "https://www.apollographql.com/docs/federation/",
"Defining a Schema": {
"Schema basics": "/schema/schema",
"Unions and interfaces": "/schema/unions-interfaces",
"Custom scalars": "/schema/custom-scalars",
"Directives": "/schema/directives",
"Creating directives": "/schema/creating-directives"
},
"Fetching Data": {
"Resolvers": "/data/resolvers",
"Data sources": "/data/data-sources",
"Error handling": "/data/errors",
"File uploads": "/data/file-uploads",
"Subscriptions": "/data/subscriptions"
},
"Testing": {
"Mocking": "/testing/mocking",
"Integration testing": "/testing/testing",
"Apollo Studio Explorer": "https://www.apollographql.com/docs/studio/explorer/",
"GraphQL Playground": "/testing/graphql-playground"
},
"Performance": {
"Caching": "/performance/caching",
"Automatic persisted queries": "/performance/apq"
},
"Security": {
"Auth": "/security/authentication",
"Terminating SSL": "/security/terminating-ssl"
},
"Integrations": {
"Node.js middleware": "/integrations/middleware",
"Plugins": "/integrations/plugins"
},
"Deployment": {
"Heroku": "/deployment/heroku",
"Lambda": "/deployment/lambda",
"Netlify": "/deployment/netlify",
"Azure Functions": "/deployment/azure-functions",
"Google Cloud Functions": "/deployment/gcp-functions"
},
"Monitoring": {
"Metrics and logging": "/monitoring/metrics",
"Health checks": "/monitoring/health-checks"
},
"API Reference": {
"apollo-server": "/api/apollo-server",
"Usage reporting plugin": "/api/plugin/usage-reporting",
"Schema reporting plugin": "/api/plugin/schema-reporting",
"Inline trace plugin": "/api/plugin/inline-trace",
"graphql-tools": "/api/graphql-tools",
"@apollo/federation": "https://www.apollographql.com/docs/federation/api/apollo-federation/",
"@apollo/gateway": "https://www.apollographql.com/docs/federation/api/apollo-gateway/"
},
"Appendices": {
"Proxy configuration": "/proxy-configuration",
"Installing graphql-tools": "/installing-graphql-tools",
"File uploads in Node.js < v8.5.0": "/migration-file-uploads",
"Migrating from the \"engine\" option": "/migration-engine-plugins"
}
}
}
12 changes: 4 additions & 8 deletions docs/source/data/data-sources.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ title: Data sources
description: Manage connections to databases and REST APIs
---

import {
ExpansionPanel,
} from 'gatsby-theme-apollo-docs/src/components/expansion-panel';

**Data sources** are classes that Apollo Server can use to encapsulate fetching data from a particular source, such as a database or a REST API. These classes help handle caching, deduplication, and errors while resolving operations.

Your server can use any number of different data sources. You don't _have_ to use data sources to fetch data, but they're strongly recommended.
Expand Down Expand Up @@ -54,7 +50,7 @@ If none of these implementations applies to your use case, you can create your o

You provide your `DataSource` subclasses to the `ApolloServer` constructor, like so:

```js{4-9}:title=index.js
```js {4-9} title="index.js"
const server = new ApolloServer({
typeDefs,
resolvers,
Expand All @@ -73,7 +69,7 @@ const server = new ApolloServer({

Your resolvers can now access your data sources from the shared `context` object and use them to fetch data:

```js:title=resolvers.js
```js title="resolvers.js"
const resolvers = {
Query: {
movie: async (_, { id }, { dataSources }) => {
Expand Down Expand Up @@ -123,7 +119,7 @@ For the options you can pass to the underlying Memcached client, [see the docume

#### Redis

```js:title=Redis
```js title="Redis"
const { BaseRedisCache } = require('apollo-server-cache-redis');
const Redis = require('ioredis');

Expand Down Expand Up @@ -166,7 +162,7 @@ You then extend the `RESTDataSource` class and implement whatever data-fetching

Here's an example `RESTDataSource` subclass that defines two data-fetching methods, `getMovie` and `getMostViewedMovies`:

```js:title=movies-api.js
```js title="movies-api.js"
const { RESTDataSource } = require('apollo-datasource-rest');

class MoviesAPI extends RESTDataSource {
Expand Down
16 changes: 7 additions & 9 deletions docs/source/data/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ title: Error handling
description: Making errors actionable on the client and server
---

import {ExpansionPanel} from 'gatsby-theme-apollo-docs';

Whenever Apollo Server encounters errors while processing a GraphQL operation, its response to the client includes an `errors` array that contains each error that occurred. Each error in the array has an `extensions` field that provides additional useful information, including an error `code` and (while in development mode) an `exception.stacktrace`.

Here's an example error response caused by misspelling the `__typename` field in a query:
Expand Down Expand Up @@ -176,7 +174,7 @@ For example, this resolver throws a [`UserInputError`](#bad_user_input) if the i

<ExpansionPanel title="Click to expand">

```js{20-25}
```js {20-25}
const {
ApolloServer,
gql,
Expand Down Expand Up @@ -218,7 +216,7 @@ This example builds on the one above by adding the name of the GraphQL argument

<ExpansionPanel title="Click to expand">

```js{22-24}
```js {22-24}
const {
ApolloServer,
gql,
Expand Down Expand Up @@ -256,7 +254,7 @@ This results in a response like the following:

<ExpansionPanel title="Click to expand">

```json{15}
```json {15}
{
"errors": [
{
Expand Down Expand Up @@ -339,7 +337,7 @@ The `ApolloServer` constructor accepts a `formatError` function that is run on e
This example returns a more generic error whenever the original error's message begins with `Database Error: `:

```js{4-12}
```js {4-12}
const server = new ApolloServer({
typeDefs,
resolvers,
Expand Down Expand Up @@ -391,7 +389,7 @@ Your `rewriteError` function is called for each error (a `GraphQLError` or an `A

Let's say our server is `throw`ing an `AuthenticationError` whenever an incorrect password is provided. We can avoid reporting these errors to Apollo Studio by defining `rewriteError`, like so:

```js{7-17}
```js {7-17}
const { ApolloServer, AuthenticationError } = require("apollo-server");
const { ApolloServerPluginUsageReporting } = require("apollo-server-core");
const server = new ApolloServer({
Expand Down Expand Up @@ -421,7 +419,7 @@ When generating an error (e.g., `new ApolloError("Failure!")`), the error's `mes

We can check these properties when determining whether an error should be reported to Apollo Studio using the `rewriteError` function as follows:

```js{7-17}
```js {7-17}
const { ApolloServer } = require("apollo-server");
const { ApolloServerPluginUsageReporting } = require("apollo-server-core");
const server = new ApolloServer({
Expand Down Expand Up @@ -458,7 +456,7 @@ throw new ApolloError("The x-api-key:12345 doesn't have sufficient privileges.")

The `rewriteError` function can ensure that such information is not sent to Apollo Studio and potentially revealed outside its intended scope:

```js{7-13}
```js {7-13}
const { ApolloServer } = require("apollo-server");
const { ApolloServerPluginUsageReporting } = require("apollo-server-core");
const server = new ApolloServer({
Expand Down
12 changes: 4 additions & 8 deletions docs/source/data/resolvers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ title: Resolvers
description: How Apollo Server processes GraphQL operations
---

import {
ExpansionPanel,
} from 'gatsby-theme-apollo-docs/src/components/expansion-panel';

Apollo Server needs to know how to populate data for every field in your schema so that it can respond to requests for that data. To accomplish this, it uses resolvers.

**A resolver is a function that's responsible for populating the data for a single field in your schema.** It can populate that data in any way you define, such as by fetching data from a back-end database or a third-party API.
Expand Down Expand Up @@ -324,7 +320,7 @@ server.listen().then(({ url }) => {

If we now update our query to also ask for each book's `title`:

```graphql{4}
```graphql {4}
query GetBooksByLibrary {
libraries {
books {
Expand Down Expand Up @@ -357,14 +353,14 @@ Resolver functions are passed four arguments: `parent`, `args`, `context`, and `
| Argument | Description |
|---|---|
| `parent` | <p>The return value of the resolver for this field's parent (i.e., the previous resolver in the [resolver chain](#resolver-chains)).</p><p>For resolvers of top-level fields with no parent (such as fields of `Query`), this value is obtained from the `rootValue` function passed to [Apollo Server's constructor](/api/apollo-server/#constructor).</p> |
| `parent` | <p>The return value of the resolver for this field's parent (i.e., the previous resolver in the [resolver chain](#resolver-chains)).</p><p>For resolvers of top-level fields with no parent (such as fields of `Query`), this value is obtained from the `rootValue` function passed to [Apollo Server's constructor](../api/apollo-server/#constructor).</p> |
| `args` | <p>An object that contains all GraphQL arguments provided for this field.</p><p> For example, when executing `query{ user(id: "4") }`, the `args` object passed to the `user` resolver is `{ "id": "4" }`.</p> |
| `context` | <p>An object shared across all resolvers that are executing for a particular operation. Use this to share per-operation state, including authentication information, dataloader instances, and anything else to track across resolvers. </p><p>See [The `context` argument](#the-context-argument) for more information.</p> |
| `info` | <p>Contains information about the operation's execution state, including the field name, the path to the field from the root, and more. </p><p>Its core fields are listed in the [GraphQL.js source code](https://github.com/graphql/graphql-js/blob/main/src/type/definition.ts#L965-L976), and it is extended with additional functionality by other modules, like [`apollo-cache-control`](https://github.com/apollographql/apollo-server/tree/570f548b887/packages/apollo-cache-control).</p> |

### The `context` argument

The `context` argument is useful for passing things that any resolver might need, like [authentication scope](https://blog.apollographql.com/authorization-in-graphql-452b1c402a9), database connections, and custom fetch functions. If you're using [dataloaders to batch requests](/data/data-sources/#using-with-dataloader) across resolvers, you can attach them to the `context` as well.
The `context` argument is useful for passing things that any resolver might need, like [authentication scope](https://blog.apollographql.com/authorization-in-graphql-452b1c402a9), database connections, and custom fetch functions. If you're using [dataloaders to batch requests](./data-sources/#using-with-dataloader) across resolvers, you can attach them to the `context` as well.

**Resolvers should never destructively modify the `context` argument.** This ensures consistency across all resolvers and prevents unexpected errors.

Expand All @@ -388,7 +384,7 @@ const server = new ApolloServer({
}
```

> The fields of the object passed to your `context` function differ if you're using middleware besides Express. [See the API reference for details.](/api/apollo-server/#middleware-specific-context-fields)
> The fields of the object passed to your `context` function differ if you're using middleware besides Express. [See the API reference for details.](../api/apollo-server/#middleware-specific-context-fields)
Context initialization can be asynchronous, allowing database connections and other operations to complete:

Expand Down
10 changes: 4 additions & 6 deletions docs/source/data/subscriptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ title: Subscriptions
description: Persistent GraphQL read operations
---

import {ExpansionPanel} from 'gatsby-theme-apollo-docs';

> **Subscriptions are not currently supported in [Apollo Federation](https://www.apollographql.com/docs/federation/).**
**Subscriptions** are long-lasting GraphQL read operations that can update their result whenever a particular server-side event occurs. Most commonly, updated results are _pushed_ from the server to subscribing clients. For example, a chat application's server might use a subscription to push newly received messages to all clients in a particular chat room.
Expand Down Expand Up @@ -59,7 +57,7 @@ const server = new ApolloServer({

Resolvers for `Subscription` fields differ from resolvers for fields of other types. Specifically, `Subscription` field resolvers are _objects_ that define a `subscribe` function:

```js:title=index.js
```js title="index.js"
const resolvers = {
Subscription: {
postCreated: {
Expand Down Expand Up @@ -118,7 +116,7 @@ type Mutation {

A basic resolver for `createPost` might look like this:

```js{3-6}
```js {3-6}
const resolvers = {
Mutation: {
createPost(parent, args, context) {
Expand Down Expand Up @@ -158,7 +156,7 @@ You pass this method an array containing the names of all event labels that the

Every `Subscription` field resolver's `subscribe` function must return an `AsyncIterator` object. This brings us back to the code sample at the top of [Resolving a subscription](#resolving-a-subscription):

```js:title=index.js
```js title="index.js"
const resolvers = {
Subscription: {
postCreated: {
Expand Down Expand Up @@ -194,7 +192,7 @@ To fix this, we can use the `withFilter` helper function to control updates on a

Here's an example resolver for `commentAdded` that uses the `withFilter` function:

```js{5-12}
```js {5-12}
const { withFilter } = require('apollo-server');

const resolvers = {
Expand Down
1 change: 0 additions & 1 deletion docs/source/deployment/azure-functions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Deploying with Azure Functions
sidebar_title: Azure Functions
description: Deploying your GraphQL server to Azure Functions
---
This is the Azure Functions integration for the Apollo community GraphQL Server. [Read Docs](https://www.npmjs.com/package/apollo-server-azure-functions)
Expand Down
13 changes: 4 additions & 9 deletions docs/source/deployment/gcp-functions.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
---
title: Deploying with Google Cloud Functions
sidebar_title: Google Cloud Functions
---

import {
ExpansionPanel,
} from 'gatsby-theme-apollo-docs/src/components/expansion-panel';

This tutorial helps you deploy Apollo Server to Google Cloud Functions. It uses the following example function handler:

<ExpansionPanel title="Click to expand">

```javascript:title=index.js
```javascript title="index.js"
const { ApolloServer, gql } = require('apollo-server-cloud-functions');

// Construct a schema, using GraphQL schema language
Expand All @@ -30,7 +25,7 @@ const resolvers = {

/*
Because `NODE_ENV` is a reserved environment variable in Google Cloud Functions
and it defaults to "production", you need to set both the `playground` and
and it defaults to "production", you need to set both the `playground` and
`introspection` options to `true` for GraphQL Playground to work correctly.
*/
const server = new ApolloServer({
Expand Down Expand Up @@ -66,7 +61,7 @@ Paste the example code at the top of this page into the contents of `index.js` i

Edit `package.json` so that it lists `apollo-server-cloud-functions` and `graphql` in its dependencies:

```json:title=package.json
```json title="package.json"
"dependencies": {
"apollo-server-cloud-functions": "^2.24.0",
"graphql": "^15.5.0"
Expand Down Expand Up @@ -184,7 +179,7 @@ exports.handler = server.createHandler();

To enable CORS, you need to modify your HTTP response headers. To do so, use the `cors` option:

```javascript{23-26}
```javascript {23-26}
const { ApolloServer, gql } = require('apollo-server-cloud-functions');

// Construct a schema, using GraphQL schema language
Expand Down
1 change: 0 additions & 1 deletion docs/source/deployment/heroku.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Deploying with Heroku
sidebar_title: Heroku
description: Deploying your GraphQL server to Heroku
---

Expand Down
Loading

0 comments on commit 628fbb7

Please sign in to comment.