0
0
GraphQLquery~10 mins

Response caching strategies 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 a cache control directive for a GraphQL query response.

GraphQL
query GetUser { user(id: 1) @cacheControl(maxAge: [1]) { id name } }
Drag options to blanks, or click blank then click option'
Atrue
Bnull
C"max-age"
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean value instead of a number for maxAge.
Using a string instead of a number for maxAge.
2fill in blank
medium

Complete the code to add a cache hint to a GraphQL resolver.

GraphQL
const resolvers = { Query: { user: (parent, args, context) => { context.cacheControl.setCacheHint({ [1]: 120 }); return getUser(args.id); } } };
Drag options to blanks, or click blank then click option'
AmaxAge
Bcache
Cttl
Dduration
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'ttl' or 'duration'.
Omitting the property name and passing only a number.
3fill in blank
hard

Fix the error in the cache control directive usage in this GraphQL schema snippet.

GraphQL
type Query { user(id: ID!): User @cacheControl(maxAge: [1]) }
Drag options to blanks, or click blank then click option'
A60
Btrue
C"60"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for maxAge.
Using a boolean value instead of a number.
4fill in blank
hard

Fill both blanks to set cache hints with maxAge and scope in a resolver.

GraphQL
context.cacheControl.setCacheHint({ [1]: 300, scope: '[2]' });
Drag options to blanks, or click blank then click option'
AmaxAge
Bscope
CPUBLIC
DPRIVATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names.
Using scope values without quotes.
5fill in blank
hard

Fill all three blanks to define a cache control directive with maxAge, scope, and inheritMaxAge.

GraphQL
type Query { posts: [Post] @cacheControl(maxAge: [1], scope: [2], inheritMaxAge: [3]) }
Drag options to blanks, or click blank then click option'
A120
BPUBLIC
Ctrue
DPRIVATE
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around maxAge number.
Using unquoted scope values.
Using string instead of boolean for inheritMaxAge.