[GH-ISSUE #86] Trying to understand nested queries with aliases #53

Open
opened 2026-03-03 00:03:00 +03:00 by kerem · 0 comments
Owner

Originally created by @christopher-caldwell on GitHub (Sep 1, 2023).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/86

I'm trying to put together a query where the alias is "deep", but am getting runtime errors. TS checks out because it's type is object.

import { query as buildQuery } from "gql-query-builder";

const works = buildQuery(
  {
    operation: "operation",
    variables: {},
    fields: [
      "id",
      {
        operation: "operartion",
        variables: {},
        fields: [
          {
            operation: {
              alias: "alias",
              name: "name",
            },
            // if this is removed (below example) 
            // it throws a runtime error of innerFields.forEach is not a function
            variables: {},
            fields: ["field"],
          },
        ],
      },
      {
       	nested: ["id"],
      },
    ],
  },
);

console.log(works)

try {
  const broken = buildQuery(
  {
    operation: "operation",
    variables: {},
    fields: [
      "id",
      {
        operation: "operartion",
        variables: {},
        fields: [
          {
            operation: {
              alias: "alias",
              name: "name",
            },
            fields: ["field"],
          },
        ],
      },
      {
       	nested: ["id"],
      },
    ],
  },
);
} catch(e){
  console.error("it didn't work", e)
}

Is it documented anywhere that this field needs to be present, even if you don't ave any variables?

Originally created by @christopher-caldwell on GitHub (Sep 1, 2023). Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/86 I'm trying to put together a query where the alias is "deep", but am getting runtime errors. TS checks out because it's type is `object`. ```typescript import { query as buildQuery } from "gql-query-builder"; const works = buildQuery( { operation: "operation", variables: {}, fields: [ "id", { operation: "operartion", variables: {}, fields: [ { operation: { alias: "alias", name: "name", }, // if this is removed (below example) // it throws a runtime error of innerFields.forEach is not a function variables: {}, fields: ["field"], }, ], }, { nested: ["id"], }, ], }, ); console.log(works) try { const broken = buildQuery( { operation: "operation", variables: {}, fields: [ "id", { operation: "operartion", variables: {}, fields: [ { operation: { alias: "alias", name: "name", }, fields: ["field"], }, ], }, { nested: ["id"], }, ], }, ); } catch(e){ console.error("it didn't work", e) } ``` Is it documented anywhere that this field needs to be present, even if you don't ave any variables?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/gql-query-builder#53
No description provided.