# Luna Tech

Tutorials For Dummies.

# 1. Resolver

Not only root fields, but virtually all fields on the types in a GraphQL schema have resolver functions.

## Batched Resolving

In JavaScript, the above strategies can be implemented using a utility called DataLoader , and there are similar utilities for other languages.

## query resolution process

Effectively, all the GraphQL server has to do is invoke all resolver functions for the fields that are contained in the query and then package up the response according to the query’s shape. Query resolution thus merely becomes a process of orchestrating the invocation of resolver functions!

## Resolver function

### args

Mutation 接收 variable 的方式。

### context

• A plain JavaScript object that every resolver in the resolver chain can read from and write to.
• A means for resolvers to communicate.
• You can write to the context when the GraphQL server itself is being initiated.
• We can attach an instance of Prisma Client (in another article) to the context when initiating the server and then access it from inside our resolvers via the context argument.

# 2. Caching

Challenging on server side.

# 3. Error handling

It returns a dedicated errors object in the server response.

{
"data": { ... },
"errors": [ ... ]
}


# 4. 怎么加新的 feature？

1. 先改 schema，比如加一个新的 type；
2. implement resolver to the added fields.

This process is also referred to as schema-driven or schema-first development.

# 5. Tips

One convenient thing about the constructor of the GraphQLServer is that typeDefs can be provided either directly as a string (as you previously did) or by referencing a file that contains your schema definition.