Bird
0
0

Consider the following resolver chain:

medium📝 query result Q5 of 15
GraphQL - Resolvers
Consider the following resolver chain:
const resolvers = {
  Query: {
    post: () => ({ id: 10, title: 'GraphQL Rocks' })
  },
  Post: {
    summary: (parent) => parent.title.slice(0, 7)
  }
};

What is the output of the query?
{ post { summary } }
AError: slice is not a function
B{ "post": { "summary": "GraphQL" } }
C{ "post": { "summary": "GraphQL R" } }
D{ "post": { "summary": "GraphQL Rocks" } }
Step-by-Step Solution
Solution:
  1. Step 1: Check the post resolver output

    Returns { id: 10, title: 'GraphQL Rocks' }.
  2. Step 2: Check the Post.summary resolver

    It slices the title string from index 0 to 7, which is 'GraphQL'.
  3. Final Answer:

    { "post": { "summary": "GraphQL" } } -> Option B
  4. Quick Check:

    String slice output = { "post": { "summary": "GraphQL" } } [OK]
Quick Trick: Use parent to access previous resolver's data [OK]
Common Mistakes:
  • Slicing incorrectly or off-by-one errors
  • Assuming slice returns full string
  • Confusing slice with substring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes