This version of HTTP snapshots differs from #5921 by implementing a snapshot server. This can be used similarly to a wiremock server. It listens on a local port, and proxies requests to an upstream HTTP API. Responses are stored in a local file, and subsequent matching requests return the stored response.
This has several advantages:
The implementation is completely separate from the router and does not require changes to the router or the router config. The existing override_subgraph_url and override_url config can be used to point the router to the running snapshot server.
The standalone server can be used to snapshot any HTTP requests, not just those made by Connectors. For example, it can be used with regular subgraph requests.
This implementation can be integrated with the existing samples_tests integration tests, used in unit tests, or used with Apollo Sandbox.
An existing integration test and unit test are migrated to the snapshot server to demonstrate how it can be used.
The implementation is behind a snapshot feature flag.
Below is an example of running a standalone server and connecting to it from Sandbox:
> cargo run --bin snapshot --features="snapshot" -- --snapshot-path /tmp/snapshots.json --url https://jsonPlaceholder.typicode.com/ --offline --port 5280
...
2024-09-20T01:54:43.377471Z INFO apollo_router::test_harness::http_snapshot: Running in offline mode ⛔️
2024-09-20T01:54:43.380146Z INFO apollo_router::test_harness::http_snapshot: Loaded 11 snapshots
2024-09-20T01:54:43.502781Z INFO apollo_router::test_harness::http_snapshot: Snapshot server listening on port 5280
2024-09-20T01:55:16.314233Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users method=GET
2024-09-20T01:55:16.323124Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/1/posts method=GET
2024-09-20T01:55:16.323451Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/2/posts method=GET
2024-09-20T01:55:16.323723Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/8/posts method=GET
2024-09-20T01:55:16.323957Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/4/posts method=GET
2024-09-20T01:55:16.324189Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/3/posts method=GET
2024-09-20T01:55:16.324437Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/5/posts method=GET
2024-09-20T01:55:16.324641Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/10/posts method=GET
2024-09-20T01:55:16.324788Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/6/posts method=GET
2024-09-20T01:55:16.324930Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/7/posts method=GET
2024-09-20T01:55:16.325033Z INFO apollo_router::test_harness::http_snapshot: Found existing snapshot url=https://jsonPlaceholder.typicode.com/users/9/posts method=GET
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
[ ] Changes are compatible[^1]
[ ] Documentation[^2] completed
[ ] Performance impact assessed and acceptable
Tests added and passing[^3]
[x] Unit Tests
[x] Integration Tests
[ ] Manual Tests
Exceptions
Notes
[^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.
[^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples.
[^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.
This version of HTTP snapshots differs from #5921 by implementing a snapshot server. This can be used similarly to a
wiremock
server. It listens on a local port, and proxies requests to an upstream HTTP API. Responses are stored in a local file, and subsequent matching requests return the stored response.This has several advantages:
override_subgraph_url
andoverride_url
config can be used to point the router to the running snapshot server.samples_tests
integration tests, used in unit tests, or used with Apollo Sandbox.An existing integration test and unit test are migrated to the snapshot server to demonstrate how it can be used.
The implementation is behind a
snapshot
feature flag.Below is an example of running a standalone server and connecting to it from Sandbox:
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Notes
[^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.