-
-
Notifications
You must be signed in to change notification settings - Fork 831
Description
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure the GraphQL Tools package versions under
package.json
matches yours. - 2. A failing test has been provided
- 3. A local solution has been provided
- 4. A pull request is pending review
Describe the bug
It seems impossible to simulate a situation where you are returned a partial set of the fields you have requested in a query. This is a very common scenario I want to test. Your UI needs to be able to handle that situation. Seemingly no matter what I try, graphql-mock returns an error when I attempt to do this. I would really appreciate help.
To Reproduce
Steps to reproduce the behavior:
const typeDefs = `#graphql
type AuthConfig {
twoFactorEnabled: Boolean
}
type OrgConfig {
auth: AuthConfig
defaultSecurityPolicy: String
}
type Query {
getOrgConfig: OrgConfig
}
`;
const query = /* GraphQL */ `
query getOrgConfig {
getOrgConfig {
auth {
twoFactorEnabled
}
defaultSecurityPolicy
}
}
`;
const mockSchema = addMocksToSchema({
schema: makeExecutableSchema({
typeDefs,
}),
mocks: {
AuthConfig: () => undefined,
},
});
graphql(mockSchema, query).then((result) => console.log("Got result", result));
Expected behavior
I expect a partial return value to be acceptable, as it is in real, not mocked, GQL.
If I try to mock AuthConfig as undefined or null I get the following
Got result {
errors: [
Error: Value returned by the mock for AuthConfig is not an object.......
This make sense given the following code:
graphql-tools/packages/mock/src/MockStore.ts
Line 433 in 0f149dc
throw new Error(`Value returned by the mock for ${typeName} is not an object`); |
My main question is how are you supposed to simulate a partial result situation if the Mocking library mandates a value for every field.
Environment:
-
OS: Mac
-
├─ @graphql-tools/[email protected]
│ └─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
│ └─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
│ └─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
└─ [email protected]
└─ @graphql-tools/[email protected] -
NodeJS: 14.18.1