Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-server-decorators

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-server-decorators

Create graphql server easier

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

graphql-server-decorators

Decorators that help creating graphql server easier These decorators don't create types or input. It just help create domain's mutations or queries

@controller

Add prototypes getQueries and getMutations into a class

@query(specs)

  • specs: Object
    • name: String. Optional. Default is generate from class name and method name. Ex: User_find, User_findOne
    • description: String. Optional
    • type: GraphqlType. Required
    • args: query arguments. Optional

@mutation(specs)

  • specs: Object
    • name: String. Optional. Default is generate from class name and method name. Ex: User_create, User_delete

    • description: String. Optional

    • type: GraphqlType. Required

    • args: mutation arguments. Optional

@controller
class Product {
  @query({
    type: Products
  })
  find(root, args, context) {
    const collection = context.collections.Product;
    return collection.find();
  }

  @query({
    name: 'getProduct'
    type: Product,
    args: {
      id: {
        type: new GraphQLNonNull(GraphQLString)
      }
    }
  })
  findOne(root, args, context) {
    const collection = context.collections.Product;
    return collection.findOne({id: args.id});
  }
  // mutations
  @mutation({
    type: Product,
    args: CreateProductArgs
  })
  create(root, args, context) {
    const collection = context.collections.Product;
    return collection.save(args.data);
  }
}

// Add to schema
const product = new Product();

let schemaDef = {
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      ...product.getQueries()
    }
  }),
  mutation: new GraphQLObjectType({
    name: 'Mutation',
    fields: {
      ...product.getMutations()
    }
  }),
};
const schema =  new GraphQLSchema(schemaDef);

Keywords

FAQs

Package last updated on 12 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc