Skip to content

Commit 2575226

Browse files
author
bashj79
committed
Fixed bug with default responses - only allow for top-level operations
1 parent c43f516 commit 2575226

6 files changed

Lines changed: 8 additions & 5 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM bbyars/mountebank:2.4.0
22

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

66
RUN mkdir /mb-graphql

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ the [mountbank mental model](https://www.mbtest.org/docs/mentalModel).
127127
| `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 |
128128
| `schemaEndpointHeaders` | An object representing headers to passed to the schema endpoint defined in `schemaEndpoint` e.g. `Authorization` header. | No | An empty object. |
129129
| `stubs` | The list of stubs responsible for matching a GraphQL request and returning a response. See further details below. | No | An empty array. |
130-
| `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. |
130+
| `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. |
131131

132132
## GraphQL Requests
133133

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mb-graphql",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "mountebank test doubles for GraphQL",
55
"author": "bashj79",
66
"license": "MIT",

src/handle-operation/mountebankHandler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default async (resolve, root, args, context, info) => {
1212
pathKey,
1313
} = getOperationTypeAndPathKey(info.path);
1414

15+
const topLevelOperation = !info.path.prev;
1516
const {
1617
response,
1718
proxy,
@@ -20,6 +21,7 @@ export default async (resolve, root, args, context, info) => {
2021
pathKey,
2122
args,
2223
headers: context.headers,
24+
topLevelOperation,
2325
});
2426
if (proxy) {
2527
const { to } = proxy;

src/mountebank-adapter/getMountebankStubResponse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default async ({
77
pathKey,
88
args,
99
headers,
10+
topLevelOperation,
1011
}) => {
1112
const stubResponse = await invokeMountebankCallback({
1213
operationType,
@@ -18,7 +19,7 @@ export default async ({
1819
response,
1920
proxy,
2021
} = stubResponse || {};
21-
if (isEmptyObject(response) && !proxy) {
22+
if (topLevelOperation && isEmptyObject(response) && !proxy) {
2223
return getDefaultResponse();
2324
}
2425
return {

0 commit comments

Comments
 (0)