[GH-ISSUE #93] Inner operation without the variables property produce an Uncaught TypeError: t.map is not a function #58

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

Originally created by @MurzNN on GitHub (Aug 12, 2024).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/93

I need to build a query with nested operations, like this:

query ($id: Int) {
  thought (id: $id) {
    id,
    name,
    thought,
    details {
      image,
      description
    }
  }
}

So, I composed this JS code to make it:

const query = gql.query({
    operation: 'thought',
    variables: { id: 1 },
    fields: [
        'id',
        'name',
        'thought',
        {
            operation: 'details',
            fields: [
                'image',
                'description',
            ],
        },
    ]
})

But it produces an error:

Uncaught TypeError: t.map is not a function

But if I add an empty variables: {} property, it starts working, here is the example:

const query = gql.query({
    operation: 'thought',
    variables: { id: 1 },
    fields: [
        'id',
        'name',
        'thought',
        {
            operation: 'details',
            variables: {},
            fields: [
                'image',
                'description',
            ],
        },
    ]
})

So, is it a bug, or intended behavior? If intended, could you please describe the reasons?

Originally created by @MurzNN on GitHub (Aug 12, 2024). Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/93 I need to build a query with nested operations, like this: ```graphql query ($id: Int) { thought (id: $id) { id, name, thought, details { image, description } } } ``` So, I composed this JS code to make it: ```js const query = gql.query({ operation: 'thought', variables: { id: 1 }, fields: [ 'id', 'name', 'thought', { operation: 'details', fields: [ 'image', 'description', ], }, ] }) ``` But it produces an error: ``` Uncaught TypeError: t.map is not a function ``` But if I add an empty `variables: {}` property, it starts working, here is the example: ```js const query = gql.query({ operation: 'thought', variables: { id: 1 }, fields: [ 'id', 'name', 'thought', { operation: 'details', variables: {}, fields: [ 'image', 'description', ], }, ] }) ``` So, is it a bug, or intended behavior? If intended, could you please describe the reasons?
kerem changed title from [GH-ISSUE #93] Inner operation without the variables property produce an Uncaught TypeError: t.map is not a function to [GH-ISSUE #93] Inner operation without the variables property produce an Uncaught TypeError: t.map is not a function 2026-03-15 11:37:45 +03:00
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#58
No description provided.