Skip to content

Commit

Permalink
Changed repository configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahincalan authored and ahincalan committed Jan 26, 2019
1 parent 20c9e77 commit b740320
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "gql-builder",
"version": "0.0.1",
"description": "Graphql Query Builder",
"main": "src/index.js",
"types": "src/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"directories": {
"src/test": "src/test"
},
Expand All @@ -13,7 +13,7 @@
"cover2": "nyc --reporter html --reporter text npm run test",
"cover": "nyc --reporter html --reporter text -r lcov -e .ts -x \"*.test.ts\" mocha -r ts-node/register src/test/**/*.test.ts && nyc report",
"build": "tsc",
"travis-cover": "nyc --reporter html --reporter text --reporter lcovonly -r lcov -e .ts -x \"*.test.ts\" mocha -r ts-node/register src/test/**/*.test.ts && nyc report",
"travis-cover": "nyc --reporter lcovonly -r lcov -e .ts -x \"*.test.ts\" mocha -r ts-node/register src/test/**/*.test.ts && nyc report",
"travis-cover2": "nyc --reporter lcovonly npm run test"
},
"repository": {
Expand All @@ -32,8 +32,6 @@
},
"homepage": "https://github.com/ahincalan/gql-builder#readme",
"dependencies": {
"D": "^1.0.0",
"tslint-config-airbnb": "^5.11.1"
},
"devDependencies": {
"@types/chai": "^4.1.7",
Expand All @@ -43,6 +41,8 @@
"nyc": "^13.1.0",
"ts-node": "^8.0.1",
"typescript": "^3.2.4",
"coveralls": "^3.0.2"
"coveralls": "^3.0.2",
"D": "^1.0.0",
"tslint-config-airbnb": "^5.11.1"
}
}
20 changes: 10 additions & 10 deletions src/lib/GqlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class GqlBuilder extends QueryField {
private _filterToString(): string {
let str = '';
for (const filter in this.filters) {
// if (this.filters.hasOwnProperty(filter)) {
if (this.filters.hasOwnProperty(filter)) {
if (typeof this.filters[filter] === 'string') {
if (str !== '') str += ',\n';
str += '$' + filter + ' : ' + this.filters[filter];
Expand All @@ -34,40 +34,40 @@ export class GqlBuilder extends QueryField {
}
}
}
// }
}
}
return (str ? '(' + str + ')' : '');
}

private _setFilters(fields?: any): void {
for (const key in fields) {
// if (fields.hasOwnProperty(key)) {
if (fields.hasOwnProperty(key)) {
if (fields[key].filters)
this.filters = {...this.filters, ...fields[key].filters};
if (fields[key].fields && Object.keys(fields[key].fields).length > 0) {
this._setFilters(fields[key].fields);
}
// }
}
}
}

private _setDepth(fields?: any): void {
for (const key in fields) {
// if (fields.hasOwnProperty(key)) {
if (fields.hasOwnProperty(key)) {
if (fields[key].parent)
fields[key].depth = fields[key].parent.depth + 1;
if (fields[key].fields && Object.keys(fields[key].fields).length > 0) {
this._setDepth(fields[key].fields);
}
// }
}
}
}


private _addFilterString(filters: any): string {
let ret = '';
for (const filter in filters) {
// if (filters.hasOwnProperty(filter)) {
if (filters.hasOwnProperty(filter)) {
if (typeof filters[filter] === 'string') {
if (ret !== '') ret += ',';
ret += filter + ': $' + filter;
Expand All @@ -84,7 +84,7 @@ export class GqlBuilder extends QueryField {
ret += sf;
ret += '}';
}
// }
}
}
if (Object.keys(filters).length > 0)
ret = '( ' + ret + ' ) ';
Expand All @@ -96,7 +96,7 @@ export class GqlBuilder extends QueryField {
const _fields = fields || this.fields;
let _ret = ret || '';
for (const key in _fields) {
// if (_fields.hasOwnProperty(key)) {
if (_fields.hasOwnProperty(key)) {
if (_fields[key].fields && Object.keys(_fields[key].fields).length > 0) {
let tt2 = '';
for (let j = 0; j <= _fields[key].depth; j++) tt2 += '\t';
Expand All @@ -114,7 +114,7 @@ export class GqlBuilder extends QueryField {
if (_fields[key].filters)
_ret += this._addFilterString(_fields[key].filters);
}
// }
}
}
return _ret;
}
Expand Down
29 changes: 19 additions & 10 deletions src/lib/QueryField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export class QueryField {
filters: any = {};
parent: any;
depth = 0;
name: string;
name: string = '';

constructor() {
this.name = '';

}

addSibling(value: any, fields?: any, filters?: any): QueryField {
Expand All @@ -30,8 +30,9 @@ export class QueryField {
} else if (value[i].constructor === Object) {
if (!value[i].name) {
throw "Not found name property";
} else {
this.addChild(value[i].name, value[i].fields, value[i].filters);
}
this.addChild(value[i].name, value[i].fields, value[i].filters);
} else {
throw "Not supported field type";
}
Expand All @@ -44,8 +45,9 @@ export class QueryField {
} else if (value.constructor === Object) {
if (!value.name) {
throw "Not found name property";
} else {
this.addChild(value.name, value.fields, value.filters);
}
this.addChild(value.name, value.fields, value.filters);

}
return this;
Expand Down Expand Up @@ -74,17 +76,19 @@ export class QueryField {
else if (fields[i].constructor === Object) {
if (!fields[i].name) {
throw "Not found name property";
} else {
this.parent.fields[value].addParent(fields[i].name, fields[i].fields, fields[i].filters);
}
this.parent.fields[value].addParent(fields[i].name, fields[i].fields, fields[i].filters);
}
}
} else if (typeof fields === 'string') {
this.parent.fields[value].addParent(fields);
} else if (fields.constructor === Object) {
if (!fields.name) {
throw "Not found name property";
} else {
this.parent.fields[value].addParent(fields.name, fields.fields, fields.filters);
}
this.parent.fields[value].addParent(fields.name, fields.fields, fields.filters);
}
}
this.parent.fields[value].parent = this.parent;
Expand All @@ -103,17 +107,19 @@ export class QueryField {
else if (fields[i].constructor === Object) {
if (!fields[i].name) {
throw "Not found name property";
} else {
this.fields[value].addParent(fields[i].name, fields[i].fields, fields[i].filters);
}
this.fields[value].addParent(fields[i].name, fields[i].fields, fields[i].filters);
}
}
} else if (typeof fields === 'string') {
this.fields[value].addParent(fields);
} else if (fields.constructor === Object) {
if (!fields.name) {
throw "Not found name property";
} else {
this.fields[value].addParent(fields.name, fields.fields, fields.filters);
}
this.fields[value].addParent(fields.name, fields.fields, fields.filters);
}
}
this.fields[value].parent = this;
Expand All @@ -140,23 +146,26 @@ export class QueryField {
this.fields[value] = new QueryField();
if (fields) {
if (fields.constructor === Array) {

for (let i = 0; i < fields.length; i++) {
if (typeof fields[i] === 'string') {
this.fields[value].addChild(fields[i]);
} else if (fields[i].constructor === Object) {
if (!fields[i].name) {
throw "Not found name property";
} else {
this.fields[value].addChild(fields[i].name, fields[i].fields, fields[i].filters);
}
this.fields[value].addChild(fields[i].name, fields[i].fields, fields[i].filters);
}
}
} else if (typeof fields === 'string') {
this.fields[value].addChild(fields);
} else if (fields.constructor === Object) {
if (!fields.name) {
throw "Not found name property";
} else {
this.fields[value].addChild(fields.name, fields.fields, fields.filters);
}
this.fields[value].addChild(fields.name, fields.fields, fields.filters);
}
}
this.fields[value].parent = this;
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"sourceMap": true,
/* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "dist",
"outDir": "./dist",
/* Redirect output structure to the directory. */
"rootDir": "src",
"rootDir": "./src",
/* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
Expand Down

0 comments on commit b740320

Please sign in to comment.