Author with fields id (ID), name (String), and posts (list of Post)Post with fields id (ID), title (String), and content (String)Query type with a field authors returning a list of AuthorJump into concepts and practice - no test required
Author with fields id (ID), name (String), and posts (list of Post)Post with fields id (ID), title (String), and content (String)Query type with a field authors returning a list of AuthorAuthor and Post with the exact fields: Author has id (ID), name (String), and posts (list of Post). Post has id (ID), title (String), and content (String).Use type keyword to define types. Lists are wrapped in square brackets like [Post].
Query type with a field authors that returns a list of Author.The root query type is named Query. Define authors as a list of Author.
maxDepth and set it to 2 to limit query depth.Use const maxDepth = 2 to create the depth limit variable.
maxDepth to restrict queries to depth 2. Use depthLimit(maxDepth) in your GraphQL server setup.Use validationRules: [depthLimit(maxDepth)] in your ApolloServer config to apply depth limiting.
What is the main purpose of depth limiting in GraphQL?
Which of the following is the correct way to set a maximum query depth of 5 in a GraphQL server using graphql-depth-limit?
const depthLimit = require('graphql-depth-limit');
const server = new ApolloServer({
schema,
validationRules: [ /* ??? */ ]
});Given this GraphQL query and a server with depth limit set to 3, what will happen?
{
user {
posts {
comments {
text
}
}
}
}What is wrong with this GraphQL server setup code that tries to limit query depth?
const depthLimit = require('graphql-depth-limit');
const server = new ApolloServer({
schema,
validationRules: depthLimit(4)
});You want to allow queries up to depth 4 but block deeper ones. You also want to log a warning when a query exceeds the limit. Which approach correctly combines depth limiting with custom logging in a GraphQL server?
const depthLimit = require('graphql-depth-limit');
const { ApolloServer } = require('apollo-server');
const loggingDepthLimit = (maxDepth) => {
return (context) => {
const validationRule = depthLimit(maxDepth);
return (validationContext) => {
const errors = validationRule(validationContext);
if (errors && errors.length > 0) {
console.warn('Query depth exceeded:', errors);
}
return errors;
};
};
};
const server = new ApolloServer({
schema,
validationRules: [loggingDepthLimit(4)]
});