0
0
GraphQLquery~20 mins

One-to-one relationships in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
One-to-One GraphQL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Querying a one-to-one relationship in GraphQL

Given the following GraphQL schema snippet:

type User {
  id: ID!
  name: String!
  profile: Profile
}

type Profile {
  id: ID!
  bio: String
  user: User!
}

What will be the result of this query?

{
  user(id: "1") {
    name
    profile {
      bio
    }
  }
}
A{"data": {"user": null}}
B{"data": {"user": {"name": "Alice", "profile": {"bio": "Loves hiking"}}}}
C{"data": {"user": {"name": "Alice", "profile": null}}}
DSyntaxError: Query missing required fields
Attempts:
2 left
💡 Hint

Remember that in a one-to-one relationship, the related object is either present or null.

🧠 Conceptual
intermediate
1:30remaining
Understanding one-to-one relationships in GraphQL

Which statement best describes a one-to-one relationship in GraphQL?

AEach object in type A is linked to exactly one object in type B, and vice versa.
BEach object in type A can be linked to many objects in type B.
CObjects in type A and B are unrelated and cannot reference each other.
DEach object in type A is linked to zero or more objects in type B.
Attempts:
2 left
💡 Hint

Think about the meaning of 'one-to-one' in everyday relationships.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL schema for one-to-one

Find the syntax error in this GraphQL schema snippet defining a one-to-one relationship:

type Author {
  id: ID!
  name: String!
  biography: Biography
}

type Biography {
  id: ID!
  text: String!
  author: Author
}
AThere is no syntax error; the schema is valid.
BThe field 'author' in Biography should be non-nullable (Author!).
CThe type 'Biography' must have a list of authors, not a single author.
DThe field 'biography' in Author should be non-nullable (Biography!).
Attempts:
2 left
💡 Hint

Check if the schema syntax follows GraphQL rules for types and fields.

optimization
advanced
1:30remaining
Optimizing data fetching in one-to-one GraphQL queries

You want to fetch a user and their profile data in one query. Which approach is best to avoid unnecessary data fetching?

AQuery only user fields and fetch profile data later with a separate query.
BQuery user and profile fields separately in two queries.
CQuery user with profile fields nested in the same query.
DQuery profile fields only and ignore user fields.
Attempts:
2 left
💡 Hint

Think about how GraphQL allows nested queries to reduce round trips.

🔧 Debug
expert
2:30remaining
Debugging null profile in one-to-one GraphQL query

Given this query:

{
  user(id: "2") {
    name
    profile {
      bio
    }
  }
}

The response is:

{"data": {"user": {"name": "Bob", "profile": null}}}

What is the most likely cause?

AThe query syntax is invalid and causes profile to be null.
BThe profile field is not defined in the GraphQL schema.
CThe user with id "2" does not exist.
DUser with id "2" does not have a linked profile in the database.
Attempts:
2 left
💡 Hint

Consider what a null nested object means in GraphQL responses.