0
0
GraphQLquery~10 mins

Depth limiting in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the maximum query depth to 3.

GraphQL
const server = new ApolloServer({ schema, validationRules: [depthLimit({ maxDepth: [1] })] });
Drag options to blanks, or click blank then click option'
A3
B10
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting maxDepth too high defeats the purpose of depth limiting.
Using a string instead of a number for maxDepth.
2fill in blank
medium

Complete the code to import the depthLimit function from the correct package.

GraphQL
import [1] from 'graphql-depth-limit';
Drag options to blanks, or click blank then click option'
AdepthLimiter
BdepthLimit
ClimitDepth
DdepthLimitRule
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names that do not exist in the package.
Forgetting to install the package before importing.
3fill in blank
hard

Fix the error in the validationRules array to correctly apply depth limiting.

GraphQL
const server = new ApolloServer({ schema, validationRules: [[1]] });
Drag options to blanks, or click blank then click option'
AdepthLimit({ maxDepth: 3 })
BdepthLimit
CdepthLimitRule(3)
DdepthLimit(3)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function without calling it.
Using incorrect argument types.
4fill in blank
hard

Fill both blanks to create a validation rule that limits depth to 4 and logs a warning on violation.

GraphQL
const depthLimitRule = depthLimit({ maxDepth: [1], onError: (err) => console.[2]('Depth limit exceeded:', err) });
Drag options to blanks, or click blank then click option'
A4
Bwarn
Cerror
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log instead of console.warn for warnings.
Setting maxDepth to a string instead of a number.
5fill in blank
hard

Fill all three blanks to define a GraphQL server with depth limiting set to 2, using the imported depthLimit function and applying it in validationRules.

GraphQL
import [1] from 'graphql-depth-limit';

const server = new ApolloServer({
  schema,
  validationRules: [[2]([3])]
});
Drag options to blanks, or click blank then click option'
AdepthLimit
C{ maxDepth: 2 }
DdepthLimiter
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and usage.
Passing maxDepth as a number directly instead of inside an object.