Skip to content

Commit 4681538

Browse files
Fix edge case for empty operations (#959)
Filter out 'undefined' definitions before checking the length. It's possible to leave a whole query behind when filtering by directive. In that case, we want to exclude it altogether. In the current state, definitions can === [undefined], giving a length of 1 and passing this check. By filtering for truthy values only, we won't include empty operations in the result of this function.
1 parent 8a0ef0e commit 4681538

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Upcoming
44

5+
- `apollo-language-server`
6+
- Fix edge case for empty operations [#959](https://github.com/apollographql/apollo-tooling/pull/959)
7+
58
## `apollo@2.4.1`
69

710
- `apollo` 2.4.1

packages/apollo-language-server/src/project/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,17 @@ export class GraphQLClientProject extends GraphQLProject {
350350
const filtered = Object.create(null);
351351
for (const operationName in current) {
352352
const document = current[operationName];
353+
353354
let serviceOnly: DocumentNode = removeDirectiveAnnotatedFields(
354355
removeDirectives(document, clientOnlyDirectives as string[]),
355356
clientSchemaDirectives as string[]
356357
);
358+
357359
if (addTypename)
358360
serviceOnly = withTypenameFieldAddedWhereNeeded(serviceOnly);
359-
if (serviceOnly.definitions.length) {
361+
// In the case we've made a document empty by filtering client directives,
362+
// we don't want to include that in the result we pass on.
363+
if (serviceOnly.definitions.filter(Boolean).length) {
360364
filtered[operationName] = serviceOnly;
361365
}
362366
}

0 commit comments

Comments
 (0)