GithubHelp home page GithubHelp logo

taneba / fullstack-graphql-app Goto Github PK

View Code? Open in Web Editor NEW
156.0 2.0 15.0 3.92 MB

An opinionated fullstack GraphQL monorepo boilerplate using pnpm, Turborepo, Prisma, GraphQL Yoga 2, Fastify, Nextjs, urql, and React

TypeScript 92.49% JavaScript 7.40% CSS 0.11%
graphql nextjs urql envelop react turborepo docker fastify prisma typescript

fullstack-graphql-app's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fullstack-graphql-app's Issues

better graphql error handling

graphql error handling

This should be easier, but there's 2 options:

1. Just throw error

like Apollo instracts:
https://www.apollographql.com/blog/graphql/error-handling/full-stack-error-handling-with-graphql-apollo/

apollo exposes 3 basic errors(just wrappers around ApolloError):

  • AuthenticationError — for authentication failures
  • ForbiddenError — for authorization failures
  • UserInputError — for validation errors on user input

Regardless of not using apollo, I would follow those patterns.

import { AuthenticationError } from 'apollo-server'
const resolvers = {
  Mutation: {
    protectedAction(root, args , { user }) { 
      if (!user) { 
        throw new AuthenticationError('You must be logged in');
      }
    }
  }
};

throws it, and the response will look like:

{
  "error": {
    "graphQLErrors": [
      {
        "message": "forbidden",
        "locations": [],
        "path": [
          "protectedAction"
        ],
        "extensions": {
          "code": "UNAUTHENTICATED",
        }
      }
    ],
    "networkError": null,
    "message": "GraphQL error: You must be logged in"
  }
}
  1. Return union type response instead

Another option is to use union type for error handling.
https://blog.logrocket.com/handling-graphql-errors-like-a-champ-with-unions-and-interfaces/

Just see the schema below and you'll get it all.

type User {
  id: ID!
  login: String!
}

type UserRegisterResultSuccess {
  user: User!
}

type UserRegisterInvalidInputError {
  message: String!
  loginErrorMessage: String
  emailErrorMessage: String
  passwordErrorMessage: String
}

type CountryBlockedError {
  message: String!
}

type UserRegisterInput {
  login: String!
  email: String!
  password: String!
}

union UserRegisterResult =
  UserRegisterResultSuccess
  | UserRegisterInvalidInputError
  | CountryBlockedError

type Mutation {
  userRegister(input: UserRegisterInput!): UserRegisterResult!
}

add example for owner check

Even though authentication/authorization is implemented well, it can be more secure.

I'd like to add a mechanism for checking ownership in the private field.

Let's say we have User type that contains public field and private field.

type User {
  name: string // public
  privateInfo: string // private. this should be restricted to user of admin role or owner
}

When we have a query that can get other users, a security concern comes in.

  type Query {
     allUsers: [User!]! @auth(role: ADMIN) // this should be ok
     friends: [User!]! @auth // this shouldn't be ok
  }

Errorboundary?

Now our code is using React.Suspense throughout our code base. With Suspense, loading ui is Suspense's work. But how about error ui? I used to see some code examples that uses Errorboundary component with suspense before. But as seeing the
React documentation, there aren't any official recommendation or code example that put Suspense and Errorboundary together.
We should investigate more on this but there's one error-boundary library by bvaughn, who is in the core React team.

https://github.com/bvaughn/react-error-boundary

investigate better error handling

I'm considering better error handling in the backend. What I mean by "better" is type safety and exhaustiveness.

core error handling

Core error would be:

  • validation
  • errors by prisma
  • errors by third party library
  • side effects

My biggest concern is type safety here so that resolvers can handle error accurately. And there seems 2 possible approach for it.

First option: neverthrow

articles:

https://pianomanfrazier.com/post/what-is-functional-programming/

https://pianomanfrazier.com/post/exceptions-considered-harmful/

Second option: ts-pattern

articles:

https://dev.to/gvergnaud/bringing-pattern-matching-to-typescript-introducing-ts-pattern-v3-0-o1k

graphql error handling

moved to separate issue: #91

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/testing-library__jest-dom Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @hookform/resolvers to v2.9.11
  • Update dependency @radix-ui/colors to v0.1.9
  • Update dependency @radix-ui/react-avatar to v1.0.4
  • Update dependency @radix-ui/react-dialog to v1.0.5
  • Update dependency @radix-ui/react-portal to v1.0.4
  • Update dependency @types/node to v16.18.98
  • Update dependency @types/styled-components to v5.1.34
  • Update dependency @types/testing-library__jest-dom to v5.14.9
  • Update dependency autoprefixer to v10.4.19
  • Update dependency postcss to v8.4.38
  • Update dependency prettier to v2.8.8
  • Update dependency tailwindcss-animate to v1.0.7
  • Update dependency tsc-alias to v1.8.10
  • Update graphql-tools monorepo (@graphql-tools/schema, @graphql-tools/utils)
  • Update dependency @fastify/compress to v6.5.0
  • Update dependency @fastify/cors to v8.5.0
  • Update dependency eslint to v8.57.0
  • Update dependency eslint-config-prettier to v8.10.0
  • Update dependency eslint-import-resolver-typescript to v3.6.1
  • Update dependency eslint-plugin-react to v7.34.2
  • Update dependency graphql to v16.8.2
  • Update dependency prettier-plugin-tailwindcss to ^0.6.0
  • Update dependency react-hook-form to v7.52.0
  • Update dependency tailwind-merge to v1.14.0
  • Update dependency ts-pattern to v4.3.0
  • Update dependency tsconfig-paths to v4.2.0
  • Update dependency tsup to v6.7.0
  • Update dependency tsx to v3.14.0
  • Update dependency turbo to v1.13.4
  • Update dependency zod to v3.23.8
  • Update nextjs monorepo to v13.5.6 (@next/font, next)
  • Update pnpm to v7.33.7
  • Update prisma monorepo to v4.16.2 (@prisma/client, prisma)
  • Update react monorepo (@types/react, @types/react-dom, eslint-plugin-react-hooks, react, react-dom, react-is, react-test-renderer)
  • Update testing-library monorepo (@testing-library/jest-dom, @testing-library/user-event)
  • Update typescript-eslint monorepo to v5.62.0 (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • Update actions/cache action to v4
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update dependency @auth0/auth0-react to v2
  • Update dependency @envelop/auth0 to v6
  • Update dependency @envelop/core to v5
  • Update dependency @envelop/depth-limit to v4
  • Update dependency @envelop/generic-auth to v7
  • Update dependency @envelop/rate-limiter to v6
  • Update dependency @fastify/compress to v7
  • Update dependency @fastify/cors to v9
  • Update dependency @fastify/helmet to v11
  • Update dependency @graphql-yoga/render-graphiql to v5
  • Update dependency @heroicons/react to v2
  • Update dependency @hookform/resolvers to v3
  • Update dependency @radix-ui/colors to v3
  • Update dependency @types/node to v20
  • Update dependency @types/testing-library__jest-dom to v6
  • Update dependency chalk to v5
  • Update dependency clsx to v2
  • Update dependency dotenv-cli to v7
  • Update dependency eslint to v9
  • Update dependency eslint-config-prettier to v9
  • Update dependency eslint-plugin-simple-import-sort to v12
  • Update dependency got to v14
  • Update dependency graphql-yoga to v5
  • Update dependency isomorphic-unfetch to v4
  • Update dependency jsonwebtoken to v9 (jsonwebtoken, @types/jsonwebtoken)
  • Update dependency jwks-rsa to v3
  • Update dependency msw to v2
  • Update dependency nodemon to v3
  • Update dependency prettier to v3
  • Update dependency tailwind-merge to v2
  • Update dependency ts-pattern to v5
  • Update dependency tsup to v8
  • Update dependency tsx to v4
  • Update dependency turbo to v2
  • Update dependency typescript to v5
  • Update dependency urql to v4
  • Update graphql-tools monorepo (major) (@graphql-tools/schema, @graphql-tools/utils, graphql-tools)
  • Update graphqlcodegenerator monorepo (major) (@graphql-codegen/cli, @graphql-codegen/gql-tag-operations-preset, @graphql-codegen/schema-ast, @graphql-codegen/typed-document-node, @graphql-codegen/typescript, @graphql-codegen/typescript-operations, @graphql-codegen/typescript-resolvers, @graphql-codegen/typescript-urql, @graphql-codegen/visitor-plugin-common)
  • Update nextjs monorepo to v14 (major) (@next/bundle-analyzer, @next/font, eslint-config-next, next)
  • Update pnpm to v9
  • Update prisma monorepo to v5 (major) (@prisma/client, prisma)
  • Update testing-library monorepo (major) (@testing-library/jest-dom, @testing-library/react)
  • Update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile.backend
github-actions
.github/workflows/ci_backend.yml
  • actions/checkout v3
  • actions/setup-node v3
  • pnpm/action-setup v2
  • actions/cache v3
  • actions/cache v3
.github/workflows/ci_frontend.yml
  • actions/checkout v3
  • actions/setup-node v3
  • pnpm/action-setup v2
  • actions/cache v3
  • actions/cache v3
nodenv
.node-version
npm
apps/backend/package.json
  • @envelop/auth0 4.0.6
  • @envelop/core 3.0.6
  • @envelop/depth-limit 2.0.6
  • @envelop/generic-auth 5.0.6
  • @envelop/rate-limiter 4.0.6
  • @fastify/compress 6.2.1
  • @fastify/cors 8.2.1
  • @fastify/helmet ^9.1.0
  • @graphql-tools/schema 9.0.18
  • @graphql-tools/utils ^9.1.4
  • @prisma/client 4.8.1
  • @types/got 9.6.12
  • @types/jsonwebtoken 8.5.9
  • @types/node 16.18.24
  • fastify 4.13.0
  • got 11.8.6
  • graphql 16.6.0
  • graphql-tools 8.3.20
  • graphql-yoga 3.9.1
  • jsonwebtoken 8.5.1
  • jwks-rsa 2.1.5
  • prisma 4.8.1
  • ts-pattern ^4.0.5
  • typescript 4.9.5
  • zod 3.20.6
  • @graphql-codegen/cli 2.16.5
  • @graphql-codegen/typescript-resolvers 2.7.13
  • @graphql-codegen/visitor-plugin-common 2.13.8
  • @graphql-yoga/render-graphiql 3.6.1
  • chalk 4.1.2
  • dotenv-cli 6.0.0
  • nodemon 2.0.22
  • tsc-alias 1.8.5
  • tsconfig-paths 4.1.2
  • tsx 3.12.6
apps/frontend/package.json
  • @auth0/auth0-react 1.12.1
  • @heroicons/react 1.0.6
  • @hookform/resolvers ^2.9.10
  • @next/font ^13.1.6
  • @radix-ui/colors 0.1.8
  • @radix-ui/react-avatar 1.0.2
  • @radix-ui/react-dialog 1.0.3
  • @radix-ui/react-icons 1.3.0
  • @radix-ui/react-portal 1.0.2
  • autoprefixer ^10.4.13
  • graphql 16.6.0
  • graphql-anywhere 4.2.8
  • next 13.3.1
  • postcss ^8.4.21
  • react 18.2.0
  • react-dom 18.2.0
  • react-hook-form 7.43.9
  • spinners-react 1.0.7
  • tailwindcss 3.2.7
  • ts-pattern 3.3.5
  • typescript 4.9.5
  • urql 2.2.3
  • wonka 4.0.15
  • zod 3.20.6
  • @graphql-codegen/cli 2.16.5
  • @graphql-codegen/gql-tag-operations-preset 1.7.4
  • @graphql-codegen/schema-ast 2.6.1
  • @graphql-codegen/typed-document-node 2.3.13
  • @graphql-codegen/typescript 2.8.8
  • @graphql-codegen/typescript-operations 2.5.13
  • @graphql-codegen/typescript-urql 3.7.3
  • @graphql-typed-document-node/core 3.1.2
  • @next/bundle-analyzer 12.3.4
  • @testing-library/jest-dom 5.16.5
  • @testing-library/react 13.4.0
  • @testing-library/user-event 14.4.3
  • @types/jest 27.5.2
  • @types/node 16.18.24
  • @types/react 18.0.38
  • @types/react-dom 18.0.11
  • @types/styled-components 5.1.26
  • @types/testing-library__jest-dom ^5.14.5
  • babel-jest 27.5.1
  • graphql-playground-html 1.6.30
  • graphql-typescript-integration 1.2.1
  • isomorphic-unfetch 3.1.0
  • jest 27.5.1
  • msw 0.44.2
  • prettier-plugin-tailwindcss ^0.2.2
  • react-is 18.2.0
  • react-test-renderer 18.2.0
  • ts-jest 27.1.5
package.json
  • autoprefixer ^10.4.13
  • postcss ^8.4.21
  • tailwindcss 3.2.7
  • eslint ^8.33.0
  • prettier 2.8.7
  • prettier-plugin-tailwindcss ^0.2.2
  • turbo 1.9.3
  • npm >=7.0.0
  • pnpm 7.26.3
packages/config/package.json
  • @typescript-eslint/eslint-plugin ^5.12.1
  • @typescript-eslint/parser ^5.12.1
  • eslint ^8.9.0
  • eslint-config-next ^12.0.8
  • eslint-config-prettier ^8.4.0
  • eslint-import-resolver-typescript ^3.0.0
  • eslint-plugin-react ^7.28.0
  • eslint-plugin-react-hooks ^4.3.0
  • eslint-plugin-simple-import-sort ^7.0.0
packages/tailwind-config/package.json
  • tailwindcss 3.2.7
  • tailwindcss-animate ^1.0.5
packages/tsconfig/package.json
packages/ui/package.json
  • @radix-ui/react-avatar 1.0.2
  • @radix-ui/react-dialog 1.0.3
  • @radix-ui/react-portal 1.0.2
  • @types/node 16.18.24
  • @types/react 18.0.38
  • @types/react-dom 18.0.11
  • autoprefixer ^10.4.13
  • class-variance-authority ^0.4.0
  • clsx ^1.2.1
  • lucide-react ^0.161.0
  • postcss ^8.4.21
  • spinners-react 1.0.7
  • tailwind-merge ^1.9.0
  • tailwindcss 3.2.7
  • tailwindcss-animate ^1.0.5
  • tsup ^6.6.0
  • typescript 4.9.5
packages/validation-schema/package.json
  • @graphql-codegen/cli 3.3.1
  • @graphql-codegen/typescript 3.0.4
  • @types/node 16.18.24
  • graphql 16.6.0
  • graphql-codegen-typescript-validation-schema ^0.7.1
  • tsup ^6.6.0
  • typescript 4.9.5
  • zod 3.20.6

  • Check this box to trigger a request for Renovate to run again on this repository

Authentication

Add auth0 based authentication. We're going to have 2 types of users. 1. normal user 2. admin user. Admin user should access all users information.

I'm planning to use envelop plugins:

  • @envelop/auth0 for authentication, general api protection
  • @envelop/generic-auth for authorization

I don't know for sure how those 2 plugins are able to work together well but I'm trying.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.