Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update graphql-tools to v7 scoped packages and simplify dependency #5183

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ The version headers in this history reflect the versions of Apollo Server itself
- `apollo-server-caching`: The test suite helper works differently, and the `TestableKeyValueCache` interface is removed.
- `apollo-datasource-rest`: We no longer officially support overriding the `baseURL` property with a getter, because TypeScript 4 does not allow you to do that.
- Previously, Apollo Server would automatically add the definition of the `@cacheControl` directive to your schema in some circumstances but not in others; this depended on how precisely you set up your schema, but not on whether you had disabled the cache control feature. In Apollo Server 3, Apollo Server is now consistent: it never automatically adds the directive definition to your schema. If you use `@cacheControl`, just [define it yourself as shown in the docs](https://www.apollographql.com/docs/apollo-server/performance/caching/#in-your-schema-static).
- The `schemaDirectives` option to `new ApolloServer` has been removed. This option was implemented inside the `graphql-tools` function `makeExecutableSchema`. If you'd like to continue using it, just import `makeExecutableSchema` from `@graphql-tools/schema` and call it yourself: `new ApolloServer({schema: makeExecutableSchema({typeDefs, resolvers, schemaDirectives})})`. Note that `graphql-tools` calls this option ["legacy" schema directives](https://www.graphql-tools.com/docs/legacy-schema-directives/) and you may want to consider the newer [`schemaTransforms`](https://www.graphql-tools.com/docs/schema-directives/) option instead.
- The `mocks` option to `new ApolloSchema` is now powered by `@graphql-tools/mock` v7 instead of `graphql-tools` v4. This contains some [breaking changes](https://www.graphql-tools.com/docs/mocking#migration-from-v7-and-below); for example, mock functions no longer receive arguments and cannot return `Promise`s. Note that some of the suggestions in the v7 migration guide suggest using the `resolvers` argument to `addMocksToSchema`. Apollo Server does not support this option, but you're welcome to call `addMocksToSchema` yourself and pass the result to the `schema` option to `new ApolloSchema`.
- `apollo-server-express`: We no longer officially support using this package with the `connect` framework. We have not actively removed any `connect` compatibility code and do still test that it works with `connect`, but we reserve the right to break that compatibility without a major version bump of this package (though it will certainly be noted in the CHANGELOG if we do so).
- Top-level exports have changed. E.g.,

- We no longer re-export the entirety of `graphql-tools` (including `makeExecutableSchema`) from all Apollo Server packages.
- We no longer re-export the entirety of `graphql-tools` (including `makeExecutableSchema`) from all Apollo Server packages. If you'd like to continue using them, install [`graphql-tools`](https://www.graphql-tools.com/) or one of its sub-packages yourself.
- The `Upload` scalar is no longer exported. (See above as to why.)

## v2.24.0
Expand Down
2 changes: 0 additions & 2 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
'schema/unions-interfaces',
'schema/custom-scalars',
'schema/directives',
'schema/creating-directives',
],
'Fetching Data': [
'data/resolvers',
Expand Down Expand Up @@ -60,7 +59,6 @@ module.exports = {
'api/plugin/usage-reporting',
'api/plugin/schema-reporting',
'api/plugin/inline-trace',
'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/)',
],
Expand Down
89 changes: 0 additions & 89 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,6 @@ The default value is `true`, **unless** the `NODE_ENV` environment variable is s
</tr>


<tr>
<td>

###### `schemaDirectives`

`Object`
</td>

<td>

A map of all [custom schema directives](../schema/directives/#custom-schema-directives) used in your schema, if any.
</td>
</tr>

<tr>
<td>

Expand Down Expand Up @@ -879,78 +865,3 @@ const typeDefs = gql`
```

This converts GraphQL strings into the format that Apollo libraries expect when working with operations and schemas. It also helps tools identify when a string contains GraphQL language (such as to enable syntax highlighting).

---

## `makeExecutableSchema`

Builds a schema from provided type definitions and resolvers.

The [`ApolloServer` constructor](#constructor) automatically calls this method using the `typeDefs` and `resolvers` options you provide, so in most cases you don't need to call it yourself.

This method is defined in the `graphql-tools` library and is re-exported from `apollo-server` as a convenience. [See its documentation here.](./graphql-tools/#makeexecutableschemaoptions)

---

## `addMockFunctionsToSchema`

The `addMockFunctionsToSchema` method is re-exported from `apollo-server` as a convenience.

Given an instance of a `GraphQLSchema` and a `mock` object, modifies the schema (in place) to return mock data for any valid query that is sent to the server.

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.

### Parameters

* `options`: <`Object`>

* `schema`: <`GraphQLSchema`> _(required)_

Pass an executable schema (`GraphQLSchema`) to be mocked.

* `mocks`: <`Object`>

Should be a map of types to mock resolver functions, e.g.:

```js
{
Type: () => true,
}
```

When `mocks` is not defined, the default scalar types (e.g. `Int`, `Float`, `String`, etc.) will be mocked.

* `preserveResolvers`: <`Boolean`>

When `true`, resolvers which were already defined will not be over-written with the mock resolver functions specified with `mocks`.

### Usage

```js
const { addMockFunctionsToSchema } = require('apollo-server');

// We'll make an assumption that an executable schema
// is already available from the `./schema` file.
const executableSchema = require('./schema');

addMockFunctionsToSchema({
schema: executableSchema,
mocks: {
// Mocks the `Int` scalar type to always return `12345`.
Int: () => 12345,

// Mocks the `Movies` type to always return 'Titanic'.
Movies: () => 'Titanic',
},
preserveResolvers: false,
});
```
---

## `graphql-tools` exports

The `graphql-tools` library provides helpful functions (such as [`makeExecutableSchema`](#makeexecutableschema) above) for creating and manipulating GraphQL schemas. Apollo Server uses many of these functions internally, and it re-exports all of them to support advanced use cases.

Apollo Server uses `graphql-tools` version 4. For documentation of version 4 functions, see [graphql-tools](./graphql-tools).

> For documentation of the _latest_ version of `graphql-tools`, see the [official `graphql-tools` documentation](https://www.graphql-tools.com/docs/introduction).
Loading