0
0
GraphQLquery~10 mins

Relationship design patterns in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a one-to-many relationship between Author and Book.

GraphQL
type Author {
  id: ID!
  name: String!
  books: [[1]!]!
}
Drag options to blanks, or click blank then click option'
AID
BAuthor
CString
DBook
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same type as the parent (Author) instead of the related type (Book).
Using scalar types like String or ID instead of the related object type.
2fill in blank
medium

Complete the code to define a many-to-many relationship between Student and Course.

GraphQL
type Student {
  id: ID!
  name: String!
  courses: [[1]!]!
}

type Course {
  id: ID!
  title: String!
  students: [Student!]!
}
Drag options to blanks, or click blank then click option'
AString
BCourse
CStudent
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same type as the parent (Student) instead of the related type (Course).
Using scalar types like String or ID instead of the related object type.
3fill in blank
hard

Fix the error in the code to correctly define a one-to-one relationship between User and Profile.

GraphQL
type User {
  id: ID!
  username: String!
  profile: [1]
}

type Profile {
  id: ID!
  bio: String
  user: User!
}
Drag options to blanks, or click blank then click option'
AProfile!
B[Profile!]
CString
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list type for a one-to-one relationship.
Omitting the non-nullable marker when the relationship is required.
4fill in blank
hard

Fill both blanks to define a bidirectional one-to-many relationship between Category and Product.

GraphQL
type Category {
  id: ID!
  name: String!
  products: [[1]!]!
}

type Product {
  id: ID!
  name: String!
  category: [2]!
}
Drag options to blanks, or click blank then click option'
AProduct
BCategory
CString
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the types in the list and single fields.
Using scalar types instead of object types.
5fill in blank
hard

Fill all three blanks to define a many-to-many relationship with an intermediate type Enrollment between Student and Course.

GraphQL
type Student {
  id: ID!
  name: String!
  enrollments: [[1]!]!
}

type Course {
  id: ID!
  title: String!
  enrollments: [Enrollment!]!
}

type Enrollment {
  id: ID!
  student: [2]!
  course: [3]!
}
Drag options to blanks, or click blank then click option'
AEnrollment
BStudent
CCourse
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using scalar types instead of object types in relationships.
Mixing up the types in the intermediate type fields.