This project provides a GraphQL mock server using Apollo Server, with support for custom fixtures and auto-generated mock responses. You can run it locally or in a container using Podman.
-
Install dependencies:
npm install
-
Run the server in development mode:
npm run dev
The server will be available at http://localhost:4000/.
-
Build the image:
podman build -t api-stubbing . -
Run the container:
podman run -p 4000:4000 api-stubbing
- Start with compose:
podman-compose -f podman-compose.yaml up --build
- Place fixture files in
src/fixtures/named as${queryname}.fixture.json. - If a fixture exists for a query, it will be returned as the mock response.
- If no fixture exists, Apollo will auto-generate the mock response.
- Some queries may require an
Authorizationheader. - Example:
Authorization: Bearer mocktoken
query {
paymentCalculation(input: { paymentType: "LEASE" }) {
paymentType
amountDueAtSigning
disclaimer
payment
calculatedPrice
cashBonus
rateReductionPercentage
aprPercentage
}
}
query {
paymentOrchestrate(input: { amount: 1000, method: "CARD" }) {
status
transactionId
message
}
}src/
index.ts
fixtures/
paymentCalculation.fixture.json
paymentOrchestrate.fixture.json
schema.graphql
Dockerfile
podman-compose.yaml
- Edit or add fixture files to customize mock responses.
- All other queries/mutations will be auto-mocked.
- For schema changes, update
schema.graphql.