0
0
GraphQLquery~20 mins

Prisma ORM with GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Prisma GraphQL Master
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 Prisma query in GraphQL?

Given a Prisma model User with fields id, name, and age, what will this GraphQL query return?

query {
  users(where: { age: { gt: 30 } }) {
    id
    name
  }
}
GraphQL
model User {
  id   Int    @id @default(autoincrement())
  name String
  age  Int
}
ASyntaxError: Invalid query
B[{ id: 2, name: "Bob" }]
C[]
D[{ id: 1, name: "Alice" }, { id: 3, name: "Charlie" }]
Attempts:
2 left
💡 Hint

Think about filtering users older than 30.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a Prisma schema for a Post with a relation to User?

Choose the correct Prisma schema snippet that defines a Post model with a relation to User via authorId.

A
model Post {
  id       Int    @id @default(autoincrement())
  title    String
  authorId Int
  author   User   @relation(fields: [authorId], references: [id])
}
B
model Post {
  id       Int    @id @default(autoincrement())
  title    String
  authorId Int @relation
  author   User
}
C
model Post {
  id       Int    @id
  title    String
  authorId Int
  author   User
}
D
model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId])
}
Attempts:
2 left
💡 Hint

Relations require specifying both fields and references.

optimization
advanced
2:00remaining
How to optimize fetching posts with their authors in Prisma GraphQL query?

You want to fetch all posts with their authors' names efficiently. Which Prisma client query is best?

Aprisma.post.findMany({ include: { author: true } })
Bprisma.post.findMany({ select: { title: true } })
Cprisma.post.findMany({ where: { author: { name: { contains: "A" } } } })
Dprisma.post.findMany()
Attempts:
2 left
💡 Hint

Including related data avoids extra queries.

🔧 Debug
advanced
2:00remaining
What error does this Prisma GraphQL mutation cause?

Given this mutation, what error will occur?

mutation {
  createUser(data: { name: "Eve", age: "twenty" }) {
    id
    name
  }
}
ARuntimeError: User already exists
BSyntaxError: Invalid mutation syntax
CTypeError: age must be an Int, not a String
DNo error, user created successfully
Attempts:
2 left
💡 Hint

Check the data types in the mutation.

🧠 Conceptual
expert
2:00remaining
Which statement best describes Prisma's role in a GraphQL API?

Choose the most accurate description of how Prisma works with GraphQL.

APrisma is a frontend library that renders GraphQL queries in the browser.
BPrisma acts as an ORM that maps GraphQL queries directly to database operations, simplifying data fetching and mutations.
CPrisma replaces GraphQL and handles all API requests internally without a schema.
DPrisma only works with REST APIs and cannot be used with GraphQL.
Attempts:
2 left
💡 Hint

Think about Prisma's function between your database and GraphQL server.