Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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
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
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
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
Hint
Use an if statement to check linting_enabled and call the lint function.
Practice
(1/5)
1. What is the main purpose of schema linting in GraphQL?
easy
A. To generate database tables automatically
B. To execute queries faster
C. To check the schema for mistakes and style issues
D. To encrypt data in the schema
Solution
Step 1: Understand schema linting role
Schema linting is used to find errors and style problems in GraphQL schemas.
Step 2: Compare with other options
Options B, C, and D describe unrelated tasks like query speed, database creation, or encryption.
Final Answer:
To check the schema for mistakes and style issues -> Option C
Quick Check:
Schema linting = check mistakes and style [OK]
Hint: Linting means checking code or schema for errors [OK]
Common Mistakes:
Confusing linting with query execution
Thinking linting creates database tables
Assuming linting encrypts data
2. Which of the following is a correct way to define a linting rule for a GraphQL schema?
easy
A. schemaLint: off
B. lintSchema = false
C. enableLinting = 0
D. "no-unused-types": true
Solution
Step 1: Identify correct lint rule syntax
Linting rules are usually defined as key-value pairs like "no-unused-types": true.
Step 2: Check other options for syntax errors
Options A, B, and D use invalid or incorrect syntax for linting rules.
Final Answer:
"no-unused-types": true -> Option D
Quick Check:
Lint rule syntax = key: value [OK]
Hint: Lint rules use key-value pairs like "rule-name": true [OK]
What will happen if the schema uses a deprecated field without a description?
medium
A. Linting will pass without errors
B. Linting will report errors for both deprecated field and missing description
C. Linting will only check for missing descriptions
D. Linting will ignore deprecated fields
Solution
Step 1: Analyze linting rules
"no-deprecated-fields": true means deprecated fields cause errors. "require-description": true means missing descriptions cause errors.
Step 2: Apply rules to schema case
Schema has a deprecated field without description, so both rules trigger errors.
Final Answer:
Linting will report errors for both deprecated field and missing description -> Option B
Quick Check:
Both rules active = errors for both issues [OK]
Hint: Active lint rules cause errors for matching schema issues [OK]
Common Mistakes:
Assuming lint ignores deprecated fields
Thinking only one rule applies
Believing missing description is allowed
4. You run a schema linter and get an error: Field 'userAge' is missing a description. Which fix will resolve this error?
medium
A. Add a description string above the 'userAge' field in the schema
B. Rename the field to 'ageUser'
C. Remove the 'userAge' field from the schema
D. Ignore the error and continue
Solution
Step 1: Understand the error meaning
The error says the field lacks a description, so the linter expects a comment or description string.
Step 2: Choose the fix that adds description
Adding a description string above the field satisfies the linter. Renaming or removing the field or ignoring the error does not fix the missing description.
Final Answer:
Add a description string above the 'userAge' field in the schema -> Option A
Quick Check:
Missing description = add description [OK]
Hint: Add descriptions as comments to fix missing description errors [OK]
Common Mistakes:
Renaming field instead of adding description
Deleting field unnecessarily
Ignoring lint errors
5. You want to enforce that all GraphQL schema types have descriptions and no unused types exist. Which combined linting configuration achieves this?
hard
A. { "require-description": true, "no-unused-types": true }
B. { "allow-unused-types": true, "require-description": false }
C. { "no-deprecated-fields": true, "allow-unused-types": false }
D. { "require-description": false, "no-unused-types": false }
Solution
Step 1: Identify rules for descriptions and unused types