0
0
GraphQLquery~30 mins

GraphQL vs REST comparison - Hands-On Comparison

Choose your learning style9 modes available
Build a Simple GraphQL API to Compare GraphQL and REST
📖 Scenario: You are creating a small API to share information about the differences between GraphQL and REST. This API will help developers understand key points by querying the data.
🎯 Goal: Build a GraphQL schema with data about GraphQL and REST comparison, then write queries to fetch this data step-by-step.
📋 What You'll Learn
Create a GraphQL type called ComparisonPoint with fields id, topic, and description
Create a list of ComparisonPoint items with exact comparison data
Add a query type comparisonPoints that returns the list
Write a GraphQL query to fetch all comparison points with their topic and description
💡 Why This Matters
🌍 Real World
APIs often need to explain or document differences between technologies. This project shows how to build a simple GraphQL API to share such information.
💼 Career
Understanding GraphQL schema design, resolvers, and queries is essential for backend developers working with modern APIs.
Progress0 / 4 steps
1
Define the ComparisonPoint type and initial data
Create a GraphQL type called ComparisonPoint with fields id (ID!), topic (String!), and description (String!). Then create a list called comparisonPoints with these exact entries: { id: "1", topic: "Data Fetching", description: "GraphQL fetches exactly what you ask for, REST returns fixed data." } and { id: "2", topic: "Endpoints", description: "GraphQL uses a single endpoint, REST uses multiple endpoints." }.
GraphQL
Need a hint?

Define the type with three fields and create an array with two objects exactly as shown.

2
Add the Query type with comparisonPoints field
Add a GraphQL type Query with a field comparisonPoints that returns a list of ComparisonPoint. Then add a resolver function called comparisonPoints that returns the comparisonPoints list.
GraphQL
Need a hint?

Define the Query type with a field returning a list of ComparisonPoint. Then write a resolver returning the data list.

3
Write a GraphQL query to fetch all comparison points
Write a GraphQL query named GetComparisonPoints that fetches the topic and description fields from comparisonPoints.
GraphQL
Need a hint?

Write a query named GetComparisonPoints that requests topic and description fields from comparisonPoints.

4
Complete the GraphQL schema export
Export the GraphQL schema by combining the type definitions and resolvers. Use makeExecutableSchema from @graphql-tools/schema with typeDefs and resolvers.
GraphQL
Need a hint?

Use makeExecutableSchema with typeDefs and resolvers, then export the schema as default.