[PR #81] feat(variables): custom builder function to override variable generation #92

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

📋 Pull Request Information

Original PR: https://github.com/atulmy/gql-query-builder/pull/81
Author: @BasitAli
Created: 4/13/2023
Status: 🔄 Open

Base: masterHead: master


📝 Commits (1)

  • 904f86c feat(variables): custom builder function to override variable generation

📊 Changes

4 files changed (+78 additions, -5 deletions)

View changed files

📝 README.md (+35 -0)
📝 src/Utils.ts (+15 -3)
📝 src/VariableOptions.ts (+1 -0)
📝 src/index.test.ts (+27 -2)

📄 Description

This allows specifying custom builder methods for variable definition to cater requirements such as #22 and #65.

import * as gql from 'gql-query-builder'

function customVarBuilder(key: string, value: BuilderVariableOptions) {
  const name = value.name ?? key;
  return `where: {${name}_eq: $${name}}`;
}

const query = gql.query({
  operation: 'userByEmail',
  variables: {
    email: { value: 'jon.doe@example.com', required: true, builder: customVarBuilder}
  },
  fields: ['userId', 'email']
})

console.log(query)

// Output
query ($email: String!) {
  userByEmail (where: {email_eq: $email}) {
    userId, email
  }
}

// Variables
{
  email: "jon.doe@example.com"
}

🔄 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/81 **Author:** [@BasitAli](https://github.com/BasitAli) **Created:** 4/13/2023 **Status:** 🔄 Open **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`904f86c`](https://github.com/atulmy/gql-query-builder/commit/904f86ceddaf54ee454c56a37c44578da40f62f2) feat(variables): custom builder function to override variable generation ### 📊 Changes **4 files changed** (+78 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+35 -0) 📝 `src/Utils.ts` (+15 -3) 📝 `src/VariableOptions.ts` (+1 -0) 📝 `src/index.test.ts` (+27 -2) </details> ### 📄 Description This allows specifying custom builder methods for variable definition to cater requirements such as #22 and #65. ```javascript import * as gql from 'gql-query-builder' function customVarBuilder(key: string, value: BuilderVariableOptions) { const name = value.name ?? key; return `where: {${name}_eq: $${name}}`; } const query = gql.query({ operation: 'userByEmail', variables: { email: { value: 'jon.doe@example.com', required: true, builder: customVarBuilder} }, fields: ['userId', 'email'] }) console.log(query) // Output query ($email: String!) { userByEmail (where: {email_eq: $email}) { userId, email } } // Variables { email: "jon.doe@example.com" } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#92
No description provided.