This project demonstrates the implementation of a GraphQL API using ASP.NET Core and HotChocolate, with a SQL & Mongo database backend. The project employs a Code First approach to define the GraphQL schema and uses AutoMapper to map database entities to the GraphQL schema.
- GraphQL HotChocolate: Provides a powerful and flexible GraphQL server implementation.
- ASP.NET Core: Serves as the web framework for building the API.
- SQL Database: Stores data for groceries and products.
- AutoMapper: Maps database entities to GraphQL schema models.
- Code First Approach: Defines GraphQL schema based on C# classes.
-
AddGrocery
- Adds a new grocery to the database.
- Input:
GroceryInput
type. - Output:
GrocerySchema
type.
-
AddProducts
- Adds a product to a specified grocery.
- Input:
ProductInput
type. - Output:
ProductSchema
type.
-
AddCustomer
- Adds a Customer .
- Input:
CustomerInput
type. - Output:
CustomerSchema
type.
-
GetProducts
- Retrieves a list of products with pagination support.
- Output: List of
ProductSchema
types. - Pagination: Uses
UseOffsetPaging
to handle page navigation withpageInfo
that includeshasNextPage
andhasPreviousPage
.
-
GetGroceries
- Retrieves a list of groceries with pagination support.
- Output: List of
GrocerySchema
types. - Pagination: Uses
UseOffsetPaging
to handle page navigation withpageInfo
that includeshasNextPage
andhasPreviousPage
.
-
GetCustomers
- Retrieves a list of customers with pagination support.
- Output: List of
CustomerSchema
types. - Pagination: Uses
UseOffsetPaging
to handle page navigation withpageInfo
that includeshasNextPage
andhasPreviousPage
.
-
Clone the Repository
git clone <repository-url> cd <project-directory>
-
Restore Dependencies
dotnet restore
-
Configuration Database Connection: Ensure your SQL and mongo database connection string is correctly configured in appsettings.json or appsettings.development.json.
Note Open Terminal should be open GraphQlDemo folder not Project
- Add Migration "nameof Migration Replace with migration name"
bash dotnet ef migrations add PriceInProduct --context GraphQlDatabaseContext --output-dir Migrations --project Data/Database/GraphQl.Database.csproj
- Update Database
dotnet ef database update --startup-project GraphQlDemo```
- Add Migration "nameof Migration Replace with migration name"
-
Run Application
dotnet run
-
Usage Open your browser and navigate to https://localhost:7104/graphql/ to interact with the GraphQL API. Use the GraphQL Playground or any GraphQL client to execute queries and mutations.
You can find the example query and Screenshots in Queries_Result Folder
Feel free to fork the repository and submit pull requests with improvements or new features.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or feedback, please contact email2wajidkhan@gmail.com, Phone Number: +971566290465.