Welcome to the graphql-specifications
repository! This project demonstrates how to test a GraphQL service built with HotChocolate using specifications and behavior-driven approaches with Reqnroll.
Specifications provide a structured, human-readable way to define and verify your GraphQL API’s behavior. By aligning tests with clear specifications, you can:
- Ensure consistent and reliable API behavior.
- Make tests easy to understand for both technical and non-technical stakeholders.
- Promote collaboration and a shared understanding of the API’s functionality.
- GraphQL Service: Built using HotChocolate, showcasing a sample domain.
- Specifications: Written in plain language to describe API behavior.
- Reqnroll Integration: Testing GraphQL queries and mutations against the specifications.
- Implemented Scenarios:
- Getting all books.
- Searching for books by title, retrieving details, and checking stock.
- Logging in as an owner or customer, with scope validation in the bearer token.
- Adding books (restricted to logged-in store owners).
Follow these steps to explore and use this repository:
Ensure you have the following installed:
- Clone the repository:
git clone https://github.com/jacobduijzer/graphql-specifications.git cd graphql-specifications
- Install dependencies:
dotnet restore
- Run the application:
dotnet run --project ./src/Bookstore.Api --no-restore
- Open the GraphQL Playground at https://localhost:5011/graphql to test the queries and mutations.
- Run the tests:
dotnet test
The CustomWebApplicationFactory
class is used to create a custom WebApplicationFactory
for integration tests. This class is used to configure the test server with the required services and settings. It is also used to override registered services, in this case the StockService
.
graphql-specifications/src/Bookstore.Specifications/Login.feature
Lines 1 to 11 in 04cf32d
- HotChocolate Documentation
- Strawberry Shake Documentation
- Reqnroll Documentation
- Gherkin Language Reference
- Writing integration tests in .NET
This project is licensed under the MIT License. See the LICENSE file for details.
For more insights, check out my blog post on using specifications with Reqnroll to test GraphQL services. (Coming soon!)
Happy Testing! 🚀