Skip to content

RED-Internal-Development/API-stubbing

Repository files navigation

API Stubbing Mock Server

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.


🚀 Local Development

  1. Install dependencies:

    npm install
  2. Run the server in development mode:

    npm run dev

    The server will be available at http://localhost:4000/.


🐳 Podman Container

Build and Run Manually

  1. Build the image:

    podman build -t api-stubbing .
  2. Run the container:

    podman run -p 4000:4000 api-stubbing

Using Podman Compose

  1. Start with compose:
    podman-compose -f podman-compose.yaml up --build

🗂️ Fixtures

  • 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.

🔒 Authenticated Queries

  • Some queries may require an Authorization header.
  • Example:
    Authorization: Bearer mocktoken
    

📄 Example GraphQL Queries

query {
  paymentCalculation(input: { paymentType: "LEASE" }) {
    paymentType
    amountDueAtSigning
    disclaimer
    payment
    calculatedPrice
    cashBonus
    rateReductionPercentage
    aprPercentage
  }
}

query {
  paymentOrchestrate(input: { amount: 1000, method: "CARD" }) {
    status
    transactionId
    message
  }
}

📦 Project Structure

src/
  index.ts
  fixtures/
    paymentCalculation.fixture.json
    paymentOrchestrate.fixture.json
schema.graphql
Dockerfile
podman-compose.yaml

📝 Notes

  • Edit or add fixture files to customize mock responses.
  • All other queries/mutations will be auto-mocked.
  • For schema changes, update schema.graphql.

About

API stubbing technique to quickly mock backend service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published