0
0
GraphQLquery~30 mins

Schema linting in GraphQL - Mini Project: Build & Apply

Choose your learning style9 modes available
GraphQL Schema Linting
📖 Scenario: You are working on a GraphQL API for a book store. You want to make sure your schema is clean and follows good practices before sharing it with your team.
🎯 Goal: Build a simple GraphQL schema and add linting rules to check for common issues like missing descriptions and consistent naming.
📋 What You'll Learn
Create a GraphQL schema with types for Book and Author
Add a configuration variable to enable linting rules
Write a linting function that checks for missing descriptions on types and fields
Complete the linting setup to output linting results for the schema
💡 Why This Matters
🌍 Real World
GraphQL schema linting helps teams maintain clean, consistent API definitions that are easier to understand and maintain.
💼 Career
Many companies use GraphQL for APIs; knowing how to write and lint schemas is valuable for backend and full-stack developers.
Progress0 / 4 steps
1
Create the GraphQL schema
Create a GraphQL schema string called schema with these exact types: Book with fields id: ID!, title: String!, and author: Author!; and Author with fields id: ID! and name: String!.
GraphQL
Need a hint?

Define the schema as a multiline string with the exact types and fields.

2
Add linting configuration
Create a variable called linting_enabled and set it to True to enable linting.
GraphQL
Need a hint?

Just create a boolean variable named linting_enabled and set it to True.

3
Write linting function
Write a function called lint_schema that takes schema as input and returns a list called issues. The function should check if the schema string contains the word "description". If not, add the string "Missing descriptions in schema" to issues. Return issues.
GraphQL
Need a hint?

Check if the word description is missing in the schema string and add a message to the list.

4
Complete linting setup
Add code that checks if linting_enabled is True. If yes, call lint_schema(schema) and store the result in a variable called lint_results.
GraphQL
Need a hint?

Use an if statement to check linting_enabled and call the lint function.