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?
Check how the input type fields are used and if optional fields are included.
The input type AddressInput includes zip as optional, but it is provided in the query. The resolver concatenates all fields with commas, so the output includes all three parts separated by commas.
Choose the correct GraphQL input type definition for a complex argument representing a product with name (string), price (float), and tags (list of strings).
Remember input types use input keyword and field types must match expected data.
Option B correctly uses input keyword, required fields with !, and a list of non-null strings for tags. Option B uses type which is invalid for input. Options C and D have wrong types or missing list structure.
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?
Check the nullability of list elements in the input type.
The input type defines 'priceRange' as a list of non-null floats ([Float!]), so null values inside the list are not allowed. The variable includes a null element, causing validation failure.
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?
Think about minimizing data transfer by avoiding unnecessary fields.
Sending only changed fields reduces payload size and improves efficiency. Sending all fields or converting to JSON string increases size or complexity. Using key-value pairs is not standard and may complicate schema.
Choose the best explanation for why GraphQL requires separate input types for complex arguments rather than reusing type definitions.
Consider the difference in purpose between input and output types in GraphQL.
Input types are restricted to fields with input data only and cannot have resolvers or functions, which prevents side effects and ensures safe validation. Regular object types can have resolvers and are used for output data.