0
0
GraphQLquery~20 mins

Validation errors in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What error occurs with missing required field?
Given this GraphQL schema snippet:
type User { id: ID! name: String! age: Int }

What error will occur if you run this query?
{ user { id age } }
GraphQL
{ user { id age } }
AField 'age' does not exist on type 'User'.
BSyntax error: Unexpected token 'user'.
CNo error, query runs successfully.
DField 'name' of required type 'String!' was not provided.
Attempts:
2 left
💡 Hint
Non-nullable fields (!) do not need to be selected in the query.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this GraphQL query
What is the syntax error in this query?
{ user(id: 1) { id name age } 
GraphQL
{ user(id: 1) { id name age } 
AInvalid argument type for 'id', should be a string.
BMissing closing brace '}' at the end of the query.
CField 'age' is not defined in the schema.
DExtra comma after 'name' field.
Attempts:
2 left
💡 Hint
Count the opening and closing braces.
🔧 Debug
advanced
2:00remaining
Why does this query fail with 'Unknown argument' error?
Given the schema:
type Query { user(id: ID!): User }

Why does this query fail?
{ user(userId: "123") { id name } }
GraphQL
{ user(userId: "123") { id name } }
AArgument name 'userId' does not match the schema, should be 'id'.
BID argument must be an integer, not a string.
CField 'name' is not defined in 'User' type.
DQuery is missing required field 'user'.
Attempts:
2 left
💡 Hint
Check argument names carefully against the schema.
🧠 Conceptual
advanced
2:00remaining
What causes a 'Field cannot be queried on type' error?
If you get an error saying a field cannot be queried on a type, what is the most likely cause?
AThe query is missing a required argument.
BThe query has a syntax error.
CThe field is deprecated but still queryable.
DThe field is not defined in the schema for that type.
Attempts:
2 left
💡 Hint
Think about schema definitions and allowed fields.
optimization
expert
2:00remaining
How to fix 'Variable "$id" of required type "ID!" was not provided' error?
Given this query:
query getUser($id: ID!) { user(id: $id) { id name } }

And this variables object:
{}

What is the best way to fix the error?
AProvide a value for the variable 'id' in the variables object.
BRemove the exclamation mark from 'ID!' in the query.
CRemove the variable and hardcode the id value in the query.
DChange the variable type to 'ID' without exclamation mark.
Attempts:
2 left
💡 Hint
Required variables must be given values when executing queries.