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-apollo-knex

v0.0.1

Published

A Generator for a simple apollo server integrated with knex

Downloads

2

Readme

generator-apollo-knex NPM version Build Status Dependency Status Coverage percentage

A Generator for a simple apollo server integrated with knex

I should point out this was inspired by the apollo-typescript-starter. There are a few changes I made to this config vs. the original but thought it would be nice to have a generator around this.

Installation

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

npm install -g yo
npm install -g generator-apollo-knex

Then generate your new project:

yo apollo-knex

This project configures Knex with postgres out of the box but you can change this by installing a compatible Knex npm database package and adding the DATABASE_CLIENT name to the .env file.

Generating a new schema

This generator also includes a CLI to create a new graphql schema that will automatically get picked up by the server.

To generate a new schema run and follow the prompts:

yo apollo-knex:schema

Important: This doesn't not create a new Knex migrate file for you. If the new schema you are creating is supposed to link up with your database, then follow the db migration pattern in Knex.

There is a script in the package.json file for you project that will allow you to run knex commands without installing knex globally. Example: npm run knex migrate:make migration_name

Project structure

Below is a default generated project structure and some brief explanation for each folder/file

.
├── Dockerfile                           # Standard Dockerfile for building to a container
├── README.md                            # README for the project. (I would appreciate input on how to make this better)
├── db                                   # Folder containing all of the Knex migrations/seed data
│   ├── migrations
│   │   └── 20180128104235_initial.js    # Initial database schema (Set up as a postgres schema, if you change the db be sure to change this as well)
│   └── seeds
│       └── initial.js                   # Seed data that can be run in your docker container
├── docker-compose.yml                   # Compose file that contains a db instance and your apollo app
├── knexfile.js                          # Builds the Knex connection config that is fed into the Database.ts file
├── license                              # Some license file
├── nodemon.json                         
├── package-lock.json
├── package.json
├── src
│   ├── context.ts                       # Where the database connection gets attached to the graphql context. You would want to add data loaders and things here depending on what you are doing.
│   ├── database.ts                      # Manages the actual database connection
│   ├── main.ts                          # Manages closing out the db connection
│   ├── schema.ts                        # Aggregates all the schemas in the schemas folder into a single graphql schema that is fed into  the ApolloServer config
│   ├── schemas
│   │   ├── index.ts                     # Index file to export all of your schemas so it is easily digested by the schema.ts file
│   │   ├── sample
│   │   │   ├── sample.spec.ts           # Spec with example stubs for database queries
│   │   │   └── sample.ts                # Implementation file for the sample schema
│   └── server.ts                        # Apollo/Express server setup
├── tsconfig.json                        # typescript configuration
├── tslint.json                          # typescript linting options
└── util
   └── wait-for-it.sh                   # A helper I use for waiting for a docker db to be started before starting the application (See example in the package.json file) [1]
  • [1] This is taken directly from the wait-for-it repo. I don't know a better way to include this in the project so if you have suggestions, by all means.

Getting To Know Yeoman

  • Yeoman has a heart of gold.
  • Yeoman is a person with feelings and opinions, but is very easy to work with.
  • Yeoman can be too opinionated at times but is easily convinced not to be.
  • Feel free to learn more about Yeoman.

License

MIT © danwakeem