graphqlify

raw JSON →
1.2.0 verified Sat Apr 25 auth: no javascript maintenance

A JavaScript library (v1.2.0, last updated 2016) for building GraphQL queries programmatically using plain JavaScript objects. Allows dynamic query construction with support for aliases, arguments, and enums via the Enum helper. Lightweight and dependency-free, but not actively maintained. Differentiated from template-based builders by its object-oriented approach, but lacks support for fragments, directives, or variables typical of modern alternatives like graphql-request or graphql-tag.

error Cannot find module 'graphqlify'
cause Package not installed or using unsupported Node version (no longer maintained).
fix
npm install graphqlify@1.2.0
error TypeError: graphqlify is not a function
cause Using CJS require without .default.
fix
const graphqlify = require('graphqlify').default;
error Uncaught TypeError: Cannot read property 'fields' of undefined
cause Object structure missing required fields (e.g., field, params).
fix
Ensure each field has a proper fields object or alias.
deprecated This package is no longer actively maintained. Consider using graphql-request or graphql-tag for modern projects.
fix Migrate to graphql-request for a more complete GraphQL client.
gotcha Using CJS require without .default returns an object with default property instead of the function.
fix Use const graphqlify = require('graphqlify').default;
breaking Aliasing with 'alias' field inside a field object may not be documented properly; some users attempt 'field' for naming.
fix Use the 'alias' key for aliases, not 'field'.
gotcha Empty fields object {} required for leaf fields; omitting it may cause undefined behavior.
fix Always add fields: {} for simple fields without subfields.
npm install graphqlify
yarn add graphqlify
pnpm add graphqlify

Demonstrates building a GraphQL query with alias, argument, and enum using graphqlify.

import graphqlify, {Enum} from 'graphqlify';

const query = graphqlify({
  characters: {
    alias: 'heroes',
    params: { kind: Enum('HUMAN') },
    fields: {
      name: {},
      homePlanet: {}
    }
  }
});

console.log(query);