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
Query: { //... }
File: graphql/book/schema.graphql
type Book { title: String author: Author} type Query { book(id: Int!): Book}
File: graphql/book/resolver.js
Query: { //... }
Start the server
File: index.js
// Dependencies // Get combined typeDefs and resolversconst typeDefs resolvers = // Initialize serverconst server = typeDefs resolvers // Start the serverserver
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 filesresolvers
The glob pattern for all resolver files