Skip to content

Commit 8865339

Browse files
committed
Bugfix: Allow object arguments of any type
1 parent 03cb02d commit 8865339

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/queryBuilder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ export default class QueryBuilder {
103103
args = args ? JSON.parse(JSON.stringify(args)) : {};
104104
if (!args) throw new Error('args is undefined');
105105

106-
if (args[model.singularName] && typeof args[model.singularName] === 'object') {
107-
args[model.singularName] = { __type: upcaseFirstLetter(model.singularName) };
108-
}
106+
Object.keys(args).forEach((key: string) => {
107+
if (args && args[key] && typeof args[key] === 'object') {
108+
args[key] = { __type: upcaseFirstLetter(key) };
109+
}
110+
});
109111

110112
// multiple
111113
multiple = multiple === undefined ? !args['id'] : multiple;

test/unit/QueryBuilder.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,14 @@ query users {
463463

464464
describe('.buildQuery', () => {
465465
it('generates a complete query for a model', () => {
466-
const args = new Map();
467-
args.set('title', 'Example Post 1');
466+
const args = { title: 'Example Post 1' };
468467

469468
let query = queryBuilder.buildQuery('query', vuexOrmApollo.context.getModel('post'), null, args, true);
470469
query = QueryBuilder.prettify(query.loc.source.body);
471470

472471
expect(query).toEqual(`
473-
query Posts {
474-
posts {
472+
query Posts($title: String!) {
473+
posts(filter: {title: $title}) {
475474
nodes {
476475
id
477476
content

0 commit comments

Comments
 (0)