Skip to content

Commit

Permalink
Remove apollo-graphql dependency (#68)
Browse files Browse the repository at this point in the history
This commit removes the apollo-graphql dependency, which doesn't
support graphql@^16 versions. We have equivalent functions in
the apollo-utils monorepo which don't have that limitation. This
change ought to have happened when those functions were originally
introduced, so the need for this change is completely expected.
  • Loading branch information
trevor-scheer authored Jun 1, 2022
1 parent 71ae0b8 commit c585bf2
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-steaks-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/server-plugin-operation-registry': patch
---

Remove the apollo-graphql dependency in favor of equivalent apollo-utils deps
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ workflows:
- "12"
- "14"
- "16"
- "17"
- "18"
- Prettier
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*.md

dist/

.volta
114 changes: 64 additions & 50 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"typescript": "4.7.2"
},
"dependencies": {
"apollo-graphql": "^0.9.5",
"@apollo/utils.createhash": "^1.1.0",
"@apollo/utils.operationregistrysignature": "^1.1.0",
"apollo-server-caching": "^3.3.0",
"apollo-server-env": "^4.2.1",
"apollo-server-errors": "^3.3.1",
Expand All @@ -56,6 +57,9 @@
"loglevel": "^1.8.0",
"make-fetch-happen": "^8.0.9"
},
"peerDependencies": {
"graphql": "14.x || 15.x || 16.x"
},
"volta": {
"node": "16.15.0",
"npm": "8.11.0"
Expand Down
23 changes: 9 additions & 14 deletions src/ApolloServerPluginOperationRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { pluginName, getStoreKey, signatureForLogging } from './common';
import {
pluginName,
getStoreKey,
signatureForLogging,
operationHash,
} from './common';
import type {
ApolloServerPlugin,
GraphQLServiceContext,
GraphQLRequestListener,
GraphQLRequestContext,
GraphQLServerListener,
} from 'apollo-server-plugin-base';
import {
/**
* We alias these to different names entirely since the user-facing values
* which are present in their manifest (signature and document) are probably
* the most important concepts to rally around right now, in terms of
* approachability to the implementor. A future version of the
* `apollo-graphql` package should rename them to make this more clear.
*/
operationHash as operationSignature,
defaultOperationRegistrySignature as defaultOperationRegistryNormalization,
} from 'apollo-graphql';
import { operationRegistrySignature } from '@apollo/utils.operationregistrysignature';
import { ForbiddenError, ApolloError } from 'apollo-server-errors';
import Agent from './agent';
import { InMemoryLRUCache } from 'apollo-server-caching';
Expand Down Expand Up @@ -151,7 +146,7 @@ for observability purposes, but all operations will be permitted.`,
throw new Error('Unable to access store.');
}

const normalizedDocument = defaultOperationRegistryNormalization(
const normalizedDocument = operationRegistrySignature(
documentFromRequestContext,

// XXX The `operationName` is set from the AST, not from the
Expand All @@ -167,7 +162,7 @@ for observability purposes, but all operations will be permitted.`,
requestContext.operationName || '',
);

const signature = operationSignature(normalizedDocument);
const signature = operationHash(normalizedDocument);

if (!signature) {
throw new ApolloError('No document.');
Expand Down
18 changes: 4 additions & 14 deletions src/__tests__/ApolloServerPluginOperationRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ import {
ApolloServerBase,
ApolloServerPluginUsageReportingDisabled,
} from 'apollo-server-core';

import {
/**
* We alias these to different names entirely since the user-facing values
* which are present in their manifest (signature and document) are probably
* the most important concepts to rally around right now, in terms of
* approachability to the implementor. A future version of the
* `apollo-graphql` package should rename them to make this more clear.
*/
defaultOperationRegistrySignature as defaultOperationRegistryNormalization,
operationHash as operationSignature,
} from 'apollo-graphql';
import { operationRegistrySignature } from '@apollo/utils.operationregistrysignature';
import { operationHash } from '../common';
import gql from 'graphql-tag';
import { print } from 'graphql';
import loglevel from 'loglevel';
Expand Down Expand Up @@ -80,11 +70,11 @@ describe('Operation registry plugin', () => {
}
`;

const normalizedQueryDocument = defaultOperationRegistryNormalization(
const normalizedQueryDocument = operationRegistrySignature(
query,
'HelloFam',
);
const queryHash = operationSignature(normalizedQueryDocument);
const queryHash = operationHash(normalizedQueryDocument);

describe('onUnregisterOperation', () => {
it('is called when unregistered operation received', async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createHash } from '@apollo/utils.createhash';

export const pluginName: string = require('../package.json').name;

export const envOverrideOperationManifest =
Expand Down Expand Up @@ -48,3 +50,7 @@ export function signatureForLogging(signature: string): string {
}
return signature.substring(0, 8);
}

export function operationHash(operation: string) {
return createHash('sha256').update(operation).digest('hex');
}

0 comments on commit c585bf2

Please sign in to comment.