Skip to content

Conversation

BasitAli
Copy link

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: '[email protected]', required: true, builder: customVarBuilder}
  },
  fields: ['userId', 'email']
})

console.log(query)

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

// Variables
{
  email: "[email protected]"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant