Wondering what’s next for npm?Check out our public roadmap! »

    graphql-to-string

    1.0.4 • Public • Published

    graphql-to-string

    Description

    A simple module to create a string for HTTP request of the .gql file with graphql query. Module reads .gql files and transpile them to single common js module where all queries can be read as a string and extended with variables.

    Installation

    $ npm i graphql-to-string -g

    Usage

    In command line run graphql-to-string command with two arguments: first folder with .gql files and second file to compile queries to. .gql saved in nested folders won't be read, only .gql files in a given folder.

    graphql-to-string ./query/ ./query/queries.js

    All queries will become properties ob an export object in the result file with the same name they were in the folder.

    Read file where queries were compiled as CommonJs module and use function addVariable to attach variables to query.

    const queries = require('./queries.js');
    const requestBody = queries.addVariable('test', {
        input: {
            test: 1
        }
    });
    // send requestBody to graphql server

    Fragments usage

    Fragments should be kept in fragments folder in a folder with queries and fragment file must have the same name as a file in fragments folder.

    Example

    Folder structure

    query
    ----fragments
    ------testFields.gql
    ----query.gql

    query.gql

    query GetSongs {
        ...songs
    }

    songs.gql

    fragment songs on Metallica {
        master
        unforgiven
    }

    Install

    npm i graphql-to-string

    DownloadsWeekly Downloads

    28

    Version

    1.0.4

    License

    ISC

    Unpacked Size

    4.22 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar