Moving On

During this chapter, you’ve learned an important new skill: how to build and use middleware that can modify the way fields are resolved during document execution. You know how to configure middleware on an individual basis, using the middleware/1,2 macros, and at the schema level, using middleware/3. Armed with this knowledge and an understanding of the MapGet middleware that’s used as Absinthe’s default resolution logic, you’re ready to build much more interesting patterns in your Absinthe schemas.

In the next chapter, we’re going to look at a critical use of middleware: securing your application behind authentication and authorization checks.

Before we move on, however, give this challenge a shot:

  1. Build some middleware that can be used to measure how long it takes to resolve a field. It should print how long it took and the current path. Hint: you may need to have the same middleware appear more than once in the middleware list. Consult the Absinthe.Resolution module docs to see what data is available to you in middleware.
  2. Apply the middleware to a specific field in our schema using the middleware/1,2 macro.
  3. Apply the middleware to all the fields in the schema that are running custom resolvers/middleware.

Once you’re feeling comfortable with the mechanics of building and applying middleware, let’s move on to how to use that knowledge to secure our API.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.59