Skip to content

Commit

Permalink
Fixed bug with default responses - only allow for top-level operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bashj79 committed Mar 8, 2021
1 parent c43f516 commit 2575226
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM bbyars/mountebank:2.4.0

ENV MB_GRAPHQL_VERSION=0.1.4
ENV MB_GRAPHQL_VERSION=0.1.5
RUN npm install -g mb-graphql@${MB_GRAPHQL_VERSION} --production

RUN mkdir /mb-graphql
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ the [mountbank mental model](https://www.mbtest.org/docs/mentalModel).
| `schemaEndpoint` | URL of a GraphQL schema file or the endpoint of an existing GraphQL API which exposes the GraphQL introspection query. | No, if `schema` is set | N/A |
| `schemaEndpointHeaders` | An object representing headers to passed to the schema endpoint defined in `schemaEndpoint` e.g. `Authorization` header. | No | An empty object. |
| `stubs` | The list of stubs responsible for matching a GraphQL request and returning a response. See further details below. | No | An empty array. |
| `defaultResponse` | The default response which will be used when no stub predicates match the query/mutation. | No | Default behaviour for the imposter is to return random data according to the defined schema. |
| `defaultResponse` | The default response for any top-level query/mutation performed against the schema. | No | Default behaviour for the imposter is to return random data according to the defined schema. |

## GraphQL Requests

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mb-graphql",
"version": "0.1.4",
"version": "0.1.5",
"description": "mountebank test doubles for GraphQL",
"author": "bashj79",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/handle-operation/mountebankHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default async (resolve, root, args, context, info) => {
pathKey,
} = getOperationTypeAndPathKey(info.path);

const topLevelOperation = !info.path.prev;
const {
response,
proxy,
Expand All @@ -20,6 +21,7 @@ export default async (resolve, root, args, context, info) => {
pathKey,
args,
headers: context.headers,
topLevelOperation,
});
if (proxy) {
const { to } = proxy;
Expand Down
3 changes: 2 additions & 1 deletion src/mountebank-adapter/getMountebankStubResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default async ({
pathKey,
args,
headers,
topLevelOperation,
}) => {
const stubResponse = await invokeMountebankCallback({
operationType,
Expand All @@ -18,7 +19,7 @@ export default async ({
response,
proxy,
} = stubResponse || {};
if (isEmptyObject(response) && !proxy) {
if (topLevelOperation && isEmptyObject(response) && !proxy) {
return getDefaultResponse();
}
return {
Expand Down

0 comments on commit 2575226

Please sign in to comment.