Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit 6c2aa9f

Browse files
authored
Merge pull request #16 from rgraphql/master
release: fix for nil field name
2 parents bad678f + aec3402 commit 6c2aa9f

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@types/jasmine": "^2.5.36",
3333
"@types/lodash": "^4.14.50",
3434
"@types/long": "^3.0.31",
35-
"@types/node": "^7.0.0",
35+
"@types/node": "^7.0.8",
3636
"cz-conventional-changelog": "^2.0.0",
3737
"istanbul": "^1.1.0-alpha.1",
3838
"jasmine": "^2.5.0",

src/query-tree/query-tree.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('QueryTreeNode', () => {
8383
let res = tree.buildRGQLTree(true);
8484
expect(res).toEqual(<IRGQLQueryTreeNode>{
8585
id: 0,
86-
fieldName: null,
86+
fieldName: '',
8787
directive: [],
8888
children: [{
8989
id: 1,

src/query-tree/query-tree.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { Subject } from 'rxjs/Subject';
4242

4343
export class QueryTreeNode {
4444
public id: number;
45-
public fieldName: string = null;
45+
public fieldName: string;
4646
public alias: string;
4747
public ast: FieldNode;
4848
public isList = false;
@@ -58,7 +58,6 @@ export class QueryTreeNode {
5858
public queryAdded: Subject<Query> = new Subject<Query>();
5959
public queryRemoved: Subject<Query> = new Subject<Query>();
6060

61-
// TODO: Compute directives.
6261
public directives: DirectiveNode[] = [];
6362
public args: { [name: string]: IVariableReference };
6463

@@ -95,7 +94,7 @@ export class QueryTreeNode {
9594
(<any>this.root).rootNodeMap[this.id] = this;
9695

9796
if (ast && ast.name) {
98-
this.fieldName = ast.name.value;
97+
this.fieldName = ast.name.value || '';
9998
}
10099

101100
if (!this.isRoot) {
@@ -169,7 +168,7 @@ export class QueryTreeNode {
169168
let fp = this.fullPath;
170169
let res: string[] = [];
171170
for (let nod of fp) {
172-
let nam = nod.fieldName;
171+
let nam = nod.fieldName || '';
173172
if (!nam) {
174173
continue;
175174
}
@@ -202,7 +201,7 @@ export class QueryTreeNode {
202201
public buildRGQLTree(includeChildren = false): IRGQLQueryTreeNode {
203202
let result: IRGQLQueryTreeNode = {
204203
id: this.id,
205-
fieldName: this.fieldName,
204+
fieldName: this.fieldName || '',
206205
directive: this.buildRGQLDirectives(),
207206
};
208207
if (this.ast && this.ast.arguments) {
@@ -448,7 +447,7 @@ export class QueryTreeNode {
448447
if (!tchild.ast || tchild.ast.kind !== 'Field') {
449448
continue;
450449
}
451-
let childName = tchild.alias || tchild.fieldName;
450+
let childName = tchild.alias || tchild.fieldName || '';
452451
if (childName === nodef.name.value) {
453452
// Alias required.
454453
let ai = this.aliasCounter++;
@@ -482,7 +481,6 @@ export class QueryTreeNode {
482481
}
483482

484483
// Check if this is reasonably equivilent (same arguments, etc).
485-
// TODO: Simplify to use arguments array, remove this.ast completely
486484
private matchesAst(node: ASTNode): boolean {
487485
if (node.kind !== this.ast.kind) {
488486
return false;

0 commit comments

Comments
 (0)