Skip to content

Commit

Permalink
Drop usage of graphql-extensions in favor of plugin API.
Browse files Browse the repository at this point in the history
This commit was already implemented in the `release-3.0` branch on the
`apollo-server` repository [[Ref]], however, now that Apollo Gateway and Apollo
Federation are part of the `federation` repository, that particular commit
will likely never see the light of day!

[Ref]: apollographql/apollo-server@05f0d2f
  • Loading branch information
abernix committed Sep 7, 2020
1 parent 3aa1b08 commit ff45cb7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
1 change: 0 additions & 1 deletion gateway-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"apollo-server-env": "^2.4.5",
"apollo-server-errors": "^2.4.2",
"apollo-server-types": "^0.5.1",
"graphql-extensions": "^0.12.4",
"loglevel": "^1.6.1",
"make-fetch-happen": "^8.0.0",
"pretty-format": "^26.0.0"
Expand Down
8 changes: 4 additions & 4 deletions gateway-js/src/datasources/LocalGraphQLDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
DocumentNode,
parse,
} from 'graphql';
import { enableGraphQLExtensions } from 'graphql-extensions';
import {
enablePluginsForSchemaResolvers,
} from 'apollo-server-core/dist/utils/schemaInstrumentation';
import { GraphQLDataSource } from './types';

export class LocalGraphQLDataSource<TContext extends Record<string, any> = Record<string, any>> implements GraphQLDataSource<TContext> {
constructor(public readonly schema: GraphQLSchema) {
// FIXME: This is needed to enable support for `resolveObject`, but we
// should move that to `apollo-graphql`
enableGraphQLExtensions(schema);
enablePluginsForSchemaResolvers(schema);
}

async process({
Expand Down
4 changes: 1 addition & 3 deletions gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ export async function executeQueryPlan<TContext>(
},
rootValue: data,
variableValues: requestContext.request.variables,
// We have a special field resolver which ensures we support aliases.
// FIXME: It's _possible_ this will change after `graphql-extensions` is
// deprecated, though not certain. See here, also: https://git.io/Jf8cS.
// See also `wrapSchemaWithAliasResolver` in `gateway-js/src/index.ts`.
fieldResolver: defaultFieldResolverWithAliasSupport,
}));
} catch (error) {
Expand Down
15 changes: 6 additions & 9 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,12 @@ export class ApolloGateway implements GraphQLService {

this.logger.debug('Schema loaded and ready for execution');

// FIXME: The comment below may change when `graphql-extensions` is
// removed, as it will be soon. It's not clear if this will be temporary,
// as is suggested, after that time, because we still very much need to
// do this special alias resolving. Original comment:
// this is a temporary workaround for GraphQLFieldExtensions automatic
// wrapping of all fields when using ApolloServer. Here we wrap all fields
// with support for resolving aliases as part of the root value which
// happens because aliases are resolved by sub services and the shape
// of the root value already contains the aliased fields as responseNames
// This is a workaround for automatic wrapping of all fields, which Apollo
// Server does in the case of implementing resolver wrapping for plugins.
// Here we wrap all fields with support for resolving aliases as part of the
// root value which happens because aliases are resolved by sub services and
// the shape of the root value already contains the aliased fields as
// responseNames
return { schema: wrapSchemaWithAliasResolver(schema), composedSdl };
}

Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"apollo-link": "1.2.14",
"apollo-link-http": "1.5.17",
"apollo-server": "2.17.0",
"apollo-server-core": "2.17.0",
"apollo-server-env": "2.4.5",
"apollo-server-testing": "2.17.0",
"apollo-server-types": "0.5.1",
"graphql-extensions": "0.12.4",
"bunyan": "1.8.14",
"codecov": "3.7.2",
"deep-freeze": "0.0.1",
Expand Down

0 comments on commit ff45cb7

Please sign in to comment.