A simple example for GraphQL, Node, and Apollo Server.
How to Run it?
npm install -g nodemon
to install nodemon globally.npm i
to install packages.npm start
to run it. Then go tohttp://localhost:4000/graphql
Folder Structure This project uses the repository pattern, that abstracts into different layers.
repositories
Contains all the configuration, models and interaction between the API and DB.services
Contains methods for our endpoints aka schemas and interactes with the repository layer.schemas
A normal graphql schemas.- Each schema has a folder inside the schemas folder with two files.
schemaName.resolvers.js
All the resolvers for the types.schemaName.types.js
All the types, mutations, inputs, etc. For our schemas.rootQuery.js
Container for all types and resolvers of our schemas.
- Modularizing your GraphQL schema code - Apollo Blog (apollographql.com)
- Resolvers - Apollo Server - Apollo GraphQL Docs
- GraphQL Full Course - Novice to Expert - YouTube
- GraphQL Schemas - GraphQL
- Used the repository pattern.
- For
BaseServiceWithRepository.js
uses the mixin pattern thar allow us to create a superclass. More info. https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/#bettermixinsthroughclassexpressions