Skip to content

Commit

Permalink
fix: handle empty query in plan (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin authored Sep 25, 2024
1 parent 3bc8035 commit 37af012
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
5 changes: 4 additions & 1 deletion playground/src/components/playground/plan-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,17 @@ export const PlanView = () => {
// Match keywords followed by (service
[/\b(\w+)(?=\s*\(service)/, 'keyword'],

// Match Flatten followed by (path
[/\b(Flatten)(?=\s*\(path)/, 'keyword'],

// Match Sequence, Parallel, Single followed by {
[/\b(QueryPlan|Sequence|Parallel)(?=\s*{)/, 'keyword'],

// Match keywords followed by { with previous line ending in }
[/(?<=}\s*\n\s*)(\w+)/, 'keyword'],

// Match service declarations: service: "serviceName"
[/(service)(\s*:\s*)("[^"]*")/, ['identifier', '', 'string.service']],
[/(service|path)(\s*:\s*)("[^"]*")/, ['identifier', '', 'string.service']],

// Match variables: $variableName
[/\$[a-zA-Z_]\w*/, 'variable'],
Expand Down
9 changes: 6 additions & 3 deletions playground/src/components/playground/prettyPrint.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { QueryPlanFetchNode, QueryPlanFetchTypeNode, Representation } from './types';
import { QueryPlan, QueryPlanFetchNode, QueryPlanFetchTypeNode, Representation } from './types';

export class PlanPrinter {
depth: number = 0;
buf: string[] = [];

print(plan: QueryPlanFetchTypeNode): string {
print(plan: QueryPlan): string {
this.buf = [];
this.printText('QueryPlan {');
this.printPlanNode(plan, true);
Expand Down Expand Up @@ -57,7 +57,10 @@ export class PlanPrinter {
if (fetch.representations) {
this.printRepresentations(fetch.representations);
}
this.printQuery(fetch.query);

if (fetch.query) {
this.printQuery(fetch.query);
}

this.depth--;
this.printText('}');
Expand Down
2 changes: 1 addition & 1 deletion playground/src/components/playground/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type QueryPlanFetchNode = {
kind: string;
subgraphName: string;
subgraphId: string;
query: string;
query?: string;
path?: string;
representations?: Representation[];
};
Expand Down
2 changes: 1 addition & 1 deletion router/internal/graphiql/graphiql.html

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion studio/src/components/playground/plan-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ export const PlanView = () => {
// Match keywords followed by (service
[/\b(\w+)(?=\s*\(service)/, "keyword"],

// Match Flatten followed by (path
[/\b(Flatten)(?=\s*\(path)/, "keyword"],

// Match Sequence, Parallel, Single followed by {
[/\b(QueryPlan|Sequence|Parallel)(?=\s*{)/, "keyword"],

Expand All @@ -214,7 +217,7 @@ export const PlanView = () => {

// Match service declarations: service: "serviceName"
[
/(service)(\s*:\s*)("[^"]*")/,
/(service|path)(\s*:\s*)("[^"]*")/,
["identifier", "", "string.service"],
],

Expand Down
8 changes: 6 additions & 2 deletions studio/src/components/playground/prettyPrint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
QueryPlan,
QueryPlanFetchNode,
QueryPlanFetchTypeNode,
Representation,
Expand All @@ -8,7 +9,7 @@ export class PlanPrinter {
depth: number = 0;
buf: string[] = [];

print(plan: QueryPlanFetchTypeNode): string {
print(plan: QueryPlan): string {
this.buf = [];
this.printText("QueryPlan {");
this.printPlanNode(plan, true);
Expand Down Expand Up @@ -63,7 +64,10 @@ export class PlanPrinter {
if (fetch.representations) {
this.printRepresentations(fetch.representations);
}
this.printQuery(fetch.query);

if (fetch.query) {
this.printQuery(fetch.query);
}

this.depth--;
this.printText("}");
Expand Down
2 changes: 1 addition & 1 deletion studio/src/components/playground/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type QueryPlanFetchNode = {
kind: string;
subgraphName: string;
subgraphId: string;
query: string;
query?: string;
path?: string;
representations?: Representation[];
};
Expand Down

0 comments on commit 37af012

Please sign in to comment.