0
0
GraphQLquery~20 mins

First GraphQL query - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this GraphQL query?

Given a GraphQL schema with a Book type having fields title and author, and a query:

{ books { title author } }

What is the expected output if the data contains two books: "1984" by "George Orwell" and "Brave New World" by "Aldous Huxley"?

GraphQL
{ books { title author } }
A{"data":{"books":[{"author":"George Orwell"},{"author":"Aldous Huxley"}]}}
B{"data":{"books":[{"title":"1984"},{"title":"Brave New World"}]}}
C{"errors":[{"message":"Field 'author' not found"}]}
D{"data":{"books":[{"title":"1984","author":"George Orwell"},{"title":"Brave New World","author":"Aldous Huxley"}]}}
Attempts:
2 left
💡 Hint

Remember that the query requests both title and author fields for each book.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes a GraphQL query?

Choose the statement that correctly describes what a GraphQL query does.

AIt sends a full database dump from the server to the client.
BIt requests specific fields from the server, returning only the requested data.
CIt updates data on the server without returning any data.
DIt automatically generates a user interface based on the schema.
Attempts:
2 left
💡 Hint

Think about how GraphQL differs from REST in terms of data fetching.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL query

Find the syntax error in the following GraphQL query:

{ books { title author } 
GraphQL
{ books { title author } 
AThe query must start with the keyword 'query'.
BField names must be quoted with double quotes.
CMissing closing brace '}' at the end of the query.
DThe fields must be separated by commas.
Attempts:
2 left
💡 Hint

Check if all braces are properly closed.

optimization
advanced
1:30remaining
How to reduce data transfer in a GraphQL query?

You want to fetch only the book titles from a large list of books to reduce data transfer. Which query is best?

A{ books { title } }
B{ books { title author } }
C{ books }
D{ books { id } }
Attempts:
2 left
💡 Hint

Only request the fields you need.

🔧 Debug
expert
2:30remaining
Why does this GraphQL query return an error?

Given the schema where Book has fields title and author, why does this query return an error?

{ books { title publisher } }
GraphQL
{ books { title publisher } }
AThe field 'publisher' does not exist in the 'Book' type.
BThe query is missing a root operation type like 'query'.
CThe field 'title' must be nested inside 'author'.
DGraphQL queries cannot request more than one field.
Attempts:
2 left
💡 Hint

Check if all requested fields exist in the schema.