npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-gql-schema-composer

v1.0.12

Published

GraphQL schema composer from different chunks with 0.1 dependencies. Small and tiny, exactly what you are looking for

Downloads

111

Readme

🟢 NodeJS GraphQL Composer

A tiny and minimalist, with minimum dependencies tool, which allows you to use, split and organize the native GQL files in your NodeJs project.


How it works?

You can use native gql files in your nodejs/graphql project. You can split and organize it according to your needs. You can call it as you want, you can nest it as you need. Keep your gql files small and simple.

Example:

Using promise chain:

const express = require('express')
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
const { composeSchema } = require('node-gql-schema-composer')

const app = express()
composeSchema('./gql')
  .then(schema => {
    app.use('/graphql', graphqlHTTP({
      schema: buildSchema(schema),
      rootValue: { hello: () => { return 'Hello world!' }}
      graphiql: true,
    }))
  })
  .then(() => app
    .listen(4000, () => console.log('Now browse to localhost:4000/graphql')))

Using async/await syntax:

const express = require('express')
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
const { composeSchema, dumpToFile, readFolder } = require('node-gql-schema-composer')

const start = async function () {

  const app = express()
  const schema = await composeSchema('./gql')

  app.use('/graphql', graphqlHTTP({
    schema: buildSchema(schema),
    rootValue: { hello: () => { return 'Hello world!' }}
    graphiql: true,
  }))

  app.listen(4000, () => console.log('Now browse to localhost:4000/graphql'))
}


start()

With Apollo Server:

const express = require('express')
const { composeSchema, dumpToFile } = require('node-gql-schema-composer')
const  { ApolloServer } = require( 'apollo-server-express')
const { ApolloServerPluginDrainHttpServer } = require( 'apollo-server-core')
const http = require( 'http')
const Query = {
  hello: () => {
    return 'Hello world!'
  },
}


async function startApolloServer(resolvers) {
  const app = express()
  const typeDefs = await composeSchema('./gql')
  const httpServer = http.createServer(app)
  const server = new ApolloServer({
    typeDefs,
    resolvers,
    plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
  })

  await server.start()
  server.applyMiddleware({ app })
  await new Promise(resolve => httpServer.listen({ port: 4000 }, resolve))
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
}

startApolloServer({ Query })
 

Dump to the schema file:

const express = require('express')
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');
const { composeSchema, dumpToFile } = require('node-gql-schema-composer')

const start = async function () {

  const app = express()
  const schema = await composeSchema('./gql')

  app.use('/graphql', graphqlHTTP({
    schema: buildSchema(schema),
    rootValue: { hello: () => { return 'Hello world!' }}
    graphiql: true,
  }))

  app.listen(4000, () => console.log('Now browse to localhost:4000/graphql'))
}

dumpToFile('./gql')  // it will create a composed schema file in the root folder

start()

Auto restart with nodemon:

You can the files extension to the nodemon and enjoy the auto-restarting behaviors on each change in gql files. Just add the following tweak to your script in the package.json file:

 "start": "nodemon --watch **/*.gql index.js"

and now your nodemon will be also sensitive to the changes in your .gql files:

❯ yarn start
yarn run v1.22.17
$ nodemon --watch **/*.gql index.js
[nodemon] 2.0.14
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): gql/index.gql
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Now browse to localhost:4000/graphql

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Now browse to localhost:4000/graphql

Inside

The module provides 3 simple functions:

  function composeSchema( path ) {...}

  /*  async function which will compose on-the-fly all your chunks .gql files
  *   into one schema used by graphql
  *   
  *   PARAMS: 
  *     < path:string > the place where you will have all your .gql files/folders 
  */
  function dumpToFile( path, name ) {...}

  /*  a simple dump function which will compose all your chunks .gql files
  *   into one schema and will write it into one single file in the root folder, according to the name, which is has a default *   name "schema"
  *   
  *   PARAMS: 
  *     < path:string > the place where you will have all your .gql files/folders 
  *     < name:string | optional> the name of dump file ( default: "schema.gql")
  */
  function readFolder( path, name ) {...}

  /*  async internal function which will read and find all your .gql|.graphql files under provided path 
  */

Made with  ❤️   by Nudelman Alex