This is a small project that demonstrates how to use GraphQL with Express.js and Apollo Server. It provides a basic setup to create a GraphQL API server using Express.js and Apollo Server.
Before running this project, ensure that you have the following dependencies installed on your system:
- Node.js (version 12 or later)
- npm (Node Package Manager)
Follow the steps below to set up and run the project:
-
Clone the repository or download the source code:
git clone https://github.com/niushay/express-graphql.git
-
Navigate to the project directory:
cd express-graphql
-
Install the required dependencies:
npm install
To start the server and run the project, execute the following command:
npm start
Once the server is running, you can access the GraphQL playground at http://localhost:4000/graphql
. The playground provides an interactive interface to test and explore the GraphQL API.
The project structure is organized as follows:
express-graphql/
├── orders/
│ ├── resolvers.js
│ └── graphql
│ └── model.js
├── products/
│ ├── resolvers.js
│ └── graphql
│ └── model.js
├── server.js
└── package.json
/resolvers.js
: This file contains the resolver functions that define how the GraphQL server handles different queries and mutations./graphql.js
: Here, you define the GraphQL schema. It includes the types, queries, and mutations supported by your API.server.js
: This is the main entry point of the application. It sets up the Express.js server and integrates Apollo Server with the defined schema and resolvers.package.json
: The package configuration file containing project metadata and dependencies.
- Express.js: Official website for Express.js.
- Apollo Server: Official documentation for Apollo Server.
- GraphQL: Official website for GraphQL.
This project is licensed under the MIT License. See the LICENSE file for more information.
Feel free to modify and extend this project to suit your needs. Happy coding!