Thanks to mocking, UI development can begin before the backend is fully functional. The UI can be tested without having to wait for lengthy database operations or maintaining a full-fledged GraphQL server.

There are a number of community-built tools, such as graphql-tools, graphql-faker, and Apollo Server’s in-built mocking feature, that make it simple to simulate user interactions with a GraphQL API by simulating their queries and schema.

In order to test our resolvers before actually implementing them, let’s use Apollo Server’s mocking feature to simulate GraphQL requests.

Head to the src/index.ts file and simply add mocks: true to Apollo Server, as follows:

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

The mocking functionality built into Apollo Server is simplistic. A value of the same type as the associated field is simply returned based on the type definitions. Please enter the following query into Apollo Studio:

query { 
  findUsers(searchQuery:"ahmed"){ 
    id name email postsCount 
  } 

  findPostsByUserId(userId:"10"){ 
    id text postBy { id name } commentsCount 
    latestComment { id comment } 
    datetime 
  } 
} 
In the same series:
[11] Mocking GraphQL with Apollo Server
[10] GraphQL APIs with Apollo Server & Apollo Studio [Part 2]
[9] GraphQL APIs with Apollo Server & Apollo Studio
[8] Watch and compile TypeScript code to JavaScript
[7] Setup TypeScript with Node.js & Express.js
[6] Setup the server with Node.js/Express.js/Apollo
[5] Storing data with PostgreSQL and TypeORM
[4] Using GraphQL and Apollo for front- and back-end integration
[3] Using NVM on Windows
[2] How to Use Node.js to Run JavaScript on Servers
[1] Modern full-stack single-page apps' architecture