Nerfing Powerful Megalomaniacs

    @jaccomeijer/graphql-query-builder
    TypeScript icon, indicating that this package has built-in type declarations

    1.4.0 • Public • Published

    graphql-query-builder

    About

    Small library to build graphQL queries dynamically.

    How does it work?

    The library translates a javascript object into a GraphQL query string.

    The object below:

    {
      fields: {
        firstName: {},
        lastName: {},
      },
      operationName: 'firstAndLastName',
      operationType: 'query',
    }

    Turns into:

    query firstAndLastName {
      firstName
      lastName
    }

    Examples

    See jest test script for a larger example.

    import {
      graphqlQueryBuilder as qb,
      Question,
    } from '@jaccomeijer/graphql-query-builder'
    
    const question: Question = {
      fields: {
        firstName: {
          arguments: {
            id: '4',
          },
        },
        lastName: {
          directive: {
            name: '@include',
            value: 'if: $withFriends',
          },
        },
      },
      operationType: 'query',
    }
    
    console.log(qb(question))
    // query {
    //  firstName(id: 4)
    //  lastName @include(if: $withFriends)
    // }

    Supported fields

    Have a look into the typescript definitions for that.

    Install

    npm i @jaccomeijer/graphql-query-builder

    DownloadsWeekly Downloads

    2

    Version

    1.4.0

    License

    MIT

    Unpacked Size

    21.4 kB

    Total Files

    15

    Last publish

    Collaborators

    • jaccomeijer