Given the following GraphQL mutation and input type, what will be the returned data?
input NewUserInput {
username: String!
age: Int
}
mutation CreateUser($input: NewUserInput!) {
createUser(input: $input) {
id
username
age
}
}Variables:
{"input": {"username": "alice", "age": 30}}input NewUserInput {
username: String!
age: Int
}
mutation CreateUser($input: NewUserInput!) {
createUser(input: $input) {
id
username
age
}
}Check which fields are required and what the mutation returns.
The input type requires 'username' but 'age' is optional. The mutation returns all requested fields including 'age' if provided.
Choose the valid syntax for defining an input type in GraphQL.
Remember input types use the keyword input and fields must have types.
Option A correctly uses input keyword and specifies field types properly. Option A uses type which is for object types, not input. Option A misses type for age. Option A misses colon after name.
You want to create a mutation that accepts a user with an address. Which input type design is best for performance and clarity?
Consider reusability and clear structure for nested data.
Option B uses nested input types properly, improving clarity and reusability. Option B flattens address fields which can be less clear. Option B uses a string for address which loses structure. Option B uses 'type' instead of 'input' for UserInput, which is invalid for inputs.
Given this input type and mutation, why does the following query cause an error?
input ProductInput {
name: String!
price: Float!
}
mutation AddProduct($input: ProductInput!) {
addProduct(input: $input) {
id
name
price
}
}Variables:
{"input": {"name": "Book"}}Check which fields are required and if all required fields are provided.
The 'price' field is marked as non-nullable (Float!) but is missing in the variables, causing an error.
Choose the statement that best explains the difference between input types and object types in GraphQL.
Think about where input types and object types are used in GraphQL operations.
Input types are designed for input data and cannot contain fields that are object types (only other input types or scalars). Object types define the data shape returned by queries or mutations. They are not interchangeable.