Modularizing your Apollo GraphQL schema code
yarn add apollo-modulizer
npm install --save apollo-modulizer
Hit the Star button if you love this project βοΈ
You can get the full example here: https://github.com/Maxvien/apollo-modulizer/tree/master/example
const { gql } = require('apollo-server');
const { createModule } = require('apollo-modulizer');
const typeDef = gql`
type User {
id: ID!
name: String
posts: [Post]
}
input UserInput {
name: String
}
`;
const resolvers = {
User: {
posts: () => [
{ id: 1, title: 'Apollo Server', content: 'Hello Apollo Server!' },
],
},
};
module.exports = createModule({ typeDef, resolvers });
const { allModules } = require('apollo-modulizer');
const User = require('./user.module');
const Post = require('./post.module');
const Query = require('./query.module');
module.exports = { typeDefs, resolvers } = mergeModules([User, Post, Query]);
const { ApolloServer } = require('apollo-server');
const { typeDefs, resolvers } = require('./modules');
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({ url }) => {
console.log(`π Server ready at ${url}`);
});