βββ This project is currently under heavy development, with plans for a full rewrite in the coming months. βββ
instant mock is a powerful tool that helps developers quickly create GraphQL endpoints for seamless alignment between front-end and back-end teams. Whether you're working with a small team or an enterprise, instant mock has you covered with robust features, including Apollo Studio schema proposal integration.
-
Instant GraphQL Endpoint Creation: Get a mock GraphQL endpoint up and running in no time, so your team can start coding against it instantly.
-
Apollo Studio Schema Proposal Integration:
- π Highlight Feature: Seamlessly create mocks from schema proposals with full access to all schemas within the mock.
- π Multiple Schema Support: Host multiple mocks from different schema proposals, allowing for advanced testing and development.
-
Realistic Mock Responses:
- π Get fake responses tailored to your schema, with the ability to refine these as your project evolves.
-
Advanced Data Seeding:
- π± Seed your mock data with basic or advanced options, enabling realistic testing scenarios.
- π οΈ Pre-fill seed data with advanced sets of proposals for more tailored testing.
-
Flexible Hosting Options:
- π₯οΈ Run locally for quick testing.
- π³ Use Docker for a containerized setup.
- π’ Works with corporate proxy
- βοΈ Host centrally to share the mock with multiple teams, ensuring everyone is on the same page.
- π Provided AWS CDK template for easy deployment to AWS
- π More soon
-
Install instant mock:
npm install instant-mock
-
Access your mock in Apollo Studio:
- Connect to your schema proposals and start using the mock endpoint.
- Hosting Multiple Mocks: Create and manage multiple mocks for different schema proposals, perfect for large teams with complex requirements.
- Data Seeding: Utilize advanced data seeding techniques to populate your mocks with realistic data, ensuring your tests are as close to production as possible.
Check out our full documentation for more detailed instructions and advanced usage examples.
We welcome contributions! Please read our contributing guide to get started.
This project is licensed under the MIT License - see the LICENSE file for details.
THE ABOVE IS A TEMPLATE GENERATED BY AI. Looks great, probabyl sucks as content
Here is the real content:
use the api to create a mock programmatically. Here's an example:
# create a mock
# create a seed
- Endpoint:
GET api/graphs
- Description: Retrieves a list of all available graphs.
- Response: JSON array of graph objects.
- Endpoint:
GET api/graphs/:graphId
- Description: Retrieves the details of a specific graph by its
graphId
. - Parameters:
graphId
(path param): The ID of the graph.withSubgraphs
(query param): Optional boolean parameter. If set to true, the response will include the given graph along with all its subgraphs
- Response: JSON object of the requested graph. If withSubgraphs=true, the response will include the graph and all subgraphs of variants.
- Endpoint:
POST api/graphs/:graphId/:variantName/proposals
- Description: Creates a schema proposal for a specific variant of the graph.
- Query Parameters:
graphId
(required): The ID of the graph.variantName
(required): The variant name of the graph.
- Request Body:
{ "displayName": "string", "description": "string (optional)", }
- Endpoint:
GET api/seeds
- Description: Retrieves a list of all seeds for a given graph and variant.
- Query Parameters:
graphId
(required): The ID of the graph.variantName
(required): The variant name of the graph.
- Response: JSON array of seed objects.
- Endpoint:
POST api/seeds
- Description: Creates a new seed for a specific graph and variant.
- Query Parameters:
graphId
(required): The ID of the graph.variantName
(required): The variant name of the graph.
- Request Body:
{ "seedResponse": { ... }, "operationName": "string", "operationMatchArguments": { ... }, "sequenceId": "string" }
- Endpoint:
GET /seeds/:id
- Description: Retrieves the details of a specific seed by its
id
. - Parameters:
id
(path param): The ID of the seed.
- Response: JSON object containing the requested seed details.
- Endpoint:
DELETE /seeds/:id
- Description: Deletes a specific seed by its
id
. - Parameters:
id
(path param): The ID of the seed.
- Response: JSON object confirming the deletion of the seed.
- Look at your wireframes and determine the demand for data
- Identify the gaps in your schema
- Create a schema proposal in Apollo Studio
- Once the schema proposal passes Apollo's composition checks, it will show up in InstantMock
- Pick the schema proposal from within InstantMock to see the endpoint and header details you need
- Make a call to the endpoint with the header info, and correctly typed fake responses for all operation permutations from your Supergraph
- Share the mock with your team and profit!
InstantMock supports powerful data seeding and sequencing capabilities.
Imagine that you are creating an end-to-end experience that spans across multiple services. The UI state depends on the sequence of queries and mutations being routed to disparate Subgraphs.
InstantMock allows you to create a sequence of operations that represent the state of your application.
Here's how you do it:
- Once you have created an InstantMock for given schema proposal
- Open the InstantMock UI at
<server-url>/seeds
, and click on "create a seed sequence" (or use the API) - You'll see a sequence UI where you can add / remove queries and mutations
- For each operation, add a response. Note, you can click the "pre-fill" button to get a fake response to speed up the process
- Repeat until you have a sequence that represents the experience you are building across the Subgraphs
Here's an example: sequence [blah] = [
- query > response [foo]
- query > response [bar]
- mutation > response ...
- query > response [baz] ]
sequence [another] = [
- query > response [bar]
- query > response [bar]
- query > response [baz] ]
- session id (client id today)
- sequenced state management (finite state machine)
An InstantMock is intended to unblock development and testing. You can manually mark a sequence as "implemented" in InstantMock, or you can opt to track the status of the Schema in Apollo Studio. This will make the sequence throw an error if it is hit in the future, prompting you to update the sequence.
FUTURE SCOPE: Data pass-through where the mock will pass the request to the actual service and return responses that exist, and fake the data that is not yet implemented.
Use the Narrative Studio to create a narrative that represents the end-to-end experience you are building. The Narrative Studio will automatically create a sequence of operations to create seeds in InstantMock. Find out more at www.narrative.tech/instant-mock
- Consume schema from a running server | push schema from CI
- Determine the demand for data and create a schema delta
npx run instant-mock
Current State: POC showing support for mocking multiple GraphQL supergraphs and with persisted seed storage.
Make sure a backend/.env
is provided with the APOLLO_API_KEY
var set and frontend/.env
is provided with REACT_APP_API_BASE_URL
, which points to the backend (defult http://localhost:3001
).
-
Install Node Version Manager (nvm):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash`
-
Frontend:
-
Navigate to the
frontend
directory:cd frontend npm install npm run start
-
-
Backend:
-
Navigate to the
backend
directory in a new terminal:cd backend npm install npm run dev
-
Make sure a backend/.env
is provided with the APOLLO_API_KEY
var set.
-
Build Image:
docker build -t xolvio/instant-mock .
-
Run Container:
docker run -d -p 3001:3001 xolvio/instant-mock
Note: Docker Compose is not supported due to networking limitations.