Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
generator-apollo-knex
Advanced tools
A Generator for a simple apollo server integrated with knex
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.
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.
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
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]
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.MIT © danwakeem
FAQs
A Generator for a simple apollo server integrated with knex
The npm package generator-apollo-knex receives a total of 0 weekly downloads. As such, generator-apollo-knex popularity was classified as not popular.
We found that generator-apollo-knex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.