Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: apollographql/apollo-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: apollo-server@2.25.1
Choose a base ref
...
head repository: apollographql/apollo-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: apollo-server@2.25.2
Choose a head ref

Commits on May 6, 2021

  1. Copy the full SHA
    778f174 View commit details

Commits on May 17, 2021

  1. Copy the full SHA
    6e7ef5d View commit details

Commits on Jun 8, 2021

  1. Copy the full SHA
    bbcedd9 View commit details

Commits on Jun 11, 2021

  1. Changes for release of Sandbox

    Stephen Barlow committed Jun 11, 2021
    Copy the full SHA
    1fcd4e6 View commit details

Commits on Jun 14, 2021

  1. Copy the full SHA
    2523a61 View commit details

Commits on Jun 15, 2021

  1. Keep subscriptions article on GraphQL playground temporarily

    Stephen Barlow committed Jun 15, 2021
    Copy the full SHA
    503600e View commit details
  2. Improve Sandbox screenshot

    Stephen Barlow committed Jun 15, 2021
    Copy the full SHA
    4316ce5 View commit details
  3. Restore note about enabling introspection

    Stephen Barlow committed Jun 15, 2021
    Copy the full SHA
    ab0fbfd View commit details
  4. Merge pull request #5301 from apollographql/sb/add-sandbox

    Changes for release of Sandbox
    Stephen Barlow authored Jun 15, 2021
    Copy the full SHA
    eed8a92 View commit details
  5. Renovate: start running against release-3.0

    We are in the final days of AS3 development and our focus is no longer
    on `main`. Let's let Renovate help us with `release-3.0` instead of
    `main`. Note that the `main` renovate.json5 is still what is used for
    configuration.
    
    We can remove all the blocked major version bumps because they are not
    relevant on AS3.
    glasser committed Jun 15, 2021
    Copy the full SHA
    ba3fdca View commit details
  6. Copy the full SHA
    0f9ead5 View commit details
  7. Followup: actually tell renovate to use release-3.0 instead of just c…

    …ommenting, and use default schedule
    glasser committed Jun 15, 2021
    Copy the full SHA
    8175573 View commit details
  8. Renovate: allow automerge

    It looks like we disabled it due to a specific issue years ago in
    #2290
    
    Let's see how the `apollo-open-source` default of `minor` works.
    glasser committed Jun 15, 2021
    Copy the full SHA
    eecaa31 View commit details
  9. Merge pull request #5185 from ginglis13/gcp-functions-docs

    apollo docs: add documentation for deploying to GCP
    Stephen Barlow authored Jun 15, 2021
    Copy the full SHA
    c929290 View commit details
  10. Edit pass on Google Cloud Functions docs

    Stephen Barlow committed Jun 15, 2021
    Copy the full SHA
    b0a8a09 View commit details
  11. Merge pull request #5312 from apollographql/sb/gcp-edits

    Edit pass on Google Cloud Functions docs
    Stephen Barlow authored Jun 15, 2021
    Copy the full SHA
    e9dcbbd View commit details
  12. Renovate: disable circleci manager

    It tries to do major bumps.
    glasser authored Jun 15, 2021
    Copy the full SHA
    c7bb352 View commit details

Commits on Jun 16, 2021

  1. Copy the full SHA
    78ab403 View commit details
  2. Copy the full SHA
    6b9c2a0 View commit details

Commits on Jun 22, 2021

  1. Update Express types files, allow further upgrades (#5352)

    Our versions for `@types/express` and `@types/express-serve-static-core`
    have gotten a bit out of date. They are already upgraded on
    `release-3.0` but that's not quite `latest` yet. Somehow despite the
    fact that neither `express` nor `serve-static` have had a new version in
    two years, the DefinitelyTyped packages for them keep getting
    backwards-incompatible changes. This is apparently helpful for some
    users who have upgraded some other packages.
    
    Because of how finicky these types are (eg specific `@types/express`
    versions depends on specific `@types/express-serve-static-core` versions
    without appropriate version dependencies between them) I do generally
    think it's best to depend on exact versions here. However I also don't
    want to have to make any more AS2 releases. So I'm making these into
    caret dependencies but don't intend to make a similar change on
    `release-3.0`.
    
    Fixes #5350.
    glasser authored Jun 22, 2021
    Copy the full SHA
    dc8693f View commit details
  2. CHANGELOG: 2.25.2

    glasser committed Jun 22, 2021
    Copy the full SHA
    e719b78 View commit details
  3. Release

     - apollo-server-azure-functions@2.25.2
     - apollo-server-cloud-functions@2.25.2
     - apollo-server-cloudflare@2.25.2
     - apollo-server-core@2.25.2
     - apollo-server-express@2.25.2
     - apollo-server-fastify@2.25.2
     - apollo-server-hapi@2.25.2
     - apollo-server-integration-testsuite@2.25.2
     - apollo-server-koa@2.25.2
     - apollo-server-lambda@2.25.2
     - apollo-server-micro@2.25.2
     - apollo-server-testing@2.25.2
     - apollo-server@2.25.2
    glasser committed Jun 22, 2021
    Copy the full SHA
    70a4312 View commit details
Showing with 463 additions and 154 deletions.
  1. +5 −1 CHANGELOG.md
  2. +1 −0 docs/gatsby-config.js
  3. +1 −0 docs/source/data/data-sources.mdx
  4. +1 −1 docs/source/data/resolvers.mdx
  5. +1 −4 docs/source/data/subscriptions.mdx
  6. +260 −0 docs/source/deployment/gcp-functions.mdx
  7. +13 −29 docs/source/getting-started.mdx
  8. BIN docs/source/images/composition_schema-1.png
  9. BIN docs/source/images/composition_schema-2.png
  10. BIN docs/source/images/getting-started/graphql-playground-response.png
  11. BIN docs/source/images/getting-started/graphql-playground.png
  12. BIN docs/source/images/graphql.png
  13. BIN docs/source/images/persistedQueries.newPath.png
  14. BIN docs/source/images/persistedQueries.optPath.png
  15. BIN docs/source/images/sandbox-response.jpg
  16. BIN docs/source/images/sandbox.jpg
  17. +14 −6 docs/source/testing/graphql-playground.mdx
  18. +5 −17 package-lock.json
  19. +1 −1 package.json
  20. +1 −1 packages/apollo-server-azure-functions/package.json
  21. +121 −37 packages/apollo-server-cloud-functions/README.md
  22. +1 −1 packages/apollo-server-cloud-functions/package.json
  23. +1 −1 packages/apollo-server-cloudflare/package.json
  24. +1 −1 packages/apollo-server-core/package.json
  25. +3 −3 packages/apollo-server-express/package.json
  26. +1 −1 packages/apollo-server-fastify/package.json
  27. +1 −1 packages/apollo-server-hapi/package.json
  28. +1 −1 packages/apollo-server-integration-testsuite/package.json
  29. +1 −1 packages/apollo-server-koa/package.json
  30. +1 −1 packages/apollo-server-lambda/package.json
  31. +1 −1 packages/apollo-server-micro/package.json
  32. +1 −1 packages/apollo-server-testing/package.json
  33. +1 −1 packages/apollo-server/package.json
  34. +25 −43 renovate.json5
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,9 +11,13 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
## v2.25.2

- `apollo-server-express`: Update dependencies on `@types/express` and `@types/express-serve-static-core`. [PR #5352](https://github.com/apollographql/apollo-server/pull/5352)

## v2.25.1

- `apollo-server-core`, `apollo-server-express`: Upgrade `subscriptions-transport-ws` dependency and remove unneeded runtime dependency on `ws`. This should enable you to install Apollo Server without depending on versions of `ws` vulnerable to [CVE-2021-32640](https://www.npmjs.com/advisories/1748). Note that the superficial integration of the unmaintained `subscriptions-transport-ws` package will be removed in Apollo Server 3; you can also avoid this vulnerability by disabling the built-in subscription support with `new ApolloServer({subscriptions: false})` and using a maintained package such as `graphql-ws` instead.
- `apollo-server-core`, `apollo-server-express`: Upgrade `subscriptions-transport-ws` dependency and remove unneeded runtime dependency on `ws`. This should enable you to install Apollo Server without depending on versions of `ws` vulnerable to [CVE-2021-32640](https://www.npmjs.com/advisories/1748). Note that the superficial integration of the unmaintained `subscriptions-transport-ws` package will be removed in Apollo Server 3; you can also avoid this vulnerability by disabling the built-in subscription support with `new ApolloServer({subscriptions: false})` and using a maintained package such as `graphql-ws` instead. (Instead of taking this upgrade, you can also upgrade `ws` to `5.2.3`, which was just released.)

## v2.25.0

1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ module.exports = {
'deployment/lambda',
'deployment/netlify',
'deployment/azure-functions',
'deployment/gcp-functions'
],
Monitoring: ['monitoring/metrics', 'monitoring/health-checks'],
'API Reference': [
1 change: 1 addition & 0 deletions docs/source/data/data-sources.mdx
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ Apollo and the larger community maintain the following open-source implementaton
| Class | Source | For Use With |
|------------------|-----------|-----------------------|
| [`RESTDataSource`](https://github.com/apollographql/apollo-server/tree/main/packages/apollo-datasource-rest) | Apollo | REST APIs ([see below](#restdatasource-reference)) |
| [`HTTPDataSource`](https://github.com/StarpTech/apollo-datasource-http) | Community | HTTP/REST APIs (newer community alternative to `RESTDataSource`) |
| [`SQLDataSource`](https://github.com/cvburgess/SQLDataSource) | Community | SQL databases (via [Knex.js](http://knexjs.org/)) |
| [`MongoDataSource`](https://github.com/GraphQLGuide/apollo-datasource-mongodb/) | Community | MongoDB |
| [`CosmosDataSource`](https://github.com/andrejpk/apollo-datasource-cosmosdb) | Community | Azure Cosmos DB |
2 changes: 1 addition & 1 deletion docs/source/data/resolvers.mdx
Original file line number Diff line number Diff line change
@@ -360,7 +360,7 @@ Resolver functions are passed four arguments: `parent`, `args`, `context`, and `
| `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/master/src/type/definition.js#L917-L928), 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> |
| `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

5 changes: 1 addition & 4 deletions docs/source/data/subscriptions.mdx
Original file line number Diff line number Diff line change
@@ -232,12 +232,9 @@ An example server is available on [GitHub](https://github.com/apollographql/docs
<img alt="Edit server-subscriptions" src="https://codesandbox.io/static/img/play-codesandbox.svg"></img>
</a>


The server exposes one subscription (`numberIncremented`) that returns an integer that's incremented on the server every second. The example requires only the `apollo-server` library.

After you start up this server, you can test out running a subscription with the Apollo Studio Explorer or GraphQL Playground, as described in the [full-stack tutorial](https://www.apollographql.com/docs/tutorial/schema/#explore-your-schema). You'll see the subscription's value update every second.

> In the Apollo Studio Explorer, you must specify your server's subscription endpoint (`ws://localhost:4000/subscriptions`) in the **Explorer Settings** tab.
After you start up this server locally, you can visit `http://localhost:4000` to test out running the `numberIncremented` subscription in GraphQL Playground. You'll see the subscription's value update every second.

## Operation context

260 changes: 260 additions & 0 deletions docs/source/deployment/gcp-functions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
---
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
const { ApolloServer, gql } = require('apollo-server-cloud-functions');

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;

// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};

/*
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
`introspection` options to `true` for GraphQL Playground to work correctly.
*/
const server = new ApolloServer({
typeDefs,
resolvers,
playground: true,
introspection: true,
});

exports.handler = server.createHandler();
```

</ExpansionPanel>


## Deploying from the Google Cloud Console

### 1. Configure the function

From your Google Cloud Console, go to the [Cloud Functions page](https://console.cloud.google.com/functions/list).

Click **Create Function**. Give the function a name and set the **Trigger type** to `HTTP`.

For quick setup and access to the GraphQL endpoint/playground, choose to **Allow unauthenticated invocations**. To require authentication for this endpoint, you can manage authorized users via [Cloud IAM](https://console.cloud.google.com/iam-admin/iam).

Save your configuration changes in the Trigger section. Copy the trigger's URL for later and click **Next**.

### 2. Write the API handlers and deploy

Now on the Code page, set the runtime to a currently supported version of Node.js (such as `Node.js 14`), and set the Entry point to `handler`.

Paste the example code at the top of this page into the contents of `index.js` in the code editor.

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

```json:title=package.json
"dependencies": {
"apollo-server-cloud-functions": "^2.24.0",
"graphql": "^15.5.0"
}
```

Click **Deploy** to initiate deployment. Then, proceed to [Testing the function](#testing-the-function).


## Deploying from your local machine

Before proceeding, you need to set up the gcloud SDK:

1. [Install the gcloud SDK](https://cloud.google.com/sdk/docs/install)

2. [Initialize the gcloud SDK and authenticate your Google account](https://cloud.google.com/sdk/docs/initializing)

Next, initialize a new Node.js project by running `npm init` in an empty directory.

Run `npm install apollo-server-cloud-functions graphql` to install the necessary dependencies and to include them in the `package.json` file.

At this point, your `package.json` should resemble the following:

```json
{
"name": "apollo-gcloud",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-cloud-functions": "^2.24.0",
"graphql": "^15.5.0"
}
}
```

Create a new file named `index.js` and paste the sample code at the top of this page into it.

Run the following command to create and deploy the function to Cloud Functions:

```bash
gcloud functions deploy apollo-graphql-example --entry-point handler --runtime nodejs14 --trigger-http
```

This creates a function named `apollo-graphql-example` that you can view from your console's [Cloud Functions page](https://console.cloud.google.com/functions/list)

The command asks some configuration questions and prints metadata about your newly created function, which includes the function's trigger URL.

For more information, see the official [Cloud Functions docs](https://cloud.google.com/functions/docs/deploying/filesystem).

## Testing the function

After deployment completes, navigate to your function's trigger URL. If deployment succeeded, GraphQL Playground opens.

> If you can't access your trigger URL, you might need to [add `allAuthenticatedUsers` or `allUsers` permissions](https://cloud.google.com/iam/docs/overview#all-authenticated-users) to your function.
You can use GraphQL Playground to test the following query:

```graphql
query TestQuery {
hello
}
```

And verify that the following response appears:

```json
{
"data": {
"hello": "Hello world!"
}
}
```

## Getting request details

To obtain information about a currently executing Google Cloud Function (HTTP headers, HTTP method, body, path, etc.) use the `context` option. This enables you to pass any request-specific data to your server's resolvers.

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

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;

// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};

const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req, res }) => ({
headers: req.headers,
req,
res,
}),
});

exports.handler = server.createHandler();
```

## Modifying the GCF Response (CORS)

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

```javascript{23-26}
const { ApolloServer, gql } = require('apollo-server-cloud-functions');
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
exports.handler = server.createHandler({
cors: {
origin: '*',
credentials: true,
},
});
```

To enable CORS response for requests with credentials (cookies, HTTP authentication) the allow origin header must equal the request origin and the allow credential header must be set to `true`.

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

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;

// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};

const server = new ApolloServer({
typeDefs,
resolvers,
});

exports.handler = server.createHandler({
cors: {
origin: true,
credentials: true,
},
});
```

### CORS Options

The options correspond to the [express `cors` configuration](https://github.com/expressjs/cors#configuration-options) with the following fields(all are optional):

| Option | Type(s) |
|--------|---------|
| `origin` | boolean \| string \| string[] |
| `methods` | string \| string[] |
| `allowedHeaders` | string \| string[] |
| `exposedHeaders` | string \| string[] |
| `credentials` | boolean |
| `maxAge` | number |
42 changes: 13 additions & 29 deletions docs/source/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Get started with Apollo Server
sidebar_title: Get started
---

import {
@@ -182,55 +183,38 @@ We're up and running!
## Step 8: Execute your first query

We can now execute GraphQL queries on our server. To execute our first query,
we can use a tool called **GraphQL Playground**.
we can use **Apollo Sandbox**.

<ExpansionPanel title="📣 The Apollo Studio Explorer now supports local servers">
With your server still running, visit [studio.apollographql.com/sandbox](https://studio.apollographql.com/sandbox) to open Sandbox:

Apollo Studio now supports **dev graphs**, which are user-specific graphs that represent your local development server. Dev graphs enable you to query your locally running server with Studio's powerful Explorer.
<img class="screenshot" src="./images/sandbox.jpg" alt="Apollo Sandbox"/>

To try out dev graphs:
The Sandbox UI includes:

1. Make sure your server is running locally.
2. Visit [studio.apollographql.com/dev](https://studio.apollographql.com/dev).
3. Create a (free) Apollo account if you don't have one. Then specify a name, endpoint (e.g., `http://localhost:4000`), and organization for your dev graph.
4. Try running operations on your local server using the [Apollo Studio Explorer](https://www.apollographql.com/docs/studio/explorer/).

</ExpansionPanel>

With your server still running, visit `http://localhost:4000` in your browser to open GraphQL Playground. (Apollo Server hosts GraphQL Playground automatically when you run it in a non-production environment.)

![GraphQL Playground](./images/getting-started/graphql-playground.png)

The GraphQL Playground UI includes:

* A text area (to the left) for writing queries
* A Play button (the triangle button in the middle) for executing queries
* A text area (to the right) for viewing query results
* Views for schema inspection and generated documentation (via tabs on the right side)
* An Operations panel (in the middle) for writing and executing queries
* A Response panel (to the right) for viewing query results
* Tabs for schema exploration, search, and settings (on the left)

Our server supports a single query named `books`. Let's execute it!

Here's a GraphQL **query string** for executing the `books` query:

```graphql
{
query GetBooks {
books {
title
author
}
}
```

Paste this string into the left text area and click the Play button. The
results (from our hardcoded data set) appear on the right:
Paste this string into the Operations panel and click the blue button in the upper right. The results (from our hardcoded data set) appear in the Response panel:

![The response from our server shows title and author!](./images/getting-started/graphql-playground-response.png)
<img class="screenshot" src="./images/sandbox-response.jpg" width="400" alt="Sandbox response panel"/>

One of the most important concepts of GraphQL is that clients can choose to query
_only for the fields they need_. Delete `author` from the query string and execute
it again. The response updates to include only the `title` field for each book!
> **Note:** If your server is deployed to an environment where `NODE_ENV` is set to `production`, introspection is **disabled** by default. This prevents Apollo Sandbox from working properly. To enable introspection, set `introspection: true` in [the options to `ApolloServer`'s constructor](./api/apollo-server/#constructor).
> **Note:** If your server is deployed to an environment where `NODE_ENV` is set to `production`, GraphQL Playground and introspection are **disabled** by default. To enable them, set `playground: true` and `introspection: true` in [the options to `ApolloServer`'s constructor](./api/apollo-server/#constructor).
One of the most important concepts of GraphQL is that clients can choose to query _only for the fields they need_. Delete `author` from the query string and execute it again. The response updates to include only the `title` field for each book!

## Combined example

Binary file removed docs/source/images/composition_schema-1.png
Binary file not shown.
Binary file removed docs/source/images/composition_schema-2.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed docs/source/images/graphql.png
Binary file not shown.
Binary file removed docs/source/images/persistedQueries.newPath.png
Binary file not shown.
Binary file removed docs/source/images/persistedQueries.optPath.png
Binary file not shown.
Binary file added docs/source/images/sandbox-response.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/sandbox.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions docs/source/testing/graphql-playground.mdx
Original file line number Diff line number Diff line change
@@ -6,17 +6,25 @@ description: Visually explore Apollo Server
import {
ExpansionPanel,
} from 'gatsby-theme-apollo-docs/src/components/expansion-panel';
import { Button } from '@apollo/space-kit/Button';
import { Link } from 'gatsby';
import { colors } from 'gatsby-theme-apollo-core';

<ExpansionPanel title="📣 The Apollo Studio Explorer now supports local development">

Apollo Studio now supports **dev graphs**, which are user-specific graphs that represent your local development server. Dev graphs enable you to query your locally running server with Studio's powerful Explorer.
**Apollo Sandbox** is a special instance of the Apollo Studio Explorer that you can use for local development without an Apollo account.

To try out dev graphs:
<p>
<Button
size="large"
color={colors.primary}
as={<Link to="https://studio.apollographql.com/sandbox/" target="_blank" />}
>
Launch Sandbox
</Button>
</p>

1. Make sure your server is running locally.
2. Visit [studio.apollographql.com/dev](https://studio.apollographql.com/dev).
3. Create a (free) Apollo account if you don't have one. Then specify a name, endpoint (e.g., `http://localhost:4000`), and organization for your dev graph.
4. Try running operations on your local server using the [Apollo Studio Explorer](https://www.apollographql.com/docs/studio/explorer/).
Sandbox automatically attempts to connect to a GraphQL server running at `http://localhost:4000`. You can use the box at the top of the page to change this URL to any local or remote GraphQL endpoint that's accessible by your browser.

</ExpansionPanel>

22 changes: 5 additions & 17 deletions package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@
"@types/bunyan": "1.8.6",
"@types/connect": "3.4.34",
"@types/cors": "2.8.10",
"@types/express": "4.17.11",
"@types/express": "4.17.12",
"@types/fast-json-stable-stringify": "2.0.0",
"@types/hapi": "17.8.10",
"@types/ioredis": "4.26.2",
2 changes: 1 addition & 1 deletion 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": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Azure Functions",
"keywords": [
"GraphQL",
158 changes: 121 additions & 37 deletions packages/apollo-server-cloud-functions/README.md
Original file line number Diff line number Diff line change
@@ -10,13 +10,11 @@ This is the Google Cloud Function integration of GraphQL Server. Apollo Server i
npm install apollo-server-cloud-functions graphql
```

## Deploying with Google Cloud Function
# Deploying with Google Cloud Functions

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

First, create a `package.json` file and include `apollo-server-cloud-functions` in your dependencies. Then in a file named `index.js`, place the following code:

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

// Construct a schema, using GraphQL schema language
@@ -33,6 +31,11 @@ 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
`introspection` options to `true` for GraphQL Playground to work correctly.
*/
const server = new ApolloServer({
typeDefs,
resolvers,
@@ -43,22 +46,111 @@ const server = new ApolloServer({
exports.handler = server.createHandler();
```

#### 2. Configure your Cloud Function and deploy
## Deploying from the Google Cloud Console

### 1. Configure the function

From your Google Cloud Console, go to the [Cloud Functions page](https://console.cloud.google.com/functions/list).

Click **Create Function**. Give the function a name and set the **Trigger type** to `HTTP`.

For quick setup and access to the GraphQL endpoint/playground, choose to **Allow unauthenticated invocations**. To require authentication for this endpoint, you can manage authorized users via [Cloud IAM](https://console.cloud.google.com/iam-admin/iam).

Save your configuration changes in the Trigger section. Copy the trigger's URL for later and click **Next**.

### 2. Write the API handlers and deploy

Now on the Code page, set the runtime to a currently supported version of Node.js (such as `Node.js 14`), and set the Entry point to `handler`.

Paste the example code at the top of this page into the contents of `index.js` in the code editor.

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

```json:title=package.json
"dependencies": {
"apollo-server-cloud-functions": "^2.24.0",
"graphql": "^15.5.0"
}
```

Click **Deploy** to initiate deployment. Then, proceed to [Testing the function](#testing-the-function).


## Deploying from your local machine

Before proceeding, you need to set up the gcloud SDK:

1. [Install the gcloud SDK](https://cloud.google.com/sdk/docs/install)

2. [Initialize the gcloud SDK and authenticate your Google account](https://cloud.google.com/sdk/docs/initializing)

Next, initialize a new Node.js project by running `npm init` in an empty directory.

Run `npm install apollo-server-cloud-functions graphql` to install the necessary dependencies and to include them in the `package.json` file.

At this point, your `package.json` should resemble the following:

```json
{
"name": "apollo-gcloud",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-cloud-functions": "^2.24.0",
"graphql": "^15.5.0"
}
}
```

Create a new file named `index.js` and paste the sample code at the top of this page into it.

On the Create Function page, set _Trigger_ to `HTTP` and _Function to execute_ to the name of your exported handler, in this case `handler`.
Run the following command to create and deploy the function to Cloud Functions:

Since NODE_ENV is a reserved environment variable in GCF and it defaults to "production", both the **playground** and **introspection**
options need to be explicitly set to `true` for the GraphQL Playground to work correctly.
```bash
gcloud functions deploy apollo-graphql-example --entry-point handler --runtime nodejs14 --trigger-http
```

After configuring your Function you can press **Create** and an http endpoint will be created a few seconds later.
This creates a function named `apollo-graphql-example` that you can view from your console's [Cloud Functions page](https://console.cloud.google.com/functions/list)

You can refer to the [Cloud Functions documentation](https://cloud.google.com/functions/docs/quickstart-console) for more details
The command asks some configuration questions and prints metadata about your newly created function, which includes the function's trigger URL.

## Getting request info
For more information, see the official [Cloud Functions docs](https://cloud.google.com/functions/docs/deploying/filesystem).

To read information about the currently executing Google Cloud Function (HTTP headers, HTTP method, body, path, ...) use the context option. This way you can pass any request specific data to your schema resolvers.
## Testing the function

After deployment completes, navigate to your function's trigger URL. If deployment succeeded, GraphQL Playground opens.

> If you can't access your trigger URL, you might need to [add `allAuthenticatedUsers` or `allUsers` permissions](https://cloud.google.com/iam/docs/overview#all-authenticated-users) to your function.
You can use GraphQL Playground to test the following query:

```graphql
query TestQuery {
hello
}
```

```js
And verify that the following response appears:

```json
{
"data": {
"hello": "Hello world!"
}
}
```

## Getting request details

To obtain information about a currently executing Google Cloud Function (HTTP headers, HTTP method, body, path, etc.) use the `context` option. This enables you to pass any request-specific data to your server's resolvers.

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

// Construct a schema, using GraphQL schema language
@@ -88,11 +180,11 @@ const server = new ApolloServer({
exports.handler = server.createHandler();
```

## Modifying the GCF Response (Enable CORS)
## Modifying the GCF Response (CORS)

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

```js
```javascript{23-26}
const { ApolloServer, gql } = require('apollo-server-cloud-functions');
// Construct a schema, using GraphQL schema language
@@ -122,9 +214,9 @@ exports.handler = server.createHandler({
});
```

To enable CORS response for requests with credentials (cookies, http authentication) the allow origin header must equal the request origin and the allow credential header must be set to true.
To enable CORS response for requests with credentials (cookies, HTTP authentication) the allow origin header must equal the request origin and the allow credential header must be set to `true`.

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

// Construct a schema, using GraphQL schema language
@@ -154,23 +246,15 @@ exports.handler = server.createHandler({
});
```

### Cors Options

The options correspond to the [express cors configuration](https://github.com/expressjs/cors#configuration-options) with the following fields(all are optional):

- `origin`: boolean | string | string[]
- `methods`: string | string[]
- `allowedHeaders`: string | string[]
- `exposedHeaders`: string | string[]
- `credentials`: boolean
- `maxAge`: number

## Principles

GraphQL Server is built with the following principles in mind:
### CORS Options

- **By the community, for the community**: GraphQL Server's development is driven by the needs of developers
- **Simplicity**: by keeping things simple, GraphQL Server is easier to use, easier to contribute to, and more secure
- **Performance**: GraphQL Server is well-tested and production-ready - no modifications needed
The options correspond to the [express `cors` configuration](https://github.com/expressjs/cors#configuration-options) with the following fields(all are optional):

Anyone is welcome to contribute to GraphQL Server, just read [CONTRIBUTING.md](https://github.com/apollographql/apollo-server/blob/main/CONTRIBUTING.md), take a look at the [roadmap](https://github.com/apollographql/apollo-server/blob/main/ROADMAP.md) and make your first PR!
| Option | Type(s) |
|--------|---------|
| `origin` | boolean \| string \| string[] |
| `methods` | string \| string[] |
| `allowedHeaders` | string \| string[] |
| `exposedHeaders` | string \| string[] |
| `credentials` | boolean |
| `maxAge` | number |
2 changes: 1 addition & 1 deletion packages/apollo-server-cloud-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloud-functions",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Google Cloud Functions",
"keywords": [
"GraphQL",
2 changes: 1 addition & 1 deletion packages/apollo-server-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloudflare",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Cloudflare workers",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-core",
"version": "2.25.1",
"version": "2.25.2",
"description": "Core engine for Apollo GraphQL server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
6 changes: 3 additions & 3 deletions packages/apollo-server-express/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-express",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Express and Connect",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
"@types/accepts": "^1.3.5",
"@types/body-parser": "1.19.0",
"@types/cors": "2.8.10",
"@types/express": "4.17.11",
"@types/express-serve-static-core": "4.17.19",
"@types/express": "^4.17.12",
"@types/express-serve-static-core": "^4.17.21",
"accepts": "^1.3.5",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-types": "file:../apollo-server-types",
2 changes: 1 addition & 1 deletion packages/apollo-server-fastify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-fastify",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Fastify",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-hapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-hapi",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Hapi",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-integration-testsuite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "apollo-server-integration-testsuite",
"private": true,
"version": "2.25.1",
"version": "2.25.2",
"description": "Apollo Server Integrations testsuite",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-koa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-koa",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Koa",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-lambda",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for AWS Lambda",
"keywords": [
"GraphQL",
2 changes: 1 addition & 1 deletion packages/apollo-server-micro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-micro",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production-ready Node.js GraphQL server for Micro",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-testing",
"version": "2.25.1",
"version": "2.25.2",
"description": "Test utils for apollo-server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
2 changes: 1 addition & 1 deletion packages/apollo-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server",
"version": "2.25.1",
"version": "2.25.2",
"description": "Production ready GraphQL Server",
"author": "Apollo <opensource@apollographql.com>",
"main": "dist/index.js",
68 changes: 25 additions & 43 deletions renovate.json5
Original file line number Diff line number Diff line change
@@ -2,61 +2,34 @@
"extends": [
"apollo-open-source"
],
/* During the last stages of v3, we are running Renovate against
* release-3.0 instead of main. Note that Renovate config still lives
* on main! Also for now let's run Renovate as much as possible rather
* than batching on the weekends like apollo-open-source does.
*/
"baseBranches": ["release-3.0"],
"schedule": null,
// Disable circleci manager; see apollographql/federation's renovate file for details.
"enabledManagers": ["npm"],
"dependencyDashboard": true,
"automerge": false,
"packageRules": [
{
"matchPackageNames": ["@types/node"],
"allowedVersions": "8.x"
},
/*
Avoid major version bumps to server frameworks (those used by the
various Apollo Server integrations (e.g. Fastify, Express, Koa, etc.),
which must be reserved for a major version bump to Apollo Server itself.
For more thoughts here, see my comment on the commits that introduced
these threshholds via `git blame`.
*/
{
"matchPackageNames": ["fastify"],
"allowedVersions": "<2"
},
{
"matchPackageNames": ["fastify-cors"],
"allowedVersions": "<1"
},
{
"matchPackageNames": ["koa-bodyparser"],
"allowedVersions": "<4"
},
{
"matchPackageNames": ["@koa/cors"],
"allowedVersions": "<3"
"allowedVersions": "12.x"
},
// make-fetch-happen is used by the op reg plugin, which uses a cache API
// that is removed in v9.
{
"matchPackageNames": ["log4js"],
"allowedVersions": "<5"
},
{
"matchPackageNames": ["hapi", "@types/hapi"],
"allowedVersions": "<18"
},
{
"matchPackageNames": ["ws"],
"allowedVersions": "<7"
},
// Remove when we're no longer supporting Node.js v6
{
"matchPackageNames": ["nock"],
"allowedVersions": "<11"
"matchPackageNames": ["make-fetch-happen"],
"allowedVersions": "8.x"
},
/*
Docs-related Renovate rules
These ensure that the `docs/` folder, which is its own application with
its own dependencies which lives inside this repository, plays by its
own Renovate rules. Those rules are defined within the external (npm)
package called `renovate-config-apolllo-docs` (defined here only by
package called `renovate-config-apollo-docs` (defined here only by
the `apollo-docs` suffix).
*/
{
@@ -70,8 +43,17 @@
// of Apollo Server. "Past" major versions should be added here!
"baseBranches": [
"main",
"version-2"
"release-3.0"
]
},
// The current Apollo Gatsby theme does not support a version of Gatsby
// that supports React 17.
{
"matchPaths": [
"docs/package.json"
],
"matchPackageNames": ["react", "react-dom"],
"allowedVersions": "16.x",
}
]
}