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

apollo-couchbase

v0.0.43

Published

A framework for building an Apollo GraphQL API backed by Couchbase.

Downloads

40

Readme

Apollo On The Couch

A framework for building GraphQL APIs with the Apollo GraphQL server backed by Couchbase.

The main inspiration for this framework is Ruby On Rails which was a game-changer when it came. But, Ruby On Rails has five huge sub-optimalities that
Apollo On The Couch aims to fix:

  1. Scalability: It didn't scale seamlessly from start up to millions of operations per second.
  2. Reliability: It required lots of infrastructure work to become enterprise-grade reliable.
  3. Capability: It didn't support full-text search and analytics out-of-the-box.
  4. Cost-effectiveness: It required a lot of infrastructure work to be able to run cost-effectively.
  5. REST vs GraphQL: It's default API was REST which is sub-optimal in so many ways compared to GraphQL.

With Apollo On The Couch you get all of the benefits with the Ruby On Rails approach and all of the above mentioned sub-optimalities fixed out-of-the-box with amazing developer and devops experience all the way from startup to millions of operations per second.

Getting Started

Prerequisites

Create Your Apollo On The Couch Server Project

Create a Typescript project with the appropriate dependencies.

npx create-apollo-couchbase-server@latest my-server

Configure the Couchbase Environment Variables in the .env file

Set the username and password of your Couchbase user.

COUCHBASE_USER=username
COUCHBASE_PASSWORD=password

Choose if you'd like to activate access control and if you want to require a JWT token to be sent as an authorization header in all requests.

AUTH=true
AUTH_ALL=false
AUTH_TOKEN_ISSUER=https://<Your Identity Provider>
AUTH_TOKEN_AUDIENCE=<Your client id>

Generate a resource

In apollo-couchbase, the GraphQL schema and resolvers are structured in units called resources. A resource will typically be similar to a REST resource, with CrUD operations, but it can really be whatever kind of group of functions that makes sense for your purposes.

If you want your resource to be similar to a typical REST resource you can use the scaffolding script, generate-resource, to generate a new resource. This script will generate resources with scaffold resolvers and schema files that you can edit to fit your purposes. You can also choose to create your resources manually if you want a different structure.

To create a resource using the scaffolding script, follow these steps:

Run the generate-resource script:

npm run generate-resource <resourceNameInPlural>

E.g

npm run generate-resource products

The new resource files are located at /src/graphql/resources/<resourceNameInPlural>. With directories for the resolvers and a schema file called schema.graphql.

Edit the resource schema file

Specify the properties you want to expose on the resource.

E.g.

type ProductContent {
    name: String!
    price: Float
    quantity: Int
    tags: [String!]
}

input ProductContentInput {
    name: String!
    price: Float
    quantity: Int
    tags: [String!]
}

input ProductContentPatchInput {
    name: String
    price: Float
    quantity: Int
    tags: [String!]
}

input ProductsListFiltersInput {
  name: String
}

Notice that there is no exclamation mark in the ProductContentPatchInput input, since you probably don't want to require any field to be included when patching records.

This script with create a collection in Couchbase if it didn't already exist and a primary index on that collection.

Generate the Typescript types for the new resource

After editing a schema file you need to run the generate-graphql-types script to update the Typescript types:

npm run generate-graphql-types

Start the server

Now, you are ready to start the server.

npm run dev

License

This project is licensed under the ISC License. See the LICENSE file for details.