Skip to content

Commit bda6e82

Browse files
authored
Fixes#19 empty args object should not generate parentheses (#27)
1 parent fce99ed commit bda6e82

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/__tests__/arguments.tests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,19 @@ describe('jsonToGraphQLQuery() - arguments', () => {
161161
);
162162
});
163163

164+
it('Empty args object should not generate parentheses', () => {
165+
const query = {
166+
query: {
167+
Posts: {
168+
__args: {},
169+
id: true,
170+
title: true
171+
}
172+
}
173+
};
174+
expect(jsonToGraphQLQuery(query)).to.equal(
175+
'query { Posts { id title } }'
176+
);
177+
});
178+
164179
});

src/jsonToGraphQLQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function convertQuery(node: any, level: number, output: [string, number][], opti
9393
const fieldCount = Object.keys(value)
9494
.filter((keyCount) => filterNonConfigFields(keyCount, options.ignoreFields!)).length;
9595
const subFields = fieldCount > 0;
96-
const argsExist = typeof value.__args === 'object';
96+
const argsExist = typeof value.__args === 'object' && Object.keys(value.__args).length > 0;
9797
const directivesExist = typeof value.__directives === 'object';
9898
const fullFragmentsExist = value.__all_on instanceof Array;
9999
const partialFragmentsExist = typeof value.__on === 'object';

0 commit comments

Comments
 (0)