Given this Apollo Server schema and resolver, what will be the output of the query { hello }?
const { ApolloServer, gql } = require('apollo-server'); const typeDefs = gql` type Query { hello: String } `; const resolvers = { Query: { hello: () => 'Hello, world!' } }; const server = new ApolloServer({ typeDefs, resolvers });
Check the resolver function for the hello field.
The resolver for hello returns the string 'Hello, world!'. So the query returns this string under the hello key.
Which option contains a syntax error in the Apollo Server setup code?
const { ApolloServer, gql } = require('apollo-server'); const typeDefs = gql` type Query { greet: String } `; const resolvers = { Query: { greet: () => 'Hi!' } }; const server = new ApolloServer({ typeDefs, resolvers });
Look at the arrow function syntax inside the resolvers object.
Option D uses incorrect arrow function syntax: greet() => 'Hi!' is invalid. It should be greet: () => 'Hi!'.
You have a large schema with many types and resolvers. Which option best improves Apollo Server startup performance?
Think about loading only what is needed when it is needed.
Lazy loading parts of the schema and resolvers delays loading until necessary, reducing initial startup time.
What is the main purpose of the context function in Apollo Server setup?
Think about what data resolvers might need access to for each request.
The context function creates an object shared by all resolvers for a single request, often used for authentication info or database connections.
Given this resolver code, what error will Apollo Server return when querying { user(id: "1") { name } } if the user is not found?
const resolvers = { Query: { user: (_, { id }) => { const user = database.findUserById(id); if (!user) { throw new Error('User not found'); } return user; } } };
Recall how Apollo Server handles errors thrown in resolvers.
When a resolver throws an error, Apollo Server sets the corresponding field to null in data and adds the error to the errors array.