I’ve set up the mock query data in index.js, but once in Apollo Studio Explorer, when I run the query, the response only returns the default ‘Hello world’ mock data. The fields from the schema are all there and correct, but the mock data is not returned – any idea what I’m doing wrong?
Index and schema files below
const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema');
const mocks = {
Query: () => ({
tracksForHome: () => [...new Array(6)],
}),
Track: () => ({
id: () => 'track_01',
title: () => 'Astro Kitty, Space Explorer',
author: () => {
return {
name: 'Grumpy Cat',
photo:
'https://res.cloudinary.com/dety84pbu/image/upload/v1606816219/kitty-veyron-sm_mctf3c.jpg',
};
},
thumbnail: () =>
'https://res.cloudinary.com/dety84pbu/image/upload/v1598465568/nebula_cat_djkt9r.jpg',
length: () => 1210,
modulesCount: () => 6,
}),
};
const server = new ApolloServer({
typeDefs,
mocks,
});
server.listen().then(() => {
console.log(`
🚀 Server is running!
🔉 Listening on port 4000
📭 Query at https://studio.apollographql.com/dev
`);
});
const { gql } = require('apollo-server');
const typeDefs = gql`
type Query {
"Query to get tracks array for the homepage grid"
tracksForHome: [Track!]!
}
"A track is a group of Modules that teaches about a specific topic"
type Track {
id: ID!
"The track's title"
title: String!
"The track's main Author"
author: Author!
"The track's illustration to display in track card or track page detail"
thumbnail: String
"The track's approximate length to complete, in minutes"
length: Int
"The number of modules this track contains"
modulesCount: Int
}
"Author of a complete Track or a Module"
type Author {
id: ID!
"Author's first and last name"
name: String!
"Author's profile picture"
photo: String
}
`;
module.exports = typeDefs;