[GH-ISSUE #82] Merging Queries #50

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

Originally created by @costag1982 on GitHub (May 12, 2023).
Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/82

Hi its not really an issue more of question and if the answer is no then a feature request

query gamesAndLeagues {
  games(query: {result: "void"}) {
    teamOne {
      id
    }
    teamTwo {
      id
    }
    result
  }
  leagues(query: {vip: false}) {
    _id
  }
}

this is a query i hit to get data from mongodb realms via gql.

I was wondering if it is possible to build this query that calls 2 collections via a single call?

Im thinking its not possible based on the docs

Thanks

Originally created by @costag1982 on GitHub (May 12, 2023). Original GitHub issue: https://github.com/atulmy/gql-query-builder/issues/82 Hi its not really an issue more of question and if the answer is no then a feature request ```javascript query gamesAndLeagues { games(query: {result: "void"}) { teamOne { id } teamTwo { id } result } leagues(query: {vip: false}) { _id } } ``` this is a query i hit to get data from mongodb realms via gql. I was wondering if it is possible to build this query that calls 2 collections via a single call? Im thinking its not possible based on the docs Thanks
Author
Owner

@dkhrunov commented on GitHub (Aug 22, 2023):

Same question!
@costag1982 did you find a solution?

<!-- gh-comment-id:1687779580 --> @dkhrunov commented on GitHub (Aug 22, 2023): Same question! @costag1982 did you find a solution?
Author
Owner

@dkhrunov commented on GitHub (Aug 22, 2023):

@costag1982 I'm found it

const query = gql.query(
      [
        {
          operation: { name: 'getUser', alias: 'getAdminUser' },
          variables: { id: 1 },
          fields: ['id', 'name', 'role']
        },
        {
          operation: { name: 'getSomething', alias: 'getAdminSomething' },
          variables: { somthingId: 99 },
          fields: ['id', 'name', 'description']
        }
      ]
    );

Result:

{
    "query": "query ($id: Int, $somthingId: Int) { getAdminUser: getUser (id: $id) { id, name, role } getAdminSomething: getSomething (somthingId: $somthingId) { id, name, description } }",
    "variables": {
        "id": 1,
        "somthingId": 99
    }
}
<!-- gh-comment-id:1687793793 --> @dkhrunov commented on GitHub (Aug 22, 2023): @costag1982 I'm found it ```typescript const query = gql.query( [ { operation: { name: 'getUser', alias: 'getAdminUser' }, variables: { id: 1 }, fields: ['id', 'name', 'role'] }, { operation: { name: 'getSomething', alias: 'getAdminSomething' }, variables: { somthingId: 99 }, fields: ['id', 'name', 'description'] } ] ); ``` Result: ```typescript { "query": "query ($id: Int, $somthingId: Int) { getAdminUser: getUser (id: $id) { id, name, role } getAdminSomething: getSomething (somthingId: $somthingId) { id, name, description } }", "variables": { "id": 1, "somthingId": 99 } } ```
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#50
No description provided.