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

generator-node-graphql

v2.0.0

Published

Generates a node project with graphql, mongoose and JWT auth

Downloads

9

Readme

generator-node-graphql

NPM version Dependency Status Node.js CI Total alerts Language grade: JavaScript

generates a node project with graphql and JWT

Installation

First, install Yeoman and generator-node-graphql using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-node-graphql

Then generate your new project:

yo node-graphql

You can also pass in some arguments or options as well

yo node-graphql --default
# Will generate a project with all question reverting to their default values, this will not prompt for any questions
yo node-graphql dog
# Will take the given string an use it as a parent folder name to place all code into, in this case, 'dog'

Generated code

If all default options are entered, the code generated should include a few runnable tests, as well as a runnable server.

Tests

The generated tests are written using Jest and provide an in memory database using mongodb-memory-server, as well as means to test any graphql resolvers and schema validations using easygraphql-tester.

The tests can be run as soon as the code is generated with:

npm run test

And a coverage report by:

npm run coverage

Source Code

The source code uses apollo-server-express along with express for graphql and the server, with the jsonwebtoken package to handle JWTs. It also uses @graphql-tools/merge and graphql-import-node for the graphql implementation, as well as dotenv for its environment files.

The server can be run with nodemon by:

npm run dev

Database

By default the chosen database is noSQL, which uses the mongoose package (keep in mind noSQL is currently the only option you can use). While the tests can run fine without any setup here, to properly run the server an instance of mongoDB should be created for the system to connect to. Please check the .env file and place your database credentials there.

What the code can do

Out of the box, if you have already set up a database, run the server and navigate to localhost:<PORT>/graphql

Out of the box, the system provides methods for creating a user, logging in and checking the logged in user (all methods using JWT for auth). If you navigate to the user.graphql file, you can see the provided mutations. Feel free to extend this here for your own system. But for now, if we want to create a user, we can simply enter the following in graphql playground

mutation {
  signup(username: "user", email: "[email protected]", password: "password")
}

Which will create a new user and return us a token.

From here we can either use that token or test the login, which we can do like this:

mutation {
  login(email: "[email protected]", password: "password")
}

The above also returns us a token. So now, let's verify and check who is currently logged in with our token.

In the HTTP HEADERS section in playground, enter the following

{
    "Authorization": "<YOUR TOKEN THAT WAS RETURNED>"
}

With the following query:

query {
    loggedInUser {
        id
        email
        password
    }
}

And when run, we should get information about the user we logged into / created earlier.

Directory Structure

The generated directory should look like this:

directory structure

License

MIT © Hudson Cassidy