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.
Run the following script on Linux:
chmod u+x gradlew
./gradlew bootRun
On Windows:
gradlew bootRun
You'll need the backend product API server running for this to work. You can get it from here. 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.
-
Start the Specmatic http stub server to emulate domain service:
docker run --network host -p 8090:8090 -v "$(pwd)/specmatic.yaml:/usr/src/app/specmatic.yaml" znsio/specmatic virtualize --port=8090
-
Build and run the BFF service (System Under Test) in a Docker container:
docker build --no-cache -t specmatic-order-bff-graphql .
docker run -p 8080:8080 specmatic-order-bff-graphql
OR, you can run the application locally with
./gradlew bootRun
-
Finally, run Specmatic Contract on the BFF service (System Under Test):
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