https://github.com/znsio/specmatic-order-bff-graphql-java
https://github.com/znsio/specmatic-order-bff-graphql-java
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/znsio/specmatic-order-bff-graphql-java
- Owner: znsio
- License: mit
- Created: 2024-05-16T03:55:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-13T13:01:08.000Z (about 1 year ago)
- Last Synced: 2025-06-28T01:05:20.358Z (12 months ago)
- Language: Kotlin
- Size: 7.02 MB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: License.md
Awesome Lists containing this project
README

# GraphQL Contract Testing Using Specmatic
* [Specmatic Website](https://specmatic.in)
* [Specmatic Documenation](https://specmatic.in/documentation.html)
This sample project demonstrates how we can practice contract-driven development and contract testing in a GraphQL (Kotlin) API that depends on an external domain service. Here, Specmatic is used to stub calls to domain API service based on its OpenAPI specification.
### Starting the server
Run the following script on Linux:
```shell
chmod u+x gradlew
./gradlew bootRun
```
On Windows:
```commandline
gradlew bootRun
```
You'll need the backend product API server running for this to work. You can get it from [here](https://github.com/znsio/specmatic-order-api-java). The README.md file in the repo contain instructions for starting up the backend API server.
Visit http://localhost:8080/graphiql to access the GraphiQL interface.
### Running the contract tests using Docker
1. Start the Specmatic http stub server to emulate domain service:
```shell
docker run --network host -p 8090:8090 -v "$(pwd)/specmatic.yaml:/usr/src/app/specmatic.yaml" znsio/specmatic virtualize --port=8090
```
2. Build and run the BFF service (System Under Test) in a Docker container:
```shell
docker build --no-cache -t specmatic-order-bff-graphql .
```
```shell
docker run -p 8080:8080 specmatic-order-bff-graphql
```
OR, you can run the application locally with `./gradlew bootRun`
3. Finally, run Specmatic Contract on the BFF service (System Under Test):
```shell
docker run --network host -v "$(pwd)/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "$(pwd)/build/reports/specmatic:/usr/src/app/build/reports/specmatic" -e SPECMATIC_GENERATIVE_TESTS=true znsio/specmatic-graphql test --port=8080 --host=host.docker.internal
```