https://github.com/tankengine-ish/graphql_api
A Node.js GraphQL API + Apollo [personal project]
https://github.com/tankengine-ish/graphql_api
apollo-server graphiql graphql-tools
Last synced: 3 months ago
JSON representation
A Node.js GraphQL API + Apollo [personal project]
- Host: GitHub
- URL: https://github.com/tankengine-ish/graphql_api
- Owner: TankEngine-ish
- Created: 2024-02-24T18:50:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-27T20:01:21.000Z (over 1 year ago)
- Last Synced: 2024-02-27T22:28:56.140Z (over 1 year ago)
- Topics: apollo-server, graphiql, graphql-tools
- Language: JavaScript
- Homepage:
- Size: 330 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphQL_API
## Overview
This is a simple GraphQL API built with Apollo Server and Express.js. It provides functionality for querying and mutating data related to products and orders.
## Setup
The server is set up in server.js using Apollo Server and Express.js. The GraphQL schema and resolvers are loaded from the *.graphql and *.resolvers.js files respectively. The server listens on port 3000 and exposes the GraphQL API at the /graphql endpoint.
## Schema
The schema is defined in the *.graphql files. It includes the following types:
- `Product`: Represents a product with an id, description, price, and reviews.
- `Review`: Represents a review with a rating and comment.
- `Order`: Represents an order with a date, subtotal, and items.
- `OrderItem`: Represents an order item with a product and quantity.The schema also includes the following queries and mutations:
* Query:
- `products`: Returns all products.
- `productsByPrice(min: Float!, max: Float!)`: Returns products within a price range.
- `product(id: ID!)`: Returns a product by ID.
- `orders`: Returns all orders.* Mutation:
- `addNewProduct(id: ID!, description: String!, price: Float!)`: Adds a new product.
- `addNewProductReview(id: ID!, rating: Int!, comment: String)`: Adds a new product review.## Resolvers
The resolvers are defined in the *.resolvers.js files. They provide the logic for fetching and mutating data based on the queries and mutations defined in the schema.
- `products.resolvers.js`: Contains resolvers for the products, productsByPrice, product, addNewProduct, and addNewProductReview queries and mutations.
- `orders.resolvers.js`: Contains the resolver for the orders query.## Data
The data for products and orders is stored in memory in the products.model.js and orders.model.js files respectively. The data includes a list of products and a list of orders, each with their respective properties as defined in the schema. The models also include functions for fetching and mutating the data.
## Notes
Before adding Apollo Server package I tested the queries inside graphiQL
![alt text]()
Once you get Apollo you can test your queries, mutations and much more inside this cool front-end itnerface.
![alt text]()