New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-combine

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-combine

A better way to modularize your GraphQL schemas and resolver objects.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
197
increased by28.76%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version

A better way to modularize your GraphQL schemas and resolver objects.

Getting started

Install it

$ npm install graphql-combine

Folder structure

graphql/
  |-- author/
      |-- schema.graphql
      |-- resolver.js
  |-- post/
      |-- schema.graphql
      |-- resolver.js
index.js

Files

File: graphql/author/schema.graphql

type Author {
  id: Int!
  firstName: String
  lastName: String
  books: [Book]
}

type Query {
  author(id: Int!): Author
}

File: graphql/author/resolver.js

export default {
  Query: {
    author: () => {
      //...
    }
  }
}

File: graphql/book/schema.graphql

type Book {
  title: String
  author: Author
}

type Query {
  book(id: Int!): Book
}

File: graphql/book/resolver.js

export default {
  Query: {
    book: () => {
      //...
    }
  }
}

Start the server

File: index.js

// Dependencies
import { ApolloServer } from 'apollo-server'
import combine from 'graphql-combine'
import path from 'path'

// Get combined typeDefs and resolvers
const { typeDefs, resolvers } = combine({
  // TypeDefs glob pattern
  typeDefs: path.join(__dirname, 'graphql/*/schema.graphql'),
 
  // Resolvers glob pattern
  resolvers: path.join(__dirname, 'graphql/*/resolver.js')
})

// Initialize server
const server = new ApolloServer({ typeDefs, resolvers })

// Start the server
server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`)
})

That's it 👍🏼

Example

Have a look at this simple example using graphql-combine and apollo-server.

API

combine(options)

The combine() function is a top-level function exported by the graphql-combine module.

  • options
    • typeDefs The glob pattern for all schema files
    • resolvers The glob pattern for all resolver files

Keywords

FAQs

Package last updated on 11 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc