[PR #66] [MERGED] feat(fields): add support to multiple nested fields #169

Closed
opened 2026-03-15 11:39:21 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/atulmy/gql-query-builder/pull/66
Author: @JoaoPedroAS51
Created: 3/7/2022
Status: Merged
Merged: 3/7/2022
Merged by: @atulmy

Base: masterHead: feat/multiple-nested-fields


📝 Commits (1)

  • 39f12c0 feat(fields): add support to multiple nested fields

📊 Changes

2 files changed (+48 additions, -7 deletions)

View changed files

📝 src/Utils.ts (+18 -6)
📝 src/index.test.ts (+30 -1)

📄 Description

Hi! First of all, thank you for your amazing package :)

When building the queries, I noticed that it was not possible to pass multiple nested fields in the same object.
I think that for simple queries, using the same object is cleaner than using one object per relationship.

Note that as far as I know these changes will not affect current behaviour, so no breaking changes.

Currently:

const query = gql({
  operation: 'posts',
  fields: [
    'id',
    'title',
    'text',
    {
      author: [
        'id',
        'name',
        'email'
      ]
    },
    // Second relation must be in another object
    {
      comments: [
        'id',
        'name',
        'body'
      ]
    }
  ]
})

Add support to:

const query = gql({
  operation: 'posts',
  fields: [
    'id',
    'title',
    'text',
    {
      author: [
        'id',
        'name',
        'email'
      ],
      // Second relation in the same object
      comments: [
        'id',
        'name',
        'body'
      ]
    },
  ]
})

Both will output the same query:

query {
  posts  {
    id,
    title,
    text,
    author {
      id,
      name,
      email
    },
    comments {
      id,
      name,
      body
    }
  }
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/atulmy/gql-query-builder/pull/66 **Author:** [@JoaoPedroAS51](https://github.com/JoaoPedroAS51) **Created:** 3/7/2022 **Status:** ✅ Merged **Merged:** 3/7/2022 **Merged by:** [@atulmy](https://github.com/atulmy) **Base:** `master` ← **Head:** `feat/multiple-nested-fields` --- ### 📝 Commits (1) - [`39f12c0`](https://github.com/atulmy/gql-query-builder/commit/39f12c09380c254f7ad6b01721ea3f7b5a32d269) feat(fields): add support to multiple nested fields ### 📊 Changes **2 files changed** (+48 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/Utils.ts` (+18 -6) 📝 `src/index.test.ts` (+30 -1) </details> ### 📄 Description Hi! First of all, thank you for your amazing package :) When building the queries, I noticed that it was not possible to pass multiple nested fields in the same object. I think that for simple queries, using the same object is cleaner than using one object per relationship. Note that as far as I know these changes will not affect current behaviour, so no breaking changes. ### Currently: ```js const query = gql({ operation: 'posts', fields: [ 'id', 'title', 'text', { author: [ 'id', 'name', 'email' ] }, // Second relation must be in another object { comments: [ 'id', 'name', 'body' ] } ] }) ``` ### Add support to: ```js const query = gql({ operation: 'posts', fields: [ 'id', 'title', 'text', { author: [ 'id', 'name', 'email' ], // Second relation in the same object comments: [ 'id', 'name', 'body' ] }, ] }) ``` ### Both will output the same query: ``` query { posts { id, title, text, author { id, name, email }, comments { id, name, body } } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-15 11:39:21 +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#169
No description provided.