1.0.0 • Published 2 years ago

desolver v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago
  1. Installing DeSolver
  • Start by running the npm command:
npm install desolver
  • The DeSolver framework works best when combined with GraphQL tools Executable Schema package. It is recommended to download that package and use that to generate your type definitions, resolver map and schema.

  • The DeSolver framework is compatible with the popular Apollo Server API. DeSolver can be utilized when combined with the resolver map object in Apollo Server.

  • Redis is used for caching resolvers. Check out Redis and node-redis for installation details. When not using Redis or when using custom caching logic, DeSolver provides a configuration option to disable this default behavior.

How to use

The desolver.use() method has the following parameters:

  • ResolverType: A string which matches the Resolver Type in your Resolver Map object. Pass the string 'All' if you want to chain the prehook functions to all your resolvers.
  • DeSolverFragments: Add any number of functions in the form of DeSolver Fragments to chain to the target Resolver Type.

Multiple successive invocations of desolver.use() will also add additional functions to the pipeline.

The following is an example use case for the desolver middleware pipeline involving guarding root queries with authentication logic:

const desolver = new Desolver()
 
// Declare authentication Desolver Fragment Function
const authentication = (parent, args, context, info, next, escapeHatch, ds) => {
 // Define some authentication logic here using args or context
 // throw error if not authenticated
}
 
// Add the authentication function to pipeline with desolver.use()
// This function will execute prior to all Query resolvers
desolver.use('Query', authentication)
 
// Invoke desolver.apply() method with the resolver map object passed
const resolvers = desolver.apply({
 Query: {
   getUserById: (parent, args, context, info) => {
     // this root query is now guarded by the authentication function
   },
 
   getPostsById: (parent, args, context, info) => {
     // this root query is now guarded by the authentication function
   },
 }
 
 // Additional resolvers here
})

desolver.use('Mutation', authentication, authorization)

const resolvers = desolver.apply({ Query: { // Query resolvers are guarded only by authentication function getUserById: desolver.useRoute(desolverFragment1, desolverFragment2),

getPostsById: (parent, { id }, context, info) => { return ctx.db.findPosts(id) }, }

Mutation: { createUser: (parent, root, args, context, info) => { // This mutation resolver is now guarded by both authentication and authorization functions } } })

<p><br>
<h3 href="#team"></h3>
 
# **Contributors**
 
DeSolver is an open-source community project on Github and accelerated by [OS Labs](https://opensourcelabs.io/). We are maintained by a small group of dedicated software engineers. We appreciate your participation, feedback, bug fixes and feature developments.
 
<p><br>
 
|                     | GitHub                           | LinkedIn                                        |
| ------------------- | -------------------------------- | ----------------------------------------------- |
| Michael Chan        | https://github.com/mckchan13     | https://www.linkedin.com/in/michael-ck-chan/    |
| Mia Kang            | https://github.com/jcmiakang     | https://www.linkedin.com/in/mia-kang/           |
| Alexander Gurfinkel | https://github.com/AlexGurfinkel | https://www.linkedin.com/in/alexandergurfinkel/ |
| Julia Hickey        | https://github.com/hijulia1136   | https://www.linkedin.com/in/juliahickey/        |
 
<p><br>

If you are interested in creating an open-source project that builds on top of DeSolver, please don't hesitate to reach out, and we'd be happy to provide feedback and support here or via [DeSolver LinkedIn](https://www.linkedin.com/company/desolver/).

<p><br>
<h3 href="#license"></h3>
 
# License
 
This product is licensed under the MIT License - see the LICENSE.md file for details.
 
This is an open source product.
 
This product is accelerated by [OS Labs](https://github.com/oslabs-beta).