Skip to content

better tool to wrap your resolver in graphql-compose ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽค

Notifications You must be signed in to change notification settings

zapkub/graphql-compose-schema-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

graphql-compose-schema-wrapper

NOTE: this repository require graphql-compose to work properly

graphql-compose-schema-wrapper - is a tools that let you can easily manage your wrapper in graphql-compose schema.

Such as verify session, Authorization, middleware and more

Installation

yarn add graphql-compose graphql graphql-compose-schema-wrapper

Usage

  • After your schema setup is done, pick resolvers or field your need to wrap (by path selector) and then use wrapResolvers, wrapResolverHelper or wrapResolverFieldHelper to wrap what you need

Use wrapResolvers

// wrap with wrapResolvers
GQC.rootQuery().addFields(
  wrapResolvers(
    {
      // list of fields you want to expose to rootQuery
      getVersionInfoWrap: info.getResolver('get')
    },
    next => rp => {
      // implement your logic here before
      // resolve data
      return next(rp)
    }
  )
)

Use wrapResolverHelper and wrapResolverFieldHelper

// wrap with path selector helper
// setup your schema
GQC.rootQuery().addFields({
  getVersionInfo: info.getResolver('get')
})
GQC.rootMutation().addFields({
  updateVersionInfo: info.getResolver('set')
})
wrapResolverHelper(
  ['Query.getVersionInfo.$get', 'Mutation.updateVersionInfo.$set'],
  next => rp => {
    // implement your logic here before
    // resolve data
    return next(rp)
  }
)

wrapResolverFieldHelper(['Query.getVersionInfoWrap.$get.version'], rp => {
    // implement your logic here before
    // resolve data
  return rp.source
})

Development

  • clone this repository
  • Run command below
yarn tsc // compile typescript ( optional watch use -w )
yarn dev // start graphql server

Limitation (PLEASE READ CAREFULLY)

  • graphql-compose-schema-wrapper cannot use with nested Resolver inside TypeComposer or Relation ( only support rootQuery and rootMutation )

LICENSE

MIT

About

better tool to wrap your resolver in graphql-compose ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽค

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published