npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elleon

v0.1.11

Published

library for graphql and node

Downloads

13

Readme

Elleon

A Graph QL framework for Node.js and the most popular orm and odm i.e. sequelize and mongoose.

Getting Started

npm i elleon

Example

Apollo Server 1

const { graphqlExpress, graphiqlExpress } = require('apollo-server-express');


const models = require('./models');)
let elleon = require('elleon');

const elleonInstance = new elleon({logging:false, sequelize:{models:models} , resolver_path:__dirname+'/resolvers', });
let schema = elleonInstance.makeExecuteableSchema();
let graph_app = graphqlExpress({
                    schema: schema,
                    context: {
                      models,
                  }),
                  
app.use(
 '/graphql',
  bodyParser.json(),
  graph_app,
);

Apollo Server 2

const { ApolloServer } = require('apollo-server-express');
const cors          = require('cors');
const models        = require('./models');
const elleon        = require('elleon');

const app = express();
app.use(cors('*'));


const elleonInstance = new elleon({logging:false, sequelize:{models:models} , resolver_path:__dirname+'/resolvers', });
const typesResolvers = elleonInstance.getTypeDefsAndResolvers();

const server = new ApolloServer({ typeDefs:typesResolvers.typeDefs, resolvers:typesResolvers.resolvers });
server.applyMiddleware({ app });

let port = 3000;
app.listen({ port }, () =>
    console.log(`Server ready at http://localhost:${port}${server.graphqlPath}`),
);

Resolvers

Make a directory, e.g. resolvers. We now group each file by function instead of type of resolver. So lets say we have user functionality. we would make a file called user.resolver.js In it we would include:


module.exports.getUser = {
  type: 'Query',
  arguments: false,
  returnType: 'User',
  resolver: () => {
    return {
        email: '[email protected]',
        name: 'john doe',
    }
  }
};

module.exports.loginUser = {
  type: 'Query',
  arguments: '(email: String, password: String)',
  returnType: 'User',
  resolver: (data, args) => {
    console.log(data, args);
    return {
        id: 2,
        email:'[email protected]',
    }
  },
};

The returnType value could be

returnType: 'User'
returnType: '[User]'
returnType: ['User']
returnType: ()=>this.models.User.schemaTypeName
returnType: ()=>[this.models.User.schemaTypeName]

Built In CRUD functionality

We have 5 boolean options

getSingleQuery
getAllQuery
createMutation
updateMutation
deleteMutation
const elleonInstance = new elleon({
    sequelize:{models:models}, 
    resolver_path:__dirname+'/resolvers', 
    getSingleQuery: true,
    createMutation: true,
});

Example Sequelize Schema

contains custom options for graphql schema

const bcrypt 			= require('bcrypt');
const bcrypt_p 			= require('bcrypt-promise');
const {to}              = require('await-to-js');

module.exports = (sequelize, DataTypes) => {
  const User = sequelize.define('user', {
    email: {
      type: DataTypes.STRING,
      unique: true,
    },
    password: {
      type:DataTypes.STRING,
      graphql: { getQueryAttribute:false, getQueryInput:false },
    },
  });

  User.beforeSave(async (user, options) => {
      let err;
      if (user.changed('password')){
          let salt, hash
          [err, salt] = await to(bcrypt.genSalt(10));
          if(err) TE(err.message, true);

          [err, hash] = await to(bcrypt.hash(user.password, salt));
          if(err) TE(err.message, true);

          user.password = hash;
      }
  });

  User.prototype.comparePassword = async function (pw) {
      let err, pass
      if(!this.password) TE('password not set');

      [err, pass] = await to(bcrypt_p.compare(pw, this.password));
      if(err) TE(err);

      if(!pass) TE('invalid password');

      return this;
  };


  User.graphqlOptions = {
      addAttributes:{
          jwt:{schemaType:'String', relation:'one'}//options one or many
      },
  };

  return User;
};