[GH-ISSUE #3] Params on nested fields ? #98

Closed
opened 2026-03-15 11:27:53 +03:00 by kerem · 6 comments
Owner

Originally created by @revskill10 on GitHub (Feb 22, 2019).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/3

Does the library support params on nested fields ?

Originally created by @revskill10 on GitHub (Feb 22, 2019). Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/3 Does the library support params on nested fields ?
kerem 2026-03-15 11:27:53 +03:00
Author
Owner

@atulmy commented on GitHub (Feb 22, 2019):

@revskill10 can you provide an example of the use case?

<!-- gh-comment-id:466364526 --> @atulmy commented on GitHub (Feb 22, 2019): @revskill10 can you provide an example of the use case?
Author
Owner

@revskill10 commented on GitHub (Feb 22, 2019):

@atulmy In my application, my query is like this

query {
  users (limit: 4) {
    posts (limit: 10) {
      title
      body
    }
  } 
}
<!-- gh-comment-id:466370738 --> @revskill10 commented on GitHub (Feb 22, 2019): @atulmy In my application, my query is like this ```js query { users (limit: 4) { posts (limit: 10) { title body } } } ```
Author
Owner

@revskill10 commented on GitHub (Feb 22, 2019):

@atulmy Thanks for taking this !
I'm using one library that supports this feature, but it's not that clean as yours.
Basically, its api is

const data = Query('author', {id: 160033}, [
  'name',
  Query('books', {}, [
    'id',
    'title',
    'isbn',
    Query('authors', {}, [
      'id',
      'name'
    ])
  ])
])
// To attach another field
// field takes arguments identical to both Query and Mutation
// (field, { args }, [ sub-fields ])
.field('book', {id: 4505161}, [
  'id',
  'title',
  Query('authors', {limit: 10}, [
    'id',
    'name'
  ]),
  'isbn'
])

Maybe you could learn from this !

<!-- gh-comment-id:466562715 --> @revskill10 commented on GitHub (Feb 22, 2019): @atulmy Thanks for taking this ! I'm using one library that supports this feature, but it's not that clean as yours. Basically, its api is ```js const data = Query('author', {id: 160033}, [ 'name', Query('books', {}, [ 'id', 'title', 'isbn', Query('authors', {}, [ 'id', 'name' ]) ]) ]) // To attach another field // field takes arguments identical to both Query and Mutation // (field, { args }, [ sub-fields ]) .field('book', {id: 4505161}, [ 'id', 'title', Query('authors', {limit: 10}, [ 'id', 'name' ]), 'isbn' ]) ``` Maybe you could learn from this !
Author
Owner

@bebraw commented on GitHub (Mar 20, 2019):

Here's one approach:

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

It's likely not a big change internally as the code has been factored along these lines already (extra type check in a certain place).

<!-- gh-comment-id:474874761 --> @bebraw commented on GitHub (Mar 20, 2019): Here's one approach: ```javascript const query = gql.query({ operation: 'users', variables: { limit: { value: 4 } }, fields: [{ operation: 'posts', variables: { limit: { value: 10 } }, fields: ['title', 'body'] }, }) ``` It's likely not a big change internally as the code has been factored along these lines already (extra type check in a certain place).
Author
Owner

@atulmy commented on GitHub (Mar 20, 2019):

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

Yes, your approach looks cleaner than what I initially thought we could do:

const query = gql.query({
  operation: 'users',
  variables: {
    user: {
      limit: 4,
      post: {
        limit 10
      }
    }
  },
  fields: [
     'id',
     'name',
     {
        posts: [
          'title',
          'body'
        ]
    }
  ]
})
<!-- gh-comment-id:474984693 --> @atulmy commented on GitHub (Mar 20, 2019): ```javascript const query = gql.query({ operation: 'users', variables: { limit: 4 }, fields: [ 'name', 'email' { operation: 'posts', variables: { limit: 10 }, fields: [ 'title', 'body' ] }, ] }) ``` Yes, your approach looks cleaner than what I initially thought we could do: ```javascript const query = gql.query({ operation: 'users', variables: { user: { limit: 4, post: { limit 10 } } }, fields: [ 'id', 'name', { posts: [ 'title', 'body' ] } ] }) ```
Author
Owner

@asaf commented on GitHub (Sep 11, 2019):

@atulmy are you planning to support this?

<!-- gh-comment-id:530233140 --> @asaf commented on GitHub (Sep 11, 2019): @atulmy are you planning to support this?
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#98
No description provided.