0
0
NestJSframework~20 mins

Schema-first approach in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema-first Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this NestJS GraphQL schema-first resolver?
Given this resolver method, what will be the returned value when the query hello is called?
NestJS
import { Resolver, Query } from '@nestjs/graphql';

@Resolver()
export class HelloResolver {
  @Query(() => String)
  hello() {
    return 'Hello, Schema-first!';
  }
}
AThrows a runtime error
Bnull
Cundefined
D"Hello, Schema-first!"
Attempts:
2 left
💡 Hint
Look at the return statement inside the resolver method.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a GraphQL schema type in schema-first approach?
Choose the valid GraphQL schema type definition for a User with fields id (ID!) and name (String).
Atype User { id: ID! name: String }
Btype User { id: ID name: String! }
Ctype User { id: ID! name: String! }
Dtype User { id: ID! name: Int }
Attempts:
2 left
💡 Hint
Check the required fields and their types carefully.
🔧 Debug
advanced
2:00remaining
What error does this NestJS schema-first resolver code produce?
Identify the error when running this resolver code:
NestJS
import { Resolver, Query } from '@nestjs/graphql';

@Resolver()
export class UserResolver {
  @Query(() => User)
  getUser() {
    return { id: 1, name: 'Alice' };
  }
}

class User {
  id: string;
  name: string;
}
ATypeError: Cannot read property 'id' of undefined
BGraphQL error: Expected type String, found Int
CSyntaxError: Unexpected token class
DNo error, returns user object correctly
Attempts:
2 left
💡 Hint
Check the type of the id field in the returned object versus the schema class.
state_output
advanced
2:00remaining
What is the value of result after executing this NestJS schema-first query resolver?
Consider this resolver method and the query call getNumbers:
NestJS
import { Resolver, Query, Int } from '@nestjs/graphql';

@Resolver()
export class NumberResolver {
  @Query(() => [Int])
  getNumbers() {
    return [1, 2, 3].map(x => x * 2);
  }
}

// Query: getNumbers
A[2, 4, 6]
BThrows a runtime error
C[0, 2, 4]
D[1, 2, 3]
Attempts:
2 left
💡 Hint
Look at the map function multiplying each number by 2.
🧠 Conceptual
expert
2:00remaining
Which statement best describes the schema-first approach in NestJS GraphQL?
Choose the most accurate description of the schema-first approach.
AResolvers are written without any schema, and schema is inferred at runtime.
BYou write TypeScript classes first, and the schema is generated automatically from them.
CYou write GraphQL schema definitions first, then implement resolvers to match the schema.
DSchema and resolvers are written together in a single file using decorators only.
Attempts:
2 left
💡 Hint
Think about the order of writing schema and resolvers in schema-first.