0
0
GraphQLquery~20 mins

Input type for complex arguments in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Input Mastery
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 with complex input?

Given the following GraphQL schema snippet:

input AddressInput {
  street: String!
  city: String!
  zip: String
}

type Query {
  getUserAddress(id: ID!, address: AddressInput!): String
}

And this query:

{
  getUserAddress(id: "123", address: {street: "Main St", city: "Springfield", zip: "01101"})
}

What is the expected output assuming the resolver returns the concatenated address string?

A{"data": {"getUserAddress": "Main St, Springfield"}}
B{"data": {"getUserAddress": "Main St Springfield 01101"}}
C{"data": {"getUserAddress": "Main St, Springfield, 01101"}}
D{"errors": [{"message": "Field 'zip' is required"}]}
Attempts:
2 left
💡 Hint

Check how the input type fields are used and if optional fields are included.

📝 Syntax
intermediate
1:30remaining
Which option is a valid GraphQL input type definition for a complex argument?

Choose the correct GraphQL input type definition for a complex argument representing a product with name (string), price (float), and tags (list of strings).

A
input ProductInput {
  name: String!
  price: Float
  tags: String!
}
B
input ProductInput {
  name: String!
  price: Float!
  tags: [String!]!
}
C
input ProductInput {
  name: String
  price: Int
  tags: String
}
D
type ProductInput {
  name: String!
  price: Float!
  tags: [String!]!
}
Attempts:
2 left
💡 Hint

Remember input types use input keyword and field types must match expected data.

🔧 Debug
advanced
2:00remaining
Why does this GraphQL query fail with a validation error?

Given this input type and query:

input FilterInput {
  category: String
  priceRange: [Float!]
}

query getProducts($filter: FilterInput!) {
  products(filter: $filter) {
    id
    name
  }
}

Variables sent:

{"filter": {"category": "Books", "priceRange": [10, null, 30]}}

Why does the query fail?

ABecause 'priceRange' contains a null value but is defined as a list of non-null floats.
BBecause the variable 'filter' is missing required fields.
CBecause 'category' is optional but provided as a string.
DBecause the query is missing a selection set for 'products'.
Attempts:
2 left
💡 Hint

Check the nullability of list elements in the input type.

optimization
advanced
1:30remaining
How to optimize a GraphQL mutation with complex input to reduce payload size?

You have a mutation that accepts a complex input type with many optional fields. Which approach best reduces the payload size sent from client to server?

ASend only the fields that have changed values in the input object.
BUse a list of key-value pairs instead of an input object.
CConvert the input object to a JSON string and send as a single scalar.
DSend all fields with default or null values to ensure completeness.
Attempts:
2 left
💡 Hint

Think about minimizing data transfer by avoiding unnecessary fields.

🧠 Conceptual
expert
2:30remaining
What is the main reason GraphQL uses input types for complex arguments instead of regular object types?

Choose the best explanation for why GraphQL requires separate input types for complex arguments rather than reusing type definitions.

AInput types automatically generate database schemas, unlike regular types.
BInput types allow circular references which regular object types do not support.
CInput types can include subscriptions which regular types cannot.
DInput types are designed to be immutable and cannot have fields that resolve to functions, ensuring safe input validation.
Attempts:
2 left
💡 Hint

Consider the difference in purpose between input and output types in GraphQL.