Help for Lift-off part 6 Odyssey course

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;

Hello @cathlevettgraphics !
I took a look at your code. It looks fine to me. Maybe your explorer settings are the cause:
on the studio explorer settings, the “mock responses” option should be toggled off, otherwise that would generate “hello world” for every String fields:

.
other than that, the previous code example:

const server = new ApolloServer({
  typeDefs,
  mocks: true
});

would yield "hello world"s as well, maybe the changes you’ve made to your index file weren’t saved (which normally would have trigger a server restart from nodemon). Just to make sure, you could try to save and restart the server manually.
Hope this helps, let me know.
Best,
Raph

Hello Raph !
Thank you so much for that advice – yes, the mock responses” option was toggled on
Working a treat now :slight_smile:

Much appreciated!
Best
Cath

Awesome! Hope you’ll have fun with the rest of the course(s)!

1 Like