1.12.0 • Published 9 months ago

create-bison-app v1.12.0

Weekly downloads
5
License
MIT
Repository
github
Last release
9 months ago

Bison is a starter repository created out of real-world apps at Echobind. It represents our current "Greenfield Web Stack" that we use when creating web apps for clients.

We're always improving on this, and welcome suggestions from the community!

Technology

Features

Conventions

  • Don't copy/paste files, use generators and Hygen templates. Need to update the generator as your project evolves? they are all in the _templates folder.
  • Use a single command to run Next, generate Nexus types, and GraphQL types for the frontend. By doing this you can ensure your types are always up-to-date.
  • Don't manually write types for GraphQL responses... use the generated query hooks from GraphQL Codegen.
  • All frontend pages are static by default. If you need something server rendered, just add getServerSideProps like you would in any Next app.

Tradeoffs

  • To reduce complexity, Bison avoids yarn workspaces and separate top-level folders. Think of your app a bit more like a traditional monolith, but with a separate frontend and API. This means that folders may be a little more "intermingled" than your used to.
  • Currently, Bison only works on Vercel. We plan to add support for Netlify soon.

Alternatives

There are a few other projects that are rapidly maturing in the Full Stack JAMStack space.

RedwoodJS Redwood is a very promising framework we've got our eye on. We took the concept of "Cells" directly from Redwood (though admittedly our version takes a bit more code!).

Blitz.js Blitz is also very promising. Blitz is built on Next.js (which we love!) and takes a very different approach by attempting to "remove" the API layer using conventions provided by Next.js.

We may borrow concepts from Redwood and Blitz over time, and could even switch to one in the future as things continue to mature.

Think of Bison as a bit closer to the metal, but preconfigured for maximum DX and efficiency. The good news is, if you disagree with any of the choices we've made, nothing is hidden from you and you're welcome to adapt the "framework" to fit your needs.


Getting Started

Create a new repo fom the Bison template.

Using yarn:

yarn create bison-app MyApp

Using npx:

npx create-bison-app MyApp

Setup the database

  1. Setup your local database with yarn db:setup. You'll be prompted to create it if it doesn't already exist:

Prisma DB Create Prompt

If you'd like to change the database name or schema, change the DATABASE_URL in prisma/.env.

Run the app locally

From the root, run yarn dev. This:

  • runs next dev to run the frontend and serverless functions locally
  • starts a watcher to generate the Prisma client on schema changes
  • starts a watcher to generate TypeScript types for GraphQL files

Recommended Dev Workflow

You're not required to follow this exact workflow, but we've found it gives a good developer experience.

API

  1. Generate a new GraphQL module using yarn g:graphql.
  2. Write a type, query, input, or mutation using Nexus
  3. Create a new request test using yarn g:test:request
  4. Run yarn test to start the test watcher
  5. Add tests cases and update schema code accordingly
  6. The GraphQL playground (localhost:3000/api/graphql) can be helpful to form the proper queries to use in tests.
  7. types.ts and api.graphql should update automatically as you change files. Sometimes it's helpful to open these as a sanity check before moving on to the frontend code.

Frontend

  1. Generate a new page using yarn g:page
  2. Generate a new component using yarn g:component
  3. If you need to fetch data in your component, use a cell. Generate one using yarn g:cell (TODO)
  4. To generate a typed GraphQL query, simply add it to the component or page:
export const SIGNUP_MUTATION = gql`
  mutation signup($data: SignupInput!) {
    signup(data: $data) {
      token
      user {
        id
      }
    }
  }
`;
  1. Use the newly generated types from codegen instead of the typical useQuery or useMutation hook. For the example above, that would be useSignupMutation. You'll now have a fully typed response to work with!
import { User, useMeQuery } from './types';

// adding this will auto-generate a custom hook in ./types
export const ME_QUERY = gql`
  query me {
    me {
      id
      email
    }
  }
`;

// an example of taking a user as an argument with optional attributes
function noIdea(user: Partial<User>) {
  console.log(user.email);
}

function fakeComponent() {
  // use the generated hook
  const { data, loading, error } = useMeQuery();

  if (loading) return <Loading />;

  // data.user will be fully typed
  return <Success user={data.user}>
}

Set up CI

This project uses GitHub Actions for CI and should work out of the box. Note, as you add ENV vars to your app, you'll want to also add them in GitHub Secrets.

Easiest CI configuration ever, right?

Setup Preview / Production Deployments

To ensure your project can be deployed using GitHub Actions, you need to add a few ENV vars to GitHub Secrets:

ENV Vars

The Vercel project and org id, can be copied from .vercel/project.json. You can generate a token from https://vercel.com/account/tokens.

After tests pass, the app will deploy to Vercel. By default, every push creates a preview deployment. Merging to the main branch will deploy to staging, and pushing to the production branch will deploy to production.

If you'd like to change these configurations, update the section below:

## For a typical JAMstack flow, this should be your default branch.
## For a traditional flow that auto-deploys staging and deploys prod is as needed, keep as is
if: github.ref != 'refs/heads/production' # every branch EXCEPT production

FAQ

Where are the generated types?

TypeScript Types for GraphQL types, queries, and mutations are generated automatically and placed in ./types.ts.

VSCode can't find new types, even though they are in ./types.ts

Try reopening VSCode.

1.13.0-canary.26

10 months ago

1.13.0-canary.27

9 months ago

1.13.0-canary.28

9 months ago

1.13.0-canary.8

1 year ago

1.13.0-canary.9

1 year ago

1.13.0-canary.7

1 year ago

1.13.0-canary.6

2 years ago

1.13.0-canary.4

2 years ago

1.13.0-canary.5

2 years ago

1.13.0-canary.2

2 years ago

1.13.0-canary.3

2 years ago

1.12.0

2 years ago

1.13.0-canary.0

2 years ago

1.13.0-canary.1

2 years ago

1.12.0-canary.17

2 years ago

1.12.1-canary.2

2 years ago

1.12.1-canary.1

2 years ago

1.12.1-canary.0

2 years ago

1.12.0-canary.16

2 years ago

1.12.0-canary.15

2 years ago

1.12.0-canary.13

2 years ago

1.12.0-canary.12

2 years ago

1.12.0-canary.11

2 years ago

1.12.0-canary.14

2 years ago

1.12.0-canary.4

2 years ago

1.12.0-canary.5

2 years ago

1.12.0-canary.6

2 years ago

1.12.0-canary.7

2 years ago

1.12.0-canary.8

2 years ago

1.12.0-canary.9

2 years ago

1.12.0-canary.10

2 years ago

1.11.0-canary.23

3 years ago

1.12.0-canary.1

3 years ago

1.12.0-canary.2

3 years ago

1.12.0-canary.3

3 years ago

1.12.0-canary.0

3 years ago

1.11.0

3 years ago

1.11.0-canary.22

3 years ago

1.11.0-canary.21

3 years ago

1.11.0-canary.20

3 years ago

1.11.0-canary.18

3 years ago

1.11.0-canary.19

3 years ago

1.11.0-canary.17

3 years ago

1.11.0-canary.16

3 years ago

1.11.0-canary.15

3 years ago

1.11.0-canary.13

3 years ago

1.11.0-canary.14

3 years ago

1.11.0-canary.12

3 years ago

1.11.0-canary.11

3 years ago

1.11.0-canary.10

3 years ago

1.11.0-canary.9

3 years ago

1.11.0-canary.8

3 years ago

1.11.0-canary.7

3 years ago

1.11.0-canary.6

3 years ago

1.11.0-canary.5

3 years ago

1.11.0-canary.2

3 years ago

1.11.0-canary.3

3 years ago

1.11.0-canary.4

3 years ago

1.10.1-canary.5

3 years ago

1.11.0-canary.0

3 years ago

1.11.0-canary.1

3 years ago

1.10.1-canary.3

3 years ago

1.10.1-canary.4

3 years ago

1.10.1-canary.2

3 years ago

1.10.1-canary.1

3 years ago

1.10.1-canary.0

3 years ago

1.10.0-canary.8

3 years ago

1.10.0

3 years ago

1.10.0-canary.6

3 years ago

1.10.0-canary.5

3 years ago

1.10.0-canary.4

3 years ago

1.10.0-canary.3

3 years ago

1.10.0-canary.7

3 years ago

1.10.0-canary.2

3 years ago

1.10.0-canary.1

3 years ago

1.10.0-canary.0

3 years ago

1.9.16-canary.0

3 years ago

1.9.15

3 years ago

1.9.14-canary.3

3 years ago

1.9.14-canary.1

4 years ago

1.9.14-canary.2

4 years ago

1.9.14-canary.0

4 years ago

1.9.12

4 years ago

1.9.11

4 years ago

1.9.10

4 years ago

1.9.9

4 years ago

1.9.8

4 years ago

1.9.7

4 years ago

1.9.6

4 years ago

1.9.5

4 years ago

1.9.4

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.9.0-canary.4

4 years ago

1.9.0-canary.1

4 years ago

1.8.0-canary.2

4 years ago

1.8.0

4 years ago

1.8.0-canary.1

4 years ago

1.7.5-canary.1

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.3-canary.4

4 years ago

1.7.3-canary.3

4 years ago

1.7.3-canary.2

4 years ago

1.7.3-canary.1

4 years ago

1.7.2

4 years ago

1.7.2-canary.1

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.7.0-canary.3

4 years ago

1.7.0-canary.2

4 years ago

1.7.0-canary.1

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago