Skip to content

Commit 1ccdfd7

Browse files
committed
Bugfix
1 parent 135fc18 commit 1ccdfd7

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

dist/vuex-orm-graphql.esm.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21493,7 +21493,7 @@ var Logger = /** @class */ (function () {
2149321493
if (this.enabled) {
2149421494
try {
2149521495
var prettified = '';
21496-
if (isObject(query) && query.loc) {
21496+
if (isPlainObject(query) && query.loc) {
2149721497
prettified = prettify(query.loc.source.body);
2149821498
}
2149921499
else {
@@ -27834,14 +27834,20 @@ var Schema = /** @class */ (function () {
2783427834
Schema.returnsConnection = function (field) {
2783527835
return (Schema.getTypeNameOfField(field).endsWith('TypeConnection'));
2783627836
};
27837+
Schema.getRealType = function (type) {
27838+
if (type.kind === 'NON_NULL') {
27839+
return this.getRealType(type.ofType);
27840+
}
27841+
else {
27842+
return type;
27843+
}
27844+
};
2783727845
Schema.getTypeNameOfField = function (field) {
27838-
if (field.type.kind === 'LIST') {
27839-
return "[" + field.type.ofType.name + "]";
27846+
var type = this.getRealType(field.type);
27847+
if (type.kind === 'LIST') {
27848+
return "[" + type.ofType.name + "]";
2784027849
}
27841-
var name = field.type.name ||
27842-
field.type.ofType.name ||
27843-
field.type.ofType.ofType.name ||
27844-
field.type.ofType.ofType.name;
27850+
var name = type.name || type.ofType.name || type.ofType.ofType.name;
2784527851
if (!name)
2784627852
throw new Error("Can't find type name for field " + field.name);
2784727853
return name;
@@ -28114,7 +28120,7 @@ var QueryBuilder = /** @class */ (function () {
2811428120
if (!args)
2811528121
throw new Error('args is undefined');
2811628122
Object.keys(args).forEach(function (key) {
28117-
if (args && args[key] && isObject(args[key])) {
28123+
if (args && args[key] && isPlainObject(args[key])) {
2811828124
args[key] = { __type: upcaseFirstLetter(key) };
2811928125
}
2812028126
});
@@ -28179,7 +28185,7 @@ var QueryBuilder = /** @class */ (function () {
2817928185
if (value && !skipFieldDueId && !isConnectionField) {
2818028186
var typeOrValue = '';
2818128187
if (signature) {
28182-
if (isObject(value) && value.__type) {
28188+
if (isPlainObject(value) && value.__type) {
2818328189
// Case 2 (User!)
2818428190
typeOrValue = value.__type + 'Input!';
2818528191
}
@@ -29345,7 +29351,7 @@ var VuexORMGraphQL = /** @class */ (function () {
2934529351
var filterObj;
2934629352
return __generator$12(this, function (_a) {
2934729353
filterObj = filter;
29348-
if (!isObject(filterObj))
29354+
if (!isPlainObject(filterObj))
2934929355
filterObj = { id: filter };
2935029356
return [2 /*return*/, this.dispatch('fetch', { filter: filterObj, bypassCache: bypassCache })];
2935129357
});

src/common/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default class Logger {
8888
if (this.enabled) {
8989
try {
9090
let prettified = '';
91-
if (_.isObject(query) && (query as DocumentNode).loc) {
91+
if (_.isPlainObject(query) && (query as DocumentNode).loc) {
9292
prettified = prettify((query as DocumentNode).loc!.source.body);
9393
} else {
9494
prettified = prettify(query as string);

src/graphql/query-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default class QueryBuilder {
110110
if (!args) throw new Error('args is undefined');
111111

112112
Object.keys(args).forEach((key: string) => {
113-
if (args && args[key] && _.isObject(args[key])) {
113+
if (args && args[key] && _.isPlainObject(args[key])) {
114114
args[key] = { __type: upcaseFirstLetter(key) };
115115
}
116116
});
@@ -182,7 +182,7 @@ export default class QueryBuilder {
182182
let typeOrValue: any = '';
183183

184184
if (signature) {
185-
if (_.isObject(value) && value.__type) {
185+
if (_.isPlainObject(value) && value.__type) {
186186
// Case 2 (User!)
187187
typeOrValue = value.__type + 'Input!';
188188
} else if (_.isArray(value) && field) {

src/graphql/schema.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GraphQLField, GraphQLSchema, GraphQLType } from '../support/interfaces';
1+
import { GraphQLField, GraphQLSchema, GraphQLType, GraphQLTypeDefinition } from '../support/interfaces';
22
import { upcaseFirstLetter } from '../support/utils';
33

44
export default class Schema {
@@ -73,15 +73,22 @@ export default class Schema {
7373
return (Schema.getTypeNameOfField(field).endsWith('TypeConnection'));
7474
}
7575

76+
static getRealType (type: GraphQLTypeDefinition): GraphQLTypeDefinition {
77+
if (type.kind === 'NON_NULL') {
78+
return this.getRealType(type.ofType);
79+
} else {
80+
return type;
81+
}
82+
}
83+
7684
static getTypeNameOfField (field: GraphQLField): string {
77-
if (field.type.kind === 'LIST') {
78-
return `[${field.type.ofType.name}]`;
85+
const type = this.getRealType(field.type);
86+
87+
if (type.kind === 'LIST') {
88+
return `[${type.ofType.name}]`;
7989
}
8090

81-
const name = field.type.name ||
82-
field.type.ofType.name ||
83-
field.type.ofType.ofType.name ||
84-
field.type.ofType.ofType.name;
91+
const name = type.name || type.ofType.name || type.ofType.ofType.name;
8592

8693
if (!name) throw new Error(`Can't find type name for field ${field.name}`);
8794

src/vuex-orm-graphql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class VuexORMGraphQL {
4949
// Register static model convenience methods
5050
(context.components.Model as (typeof PatchedModel)).fetch = async function (filter: any, bypassCache = false) {
5151
let filterObj = filter;
52-
if (!_.isObject(filterObj)) filterObj = { id: filter };
52+
if (!_.isPlainObject(filterObj)) filterObj = { id: filter };
5353
return this.dispatch('fetch', { filter: filterObj, bypassCache });
5454
};
5555

test/support/mock-schema.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const typeDefs = `
5353
5454
upvotePost(captchaToken: String!, id: ID!): Post!
5555
sendSms(to: String!, text: String!): SmsStatus!
56+
reorderItems(id: ID!, itemIds: [ID]!): PostTypeConnection
5657
}
5758
5859
type Status {
@@ -134,7 +135,6 @@ export const typeDefs = `
134135
title: String
135136
userId: ID
136137
otherId: ID
137-
crazyIDList: [ID]
138138
published: Boolean
139139
user: User
140140
comments: CommentTypeConnection
@@ -145,7 +145,6 @@ export const typeDefs = `
145145
id: ID
146146
content: String
147147
title: String
148-
crazyIDList: [ID]
149148
userId: ID
150149
otherId: ID
151150
published: Boolean
@@ -157,7 +156,6 @@ export const typeDefs = `
157156
id: ID
158157
content: String
159158
title: String
160-
crazyIDList: [ID]
161159
userId: ID
162160
otherId: ID
163161
published: Boolean
@@ -400,7 +398,6 @@ const posts = [
400398
content: 'GraphQL is so nice!',
401399
title: 'GraphQL',
402400
otherId: 123,
403-
crazyIDList: [1, 2, 3],
404401
published: true,
405402
userId: 1
406403
},
@@ -410,7 +407,6 @@ const posts = [
410407
content: 'Vue is so awesome!',
411408
title: 'Vue.js',
412409
otherId: 435,
413-
crazyIDList: [4, 5],
414410
published: true,
415411
userId: 3
416412
},
@@ -420,7 +416,6 @@ const posts = [
420416
content: 'Vuex-ORM is so crisp',
421417
title: 'Vuex-ORM',
422418
otherId: 987,
423-
crazyIDList: [6],
424419
published: false,
425420
userId: 3
426421
}

test/unit/QueryBuilder.spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ describe('QueryBuilder', () => {
2424
otherId: 18,
2525
userId: 5,
2626
user: { __type: 'User' },
27-
crazyIDList: [1, 2, 4, 9, 68],
2827
comments: [{
2928
id: 1,
3029
content: 'test'
3130
}]
3231
}, true, false, false);
3332

34-
expect(args).toEqual('($content: String!, $title: String!, $otherId: ID!, $user: UserInput!, ' +
35-
'$crazyIDList: [ID]!)');
33+
expect(args).toEqual('($content: String!, $title: String!, $otherId: ID!, $user: UserInput!)');
34+
35+
36+
37+
args = QueryBuilder.buildArguments(model, {
38+
id: 5,
39+
itemIds: [1, 2, 4, 9, 68]
40+
}, true, false, true, context.schema.getMutation('reorderItems'));
41+
42+
expect(args).toEqual('($id: ID!, $itemIds: [ID]!)');
3643
});
3744

3845
it('can generate fields with variables', () => {

0 commit comments

Comments
 (0)