I have simple schema and server; Schema.js:
const typeDefs = gql`
type Query {
people: [Person!]!
}
type Person {
name: String!
age: Int!
job: String
}
`;
And my server:
const mocks = {
Person: () => ({
name: () => "Henry Adams",
age: () => 21,
})
};
const server = new ApolloServer({ typeDefs, mocks: mocks });
server.listen().then(() => {
console.log(`
Listening on port 4000
Query at http://localhost:4000
`);
});
The above works as expected when I query for it on graphIQL, I know how to have multiple of the same exact instance if I change the server.js to the following:
const mocks = {
Query: () => ({
people: () => [...new Array(4)],
}),
Person: () => ({
name: () => "Henry Adams",
age: () => 21,
})
};
const server = new ApolloServer({ typeDefs, mocks: mocks });
server.listen().then(() => {
console.log(`
Listening on port 4000
Query at http://localhost:4000
`);
});
This however is NOT what I am looking to do, instead I would like to do multiple different instances of the same type in my mock data, I have tried two different syntaxes and suprisingly cannot find this by googling: Syntax one:
const mocks = {
Person: () => ({
name: () => "Henry Adams",
age: () => 21,
}),
Person: () => ({
name: () => "Berry, Lee",
age: () => 28,
})
};
When I query with the above syntax only the second instance "Berry Lee" comes up. The second syntax I assumed would work:
const mocks = {
Person: () => ({
name: () => "Henry Adams",
age: () => 21,
},
{
name: () => "Berry, Lee",
age: () => 28,
}),
};
I have the same problem with this second syntax, only the second type shows up when querying.