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

Commit

Permalink
Merge pull request #16 from rgraphql/master
Browse files Browse the repository at this point in the history
release: fix for nil field name
  • Loading branch information
paralin authored Mar 18, 2017
2 parents bad678f + aec3402 commit 6c2aa9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/jasmine": "^2.5.36",
"@types/lodash": "^4.14.50",
"@types/long": "^3.0.31",
"@types/node": "^7.0.0",
"@types/node": "^7.0.8",
"cz-conventional-changelog": "^2.0.0",
"istanbul": "^1.1.0-alpha.1",
"jasmine": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/query-tree/query-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('QueryTreeNode', () => {
let res = tree.buildRGQLTree(true);
expect(res).toEqual(<IRGQLQueryTreeNode>{
id: 0,
fieldName: null,
fieldName: '',
directive: [],
children: [{
id: 1,
Expand Down
12 changes: 5 additions & 7 deletions src/query-tree/query-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { Subject } from 'rxjs/Subject';

export class QueryTreeNode {
public id: number;
public fieldName: string = null;
public fieldName: string;
public alias: string;
public ast: FieldNode;
public isList = false;
Expand All @@ -58,7 +58,6 @@ export class QueryTreeNode {
public queryAdded: Subject<Query> = new Subject<Query>();
public queryRemoved: Subject<Query> = new Subject<Query>();

// TODO: Compute directives.
public directives: DirectiveNode[] = [];
public args: { [name: string]: IVariableReference };

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

if (ast && ast.name) {
this.fieldName = ast.name.value;
this.fieldName = ast.name.value || '';
}

if (!this.isRoot) {
Expand Down Expand Up @@ -169,7 +168,7 @@ export class QueryTreeNode {
let fp = this.fullPath;
let res: string[] = [];
for (let nod of fp) {
let nam = nod.fieldName;
let nam = nod.fieldName || '';
if (!nam) {
continue;
}
Expand Down Expand Up @@ -202,7 +201,7 @@ export class QueryTreeNode {
public buildRGQLTree(includeChildren = false): IRGQLQueryTreeNode {
let result: IRGQLQueryTreeNode = {
id: this.id,
fieldName: this.fieldName,
fieldName: this.fieldName || '',
directive: this.buildRGQLDirectives(),
};
if (this.ast && this.ast.arguments) {
Expand Down Expand Up @@ -448,7 +447,7 @@ export class QueryTreeNode {
if (!tchild.ast || tchild.ast.kind !== 'Field') {
continue;
}
let childName = tchild.alias || tchild.fieldName;
let childName = tchild.alias || tchild.fieldName || '';
if (childName === nodef.name.value) {
// Alias required.
let ai = this.aliasCounter++;
Expand Down Expand Up @@ -482,7 +481,6 @@ export class QueryTreeNode {
}

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

0 comments on commit 6c2aa9f

Please sign in to comment.