1.0.2 • Published 6 years ago

graphql-collector v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

graphql-collector

Import GraphQL queries/mutations/subscriptions of your project to one object

Installation

npm version

npm i graphql-collector

Use as global module

npm i -g graphql-collector

then run command graphql-collector [directory] [filename.json]

graphql-collector graphql schema.json

or simply run in your project, module will try to find all graphql files in folder and save to file schema.json

graphql-collector

Usage

const { collect } = require('graphql-collector')

const graphqlSchemasDir = path.join(__dirname, 'graphql')

const schema = collect(graphqlSchemasDir).then(schema => {
  console.log(schema)
})

Also you can use collectToFile function

const { collectToFile } = require('graphql-collector')

const graphqlSchemasDir = path.join(__dirname, 'graphql')

const file = path.join(__dirname, 'graphql.json')

const schema = await collectToFile(graphqlSchemasDir, file)

Example

Files: movie-fragment.graphql

fragment Movie on Film {
  id
  title
  director
  planetConnection {
    planets {
      ...Place
    }
  }
}

place-fragment.graphql

fragment Place on Planet {
  name
  climates
}

listmovies.graphql

query ListMovies {
  allFilms {
    films {
      ...Movie
    }
  }
}

Will be convert to this object

  const schema = {
    ListMovies: `query ListMovies { allFilms { films { ...Movie } } } fragment 
    Movie on Film { id title director planetConnection { planets { ...Place } } } 
    fragment Place on Planet { name climates }`
  }
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago