gtl-node

0.0.3 • Public • Published

Graphql Typedefs loader

Build Status Coverage Status codebeat badge CodeFactor Codacy Badge node-current npm npm bundle size npm bundle size Snyk Vulnerabilities for GitHub Repo PRs Welcome

Graphql Typedefs Loader is simple multiple loader schema for GraphQL, you can load many schema files with extension .graphql in your GraphQL project, please check more example usage, how about this module it works.

Installation

$ npm install gtl-node -S or yarn add gtl-node -S

Example Usage

  • Example Usage Multiple File Inside Directory
    • Example Usage Using CommonJs
      const http from = require('http')
      const { ApolloServer } = require('apollo-server-express')
      const { applyMiddleware } = require('graphql-middleware')
      const { makeExecutableSchema } = require('@graphql-tools/schema')
      const playground = require('graphql-playground-middleware-express')
      const express = require('express')
      // import module like this
      const { gtl } = require('gtl-node')
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ directory: 'graphql/typeDefs', pattern: '**/*', extension: 'graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
    • Example Usage Using ES6
      import http from 'http'
      import { ApolloServer } from 'apollo-server-express'
      import { applyMiddleware } from 'graphql-middleware'
      import { makeExecutableSchema } from '@graphql-tools/schema'
      import playground from 'graphql-playground-middleware-express'
      import express from 'express'
      // import module like this
      import { gtl } from 'gtl-node'
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ directory: 'graphql/typeDefs', pattern: '**/*', extension: 'graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
  • Example Usage Multiple File Outside Directory
    • Example Usage Using CommonJs
      const http from = require('http')
      const { ApolloServer } = require('apollo-server-express')
      const { applyMiddleware } = require('graphql-middleware')
      const { makeExecutableSchema } = require('@graphql-tools/schema')
      const playground = require('graphql-playground-middleware-express')
      const express = require('express')
      // import module like this
      const { gtl } = require('gtl-node')
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ pattern: '**/*', extension: 'graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
    • Example Usage Using ES6
      import http from 'http'
      import { ApolloServer } from 'apollo-server-express'
      import { applyMiddleware } from 'graphql-middleware'
      import { makeExecutableSchema } from '@graphql-tools/schema'
      import playground from 'graphql-playground-middleware-express'
      import express from 'express'
      // import module like this
      import { gtl } from 'gtl-node'
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ pattern: '**/*', extension: 'graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
  • Example Usage Single File Inside Directory
    • Example Usage Using CommonJs
      const http from = require('http')
      const { ApolloServer } = require('apollo-server-express')
      const { applyMiddleware } = require('graphql-middleware')
      const { makeExecutableSchema } = require('@graphql-tools/schema')
      const playground = require('graphql-playground-middleware-express')
      const express = require('express')
      // import module like this
      const { gtl } = require('gtl-node')
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ directory: 'graphql/typedefs' , fileName: 'schema.graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
    • Example Usage Using ES6
      import http from 'http'
      import { ApolloServer } from 'apollo-server-express'
      import { applyMiddleware } from 'graphql-middleware'
      import { makeExecutableSchema } from '@graphql-tools/schema'
      import playground from 'graphql-playground-middleware-express'
      import express from 'express'
      // import module like this
      import { gtl } from 'gtl-node'
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ directory: 'graphql/typedefs' , fileName: 'schema.graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
  • Example Usage Single File Outside Directory
    • Example Usage Using CommonJs
      const http from = require('http')
      const { ApolloServer } = require('apollo-server-express')
      const { applyMiddleware } = require('graphql-middleware')
      const { makeExecutableSchema } = require('@graphql-tools/schema')
      const playground = require('graphql-playground-middleware-express')
      const express = require('express')
      // import module like this
      const { gtl } = require('gtl-node')
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ fileName: 'schema.graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()
    • Example Usage Using ES6
      import http from 'http'
      import { ApolloServer } from 'apollo-server-express'
      import { applyMiddleware } from 'graphql-middleware'
      import { makeExecutableSchema } from '@graphql-tools/schema'
      import playground from 'graphql-playground-middleware-express'
      import express from 'express'
      // import module like this
      import { gtl } from 'gtl-node'
    
      // change with your graphql schema location folder
      const typeDefs = gtl({ fileName: 'schema.graphql' }) 
      const { resolvers } = require('./graphql/resolvers')
      const graphqlPlayground = playground.default
    
      (async function () {
        const apolloServer = new ApolloServer({
          schema: applyMiddleware(makeExecutableSchema({ typeDefs, resolvers }))
        })
    
        const app = express()
        const server = http.createServer(app)
    
        app.get('/playground', graphqlPlayground({ endpoint: '/graphql', codeTheme: 'light' }))
    
        await apolloServer.start()
        apolloServer.applyMiddleware({ app })
        server.listen(process.env.PORT || 3000, () => console.log(`Apollo server running on ${server.address().port}`))
      })()

Testing

  • Testing Via Local

    npm test or make test
  • Testing Via Local And Build

    make build
  • Testing Via Docker

    docker build -t gtl-node or make dkb tag=gtl-node

Bugs

For information on bugs related to package libraries, please visit here

Contributing

Want to make Graphql Typedefs Loader more perfect ? Let's contribute and follow the contribution guide.

License

BACK TO TOP

Package Sidebar

Install

npm i gtl-node

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

27.7 kB

Total Files

15

Last publish

Collaborators

  • restuwahyu13