Skip to content

Commit c817852

Browse files
committed
Lint fixes
1 parent 5b35157 commit c817852

File tree

6 files changed

+68
-81
lines changed

6 files changed

+68
-81
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8135,14 +8135,12 @@ var QueryBuilder = /** @class */ (function () {
81358135
if (signature === void 0) { signature = false; }
81368136
if (valuesAsVariables === void 0) { valuesAsVariables = false; }
81378137
var returnValue = '';
8138-
var any = false;
81398138
var first = true;
81408139
if (args) {
81418140
Object.keys(args).forEach(function (key) {
81428141
var value = args[key];
81438142
// Ignore ids and connections
81448143
if (!(value instanceof Array || key === 'id')) {
8145-
any = true;
81468144
var typeOrValue = '';
81478145
if (signature) {
81488146
if (typeof value === 'object' && value.__type) {
@@ -8172,7 +8170,7 @@ var QueryBuilder = /** @class */ (function () {
81728170
first = false;
81738171
}
81748172
});
8175-
if (any)
8173+
if (!first)
81768174
returnValue = "(" + returnValue + ")";
81778175
}
81788176
return returnValue;
@@ -8346,11 +8344,11 @@ var Logger = /** @class */ (function () {
83468344
/**
83478345
* Capitalizes the first letter of the given string.
83488346
*
8349-
* @param {string} string
8347+
* @param {string} input
83508348
* @returns {string}
83518349
*/
8352-
function capitalizeFirstLetter(string) {
8353-
return string.charAt(0).toUpperCase() + string.slice(1);
8350+
function capitalizeFirstLetter(input) {
8351+
return input.charAt(0).toUpperCase() + input.slice(1);
83548352
}
83558353

83568354
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -8433,6 +8431,20 @@ var VuexORMApollo = /** @class */ (function () {
84338431
VuexORMApollo.install = function (components, options) {
84348432
return new VuexORMApollo(components, options);
84358433
};
8434+
/**
8435+
* Returns a model by name
8436+
*
8437+
* @param {Model|string} model
8438+
* @returns {Model}
8439+
*/
8440+
VuexORMApollo.prototype.getModel = function (model) {
8441+
if (!(model instanceof Model)) {
8442+
model = this.models.get(inflection$2.singularize(model));
8443+
if (!model)
8444+
throw new Error("No such model " + model + "!");
8445+
}
8446+
return model;
8447+
};
84368448
/**
84378449
* Wraps all Vuex-ORM entities in a Model object and saves them into this.models
84388450
*/
@@ -8450,8 +8462,8 @@ var VuexORMApollo = /** @class */ (function () {
84508462
this.components.subActions.fetch = this.fetch.bind(this);
84518463
this.components.subActions.persist = this.persist.bind(this);
84528464
this.components.subActions.push = this.push.bind(this);
8453-
//this.components.subActions.destroy = this.destroy.bind(this);
8454-
//this.components.subActions.destroyAll = this.destroyAll.bind(this);
8465+
// this.components.subActions.destroy = this.destroy.bind(this);
8466+
// this.components.subActions.destroyAll = this.destroyAll.bind(this);
84558467
};
84568468
/**
84578469
* Will be called, when dispatch('entities/something/fetch') is called.
@@ -8506,8 +8518,8 @@ var VuexORMApollo = /** @class */ (function () {
85068518
this.logger.logQuery(query);
85078519
delete data.id;
85088520
return [4 /*yield*/, this.apolloClient.mutate({
8509-
"mutation": src(query),
8510-
"variables": (_c = {}, _c[model.singularName] = this.queryBuilder.transformOutgoingData(data), _c)
8521+
'mutation': src(query),
8522+
'variables': (_c = {}, _c[model.singularName] = this.queryBuilder.transformOutgoingData(data), _c)
85118523
})];
85128524
case 1:
85138525
newData = _d.sent();
@@ -8557,20 +8569,6 @@ var VuexORMApollo = /** @class */ (function () {
85578569
dispatch('create', { data: data[key] });
85588570
});
85598571
};
8560-
/**
8561-
* Returns a model by name
8562-
*
8563-
* @param {Model|string} model
8564-
* @returns {Model}
8565-
*/
8566-
VuexORMApollo.prototype.getModel = function (model) {
8567-
if (!(model instanceof Model)) {
8568-
model = this.models.get(inflection$2.singularize(model));
8569-
if (!model)
8570-
throw new Error("No such model " + model + "!");
8571-
}
8572-
return model;
8573-
};
85748572
return VuexORMApollo;
85758573
}());
85768574

src/index.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory';
55
import gql from 'graphql-tag';
66
import { Data, ActionParams, Field, Arguments, ORMModel } from './interfaces';
77
import Logger from './logger';
8-
import { FetchResult } from "apollo-link";
8+
import { FetchResult } from 'apollo-link';
99
import QueryBuilder from './queryBuilder';
1010
import { capitalizeFirstLetter } from './utils';
1111

@@ -71,6 +71,21 @@ export default class VuexORMApollo {
7171
return new VuexORMApollo(components, options);
7272
}
7373

74+
/**
75+
* Returns a model by name
76+
*
77+
* @param {Model|string} model
78+
* @returns {Model}
79+
*/
80+
public getModel (model: Model | string): Model {
81+
if (!(model instanceof Model)) {
82+
model = this.models.get(inflection.singularize(model)) as Model;
83+
if (!model) throw new Error(`No such model ${model}!`);
84+
}
85+
86+
return model;
87+
}
88+
7489
/**
7590
* Wraps all Vuex-ORM entities in a Model object and saves them into this.models
7691
*/
@@ -89,8 +104,8 @@ export default class VuexORMApollo {
89104

90105
this.components.subActions.persist = this.persist.bind(this);
91106
this.components.subActions.push = this.push.bind(this);
92-
//this.components.subActions.destroy = this.destroy.bind(this);
93-
//this.components.subActions.destroyAll = this.destroyAll.bind(this);
107+
// this.components.subActions.destroy = this.destroy.bind(this);
108+
// this.components.subActions.destroyAll = this.destroyAll.bind(this);
94109
}
95110

96111
/**
@@ -125,15 +140,14 @@ export default class VuexORMApollo {
125140
const model = this.getModel(state.$name);
126141
const name = `create${capitalizeFirstLetter(model.singularName)}`;
127142

128-
129143
const data = model.baseModel.getters('find', { id })();
130144

131145
// Send the request to the GraphQL API
132-
const signature = this.queryBuilder.buildArguments({contract: {__type: 'Contract'}}, true);
146+
const signature = this.queryBuilder.buildArguments({ contract: { __type: 'Contract' } }, true);
133147

134148
const query = `
135149
mutation ${name}${signature} {
136-
${this.queryBuilder.buildField(model, false, {contract: {__type: 'Contract'}}, true, undefined, name)}
150+
${this.queryBuilder.buildField(model, false, { contract: { __type: 'Contract' } }, true, undefined, name)}
137151
}
138152
`;
139153

@@ -143,22 +157,20 @@ export default class VuexORMApollo {
143157

144158
// Send GraphQL Mutation
145159
const newData = await this.apolloClient.mutate({
146-
"mutation": gql(query),
147-
"variables": {
160+
'mutation': gql(query),
161+
'variables': {
148162
[model.singularName]: this.queryBuilder.transformOutgoingData(data)
149163
}
150164
});
151165

152-
153166
// Insert incoming data into the store
154167
this.storeData(newData, dispatch);
155168

156169
return newData;
157170
}
158171

159-
160-
private async push({ state, dispatch }: ActionParams, { id }: ActionParams) {
161-
172+
private async push ({ state, dispatch }: ActionParams, { id }: ActionParams) {
173+
// TODO
162174
}
163175

164176
/**
@@ -184,19 +196,4 @@ export default class VuexORMApollo {
184196
dispatch('create', { data: data[key] });
185197
});
186198
}
187-
188-
/**
189-
* Returns a model by name
190-
*
191-
* @param {Model|string} model
192-
* @returns {Model}
193-
*/
194-
public getModel (model: Model|string): Model {
195-
if (!(model instanceof Model)) {
196-
model = this.models.get(inflection.singularize(model)) as Model;
197-
if (!model) throw new Error(`No such model ${model}!`);
198-
}
199-
200-
return model;
201-
}
202199
}

src/interfaces.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Model from "./model";
1+
import Model from './model';
22

33
export interface ActionParams {
44
commit: any;
@@ -9,7 +9,7 @@ export interface ActionParams {
99
state: any;
1010
filter?: Filter;
1111
data?: Data;
12-
id?: string|number
12+
id?: string | number;
1313
}
1414

1515
export interface Data {
@@ -28,8 +28,8 @@ export interface ORMModel {
2828
entity: string;
2929

3030
fields (): any;
31-
dispatch(name: string, ...params: Array<any>): any;
32-
getters(name: string, ...params: Array<any>): any;
31+
dispatch (name: string, ...params: Array<any>): any;
32+
getters (name: string, ...params: Array<any>): any;
3333
}
3434

3535
export interface Field {

src/logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import QueryBuilder from './queryBuilder';
2-
import {DocumentNode} from "graphql";
2+
import { DocumentNode } from 'graphql';
33

44
export default class Logger {
55
private readonly enabled: boolean;
@@ -24,19 +24,19 @@ export default class Logger {
2424
}
2525
}
2626

27-
public logQuery(query: string|DocumentNode) {
27+
public logQuery (query: string | DocumentNode) {
2828
if (this.enabled) {
2929
try {
3030
this.group('Sending query:');
3131

3232
if (typeof query === 'object' && query.loc) {
3333
console.log(QueryBuilder.prettify(query.loc.source.body));
3434
} else {
35-
console.log(QueryBuilder.prettify(<string>query));
35+
console.log(QueryBuilder.prettify(query as string));
3636
}
3737

3838
this.groupEnd();
39-
} catch(e) {
39+
} catch (e) {
4040
console.error('[Vuex-ORM-Apollo] There is a syntax error in the query!', e, query);
4141
}
4242
}

src/queryBuilder.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
import { print } from 'graphql/language/printer';
22
import { parse } from 'graphql/language/parser';
3-
import {Arguments, Data, Field} from "./interfaces";
4-
import Model from "./model";
5-
import gql from "graphql-tag";
6-
import Logger from "./logger";
3+
import { Arguments, Data, Field } from './interfaces';
4+
import Model from './model';
5+
import gql from 'graphql-tag';
6+
import Logger from './logger';
77
const inflection = require('inflection');
88

9-
109
/**
1110
* This class takes care of everything GraphQL query related, especially the generation of queries out of models
1211
*/
1312
export default class QueryBuilder {
1413
private readonly logger: Logger;
15-
private readonly getModel: (name: Model|string) => Model;
16-
14+
private readonly getModel: (name: Model | string) => Model;
1715

1816
/**
1917
* Constructor.
2018
* @param {Logger} logger
2119
* @param {(name: (Model | string)) => Model} getModel
2220
*/
23-
public constructor(logger: Logger, getModel: (name: Model|string) => Model) {
21+
public constructor (logger: Logger, getModel: (name: Model | string) => Model) {
2422
this.logger = logger;
2523
this.getModel = getModel;
2624
}
2725

28-
2926
/**
3027
* Takes a string with a graphql query and formats it
3128
* @param {string} query
3229
* @returns {string}
3330
*/
34-
public static prettify(query: string): string {
31+
public static prettify (query: string): string {
3532
return print(parse(query));
3633
}
3734

38-
3935
/**
4036
* Generates the arguments string for a graphql query based on a given map.
4137
*
@@ -62,11 +58,10 @@ export default class QueryBuilder {
6258
* variables instead of values
6359
* @returns {String}
6460
*/
65-
public buildArguments(args: Arguments | undefined,
61+
public buildArguments (args: Arguments | undefined,
6662
signature: boolean = false,
6763
valuesAsVariables: boolean = false): string {
6864
let returnValue: string = '';
69-
let any: boolean = false;
7065
let first: boolean = true;
7166

7267
if (args) {
@@ -75,7 +70,6 @@ export default class QueryBuilder {
7570

7671
// Ignore ids and connections
7772
if (!(value instanceof Array || key === 'id')) {
78-
any = true;
7973
let typeOrValue: any = '';
8074

8175
if (signature) {
@@ -104,13 +98,12 @@ export default class QueryBuilder {
10498
}
10599
});
106100

107-
if (any) returnValue = `(${returnValue})`;
101+
if (!first) returnValue = `(${returnValue})`;
108102
}
109103

110104
return returnValue;
111105
}
112106

113-
114107
/**
115108
* Transforms outgoing data. Use for variables param.
116109
*
@@ -119,7 +112,7 @@ export default class QueryBuilder {
119112
* @param {Data} data
120113
* @returns {Data}
121114
*/
122-
public transformOutgoingData(data: Data): Data {
115+
public transformOutgoingData (data: Data): Data {
123116
const model: Model = this.getModel(data.$self().entity);
124117
const relations: Map<string, Field> = model.getRelations();
125118
const returnValue: Data = {};
@@ -136,7 +129,6 @@ export default class QueryBuilder {
136129
return returnValue;
137130
}
138131

139-
140132
/**
141133
* Transforms a set of incoming data to the format vuex-orm requires.
142134
*
@@ -209,7 +201,7 @@ export default class QueryBuilder {
209201
* @param {string} name
210202
* @returns {string}
211203
*/
212-
public buildField (model: Model|string, multiple: boolean = true, args?: Arguments, withVars: boolean = false, rootModel?: Model, name?: string): string {
204+
public buildField (model: Model | string, multiple: boolean = true, args?: Arguments, withVars: boolean = false, rootModel?: Model, name?: string): string {
213205
model = this.getModel(model);
214206

215207
let params: string = this.buildArguments(args, false, withVars);

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Capitalizes the first letter of the given string.
33
*
4-
* @param {string} string
4+
* @param {string} input
55
* @returns {string}
66
*/
7-
export function capitalizeFirstLetter(string: string) {
8-
return string.charAt(0).toUpperCase() + string.slice(1);
7+
export function capitalizeFirstLetter (input: string) {
8+
return input.charAt(0).toUpperCase() + input.slice(1);
99
}

0 commit comments

Comments
 (0)