https://github.com/yariksav/graphql-collector
Collect graphql schemas into one object with named params
https://github.com/yariksav/graphql-collector
Last synced: 3 months ago
JSON representation
Collect graphql schemas into one object with named params
- Host: GitHub
- URL: https://github.com/yariksav/graphql-collector
- Owner: yariksav
- Created: 2018-08-06T16:00:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-28T11:07:11.000Z (over 6 years ago)
- Last Synced: 2024-12-30T06:43:25.853Z (5 months ago)
- Language: JavaScript
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-collector
Import GraphQL queries/mutations/subscriptions of your project to one object
## Installation
[](https://badge.fury.io/js/graphql-collector)
npm i graphql-collector
## Use as global module
npm i -g graphql-collector
then run command `graphql-collector [directory] [filename.json]`
```bash
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`
```bash
graphql-collector
```## Usage
```js
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
```js
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`
```graphql
fragment Movie on Film {
id
title
director
planetConnection {
planets {
...Place
}
}
}
```
`place-fragment.graphql`
```graphql
fragment Place on Planet {
name
climates
}
```
`listmovies.graphql`
```graphql
query ListMovies {
allFilms {
films {
...Movie
}
}
}
```
Will be convert to this object```js
const schema = {
ListMovies: `query ListMovies { allFilms { films { ...Movie } } } fragment
Movie on Film { id title director planetConnection { planets { ...Place } } }
fragment Place on Planet { name climates }`
}
```