[PR #33] [MERGED] Handle parameters on nested fields #154

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

📋 Pull Request Information

Original PR: https://github.com/atulmy/gql-query-builder/pull/33
Author: @cbonaudo
Created: 6/16/2020
Status: Merged
Merged: 6/20/2020
Merged by: @atulmy

Base: masterHead: master


📝 Commits (10+)

📊 Changes

5 files changed (+115 additions, -30 deletions)

View changed files

📝 src/Fields.ts (+3 -1)
src/NestedField.ts (+24 -0)
📝 src/Utils.ts (+52 -9)
📝 src/adapters/DefaultQueryAdapter.ts (+15 -20)
📝 src/index.test.ts (+21 -0)

📄 Description

fix #3

Hi, I have used this lib for a moment, and really like what it brings, and I fell upon a missing feature (that was brought up in your issue #3), adding variables to fields, like so :

query ($id: ID) { 
  getPublicationNames  { 
    publication (id: $id) {
      id, 
      name
    } 
  } 
}

I added a test case, and worked on the syntax that was provided on the issue :

const query = gql.query({
  operation: 'users',
  variables: { limit: 4 },
  fields: [
    'name',
    'email'
    {
      operation: 'posts',
      variables: { limit: 10 },
      fields: [
        'title', 
        'body'
      ]
    },
  ]
})

It seems to work for me, the tests are ok, and it worked in a real app as a test. If this can be of interest, I'd love to have this added to the library.

I did try to clean up as much my additions, but feel free to tell me where I could ease the integration, and where could be some improvements or errors.

Thanks a lot !!!


🔄 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/33 **Author:** [@cbonaudo](https://github.com/cbonaudo) **Created:** 6/16/2020 **Status:** ✅ Merged **Merged:** 6/20/2020 **Merged by:** [@atulmy](https://github.com/atulmy) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`2964b88`](https://github.com/atulmy/gql-query-builder/commit/2964b88434b9cbb6e8d3fac14e65be27aeabe931) add tests - [`2ca6e03`](https://github.com/atulmy/gql-query-builder/commit/2ca6e03aeda31e38d98480b3a8f97041ca628e8a) add tests - [`2060035`](https://github.com/atulmy/gql-query-builder/commit/2060035864b68dd4609e4f9ae601ff623de64f85) update fields with variables - [`1f3bd34`](https://github.com/atulmy/gql-query-builder/commit/1f3bd347101e266156f12117e21b229afee528b7) add query variables - [`0a73055`](https://github.com/atulmy/gql-query-builder/commit/0a7305504cd44e804804e07df908aadd097efe03) add variables to query object - [`f454250`](https://github.com/atulmy/gql-query-builder/commit/f45425049b30ff1553745066a68edfda6fe3840c) update test - [`36a8ce0`](https://github.com/atulmy/gql-query-builder/commit/36a8ce0fcd9034b3c2822446f390ff587dfbf39a) Merge pull request #1 from cbonaudo/handle-nested-fields-w-variables - [`35524ac`](https://github.com/atulmy/gql-query-builder/commit/35524ac7e5050deafb2d1d4595c21c4f57b68dcd) clean queryField - [`013cc88`](https://github.com/atulmy/gql-query-builder/commit/013cc888dc41287e3abe2525f2a1b8445c8a972a) extract queryDataNameArgs to Utils - [`8d8b891`](https://github.com/atulmy/gql-query-builder/commit/8d8b89192e061145cbcf0652fccb6eaddc9f85d5) clean field nested variables ### 📊 Changes **5 files changed** (+115 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `src/Fields.ts` (+3 -1) ➕ `src/NestedField.ts` (+24 -0) 📝 `src/Utils.ts` (+52 -9) 📝 `src/adapters/DefaultQueryAdapter.ts` (+15 -20) 📝 `src/index.test.ts` (+21 -0) </details> ### 📄 Description fix #3 Hi, I have used this lib for a moment, and really like what it brings, and I fell upon a missing feature (that was brought up in your [issue #3](https://github.com/atulmy/gql-query-builder/issues/3)), adding variables to fields, like so : ```js query ($id: ID) { getPublicationNames { publication (id: $id) { id, name } } } ``` I added a test case, and worked on the syntax that was provided on the issue : ```js const query = gql.query({ operation: 'users', variables: { limit: 4 }, fields: [ 'name', 'email' { operation: 'posts', variables: { limit: 10 }, fields: [ 'title', 'body' ] }, ] }) ``` It seems to work for me, the tests are ok, and it worked in a real app as a test. If this can be of interest, I'd love to have this added to the library. I did try to clean up as much my additions, but feel free to tell me where I could ease the integration, and where could be some improvements or errors. Thanks a lot !!! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-15 11:38:32 +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#154
No description provided.