Skip to content

Commit

Permalink
fix: revert bad Apollo Server "fix"
Browse files Browse the repository at this point in the history
Fix bad Apollo Server "fix"
  • Loading branch information
gajus committed Jul 22, 2019
2 parents dc2fa89 + 430fcc7 commit 309ea5b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,13 @@ class DeduplicateResponseExtension extends GraphQLExtension {
const { context, graphqlResponse } = o
// Ensures `?deduplicate=1` is used in the request
if (context.req.query.deduplicate && graphqlResponse.data && !graphqlResponse.data.__schema) {
const newResponse = deflate(graphqlResponse)
const data = deflate(graphqlResponse.data)
return {
...o,
graphqlResponse: newResponse,
graphqlResponse: {
...graphqlResponse,
data,
},
}
}

Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@
"test": "NODE_ENV=test nyc --reporter=text ava --verbose --serial"
},
"version": "1.0.0",
"dependencies": {
"is-plain-object": "^3.0.0"
}
"dependencies": {}
}
6 changes: 0 additions & 6 deletions src/deflate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @flow

import isPlainObject from 'is-plain-object';

// eslint-disable-next-line complexity
const deflate = (node: Object, index: Object, path: $ReadOnlyArray<string>) => {
if (node && node.id && node.__typename) {
Expand All @@ -26,10 +24,6 @@ const deflate = (node: Object, index: Object, path: $ReadOnlyArray<string>) => {
}
}

if (!isPlainObject(node)) {
return node;
}

const fieldNames = Object.keys(node);

const result = {};
Expand Down
15 changes: 0 additions & 15 deletions test/deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,3 @@ test('does not deconstruct an array of string', (t) => {
}
});
});

// https://github.com/gajus/graphql-deduplicator/issues/13
test('regression: does not change object types', (t) => {
const http = {
headers: new Map([['foo', 'bar']])
};
const response = {
http
};

const deflatedResponse: any = deflate(response);

t.true(deflatedResponse.http.headers instanceof Map);
t.deepEqual(deflatedResponse.http.headers.get('foo'), 'bar');
});

0 comments on commit 309ea5b

Please sign in to comment.