[ ] 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
Mocked values for fields that take in parameters are not respected when provided in a list.
If you have a field on an object that takes in parameters, and you attempt to mock that field in a list of those objects, the mocked value for the field is ignored, and a default value is provided instead.
To Reproduce Steps to reproduce the behavior:
The following code can be used to reproduce the issue
import { addMocksToSchema } from "@graphql-tools/mock";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { graphql } from "graphql";
const typeDefs = `#graphql
type UserGroup {
id: ID!
users: [User!]!
}
type User {
id: ID!
# User has a nullable membership field that takes in some input
membership(param: String!): Membership
}
type Membership {
id: ID!
}
type Query {
getUserGroup: UserGroup
}
`;
const query = /* GraphQL */ `
query GetUserGroup {
getUserGroup {
id
users {
id
# input is provided in the query here
membership(param: "test") {
id
}
}
}
}
`;
const mockSchema = addMocksToSchema({
schema: makeExecutableSchema({
typeDefs,
}),
mocks: {
UserGroup: () => ({
users: [
// Neither of these overrides work
{ membership: null },
{ membership: { id: "mock-membership-id" } },
],
}),
},
});
graphql(mockSchema, query).then((result) => console.log("Got result", result));
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
Mocked values for fields that take in parameters are not respected when provided in a list.
If you have a field on an object that takes in parameters, and you attempt to mock that field in a list of those objects, the mocked value for the field is ignored, and a default value is provided instead.
To Reproduce Steps to reproduce the behavior:
The following code can be used to reproduce the issue
The result that is printed out: As json
Screenshot of browser console:
Expected behavior
The overrides should work, and the returned result should be:
Environment:
@graphql-tools/mock
: 9.0.1@graphql-tools/schema
: 10.0.2graphql
: 15.8.0Additional context
The overrides work as expected with minor tweaks:
param
optional, and don't pass one in in the query, the overrides workmembership
via mockingUser
works as expected