This container is usefull in you local development environment or for integration testing also locally or in your CI pipeline.
Thanks to module gqlmocks you can simply share a schema of a third party service inside the container and get a fully working GraphQL API.
This is an example of a docker-compose.yml you can use:
version: "3.7"
services:
graphql-api-mock:
image: michalsimon/gqlmocks:latest
volumes:
- ./api.graphql:/gqlmocks/schema.graphql
command: npx gqlmocks serve --port=4002 --schema=./schema.graphql
ports:
- 4002:4002
According to the documentation, you can also define mock handler.js to serve your own mock data:
const fs = require('fs');
const { GraphQLHandler } = require("graphql-mocks");
const schema = fs.readFileSync('./schema.graphql', {
encoding: 'utf8',
flag: 'r',
});
const resolverMap = {
Query: {
userInfo() {
return {
id: 'ef2699bb-0977-48e6-8f07-42118d34660d',
};
},
},
};
module.exports = new GraphQLHandler({
resolverMap,
dependencies: {
graphqlSchema: schema,
},
});
To use a custom handler your command needs to have the correct parameter:
npx gqlmocks serve --port=4002 --schema=./schema.graphql --schema=./schema.graphql
Content type
Image
Digest
sha256:9013513ba…
Size
101 MB
Last updated
over 1 year ago
docker pull michalsimon/gqlmocks