Git Product home page Git Product logo

graphql-to-string's Introduction

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
}

graphql-to-string's People

Watchers

James Cloos avatar Sergiy Ryazanov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.