taneba / fullstack-graphql-app Goto Github PK
View Code? Open in Web Editor NEWAn opinionated fullstack GraphQL monorepo boilerplate using pnpm, Turborepo, Prisma, GraphQL Yoga 2, Fastify, Nextjs, urql, and React
An opinionated fullstack GraphQL monorepo boilerplate using pnpm, Turborepo, Prisma, GraphQL Yoga 2, Fastify, Nextjs, urql, and React
This should be easier, but there's 2 options:
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):
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"
}
}
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!
}
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
}
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.
As @kettanaito commented on my article about msw, @msw/data seems pretty nice in terms of reducing boilerplates.
I'm considering better error handling in the backend. What I mean by "better" is type safety and exhaustiveness.
Core error would be:
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
moved to separate issue: #91
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 |
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@graphql-tools/schema
, @graphql-tools/utils
)@next/font
, next
)@prisma/client
, prisma
)@types/react
, @types/react-dom
, eslint-plugin-react-hooks
, react
, react-dom
, react-is
, react-test-renderer
)@testing-library/jest-dom
, @testing-library/user-event
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)jsonwebtoken
, @types/jsonwebtoken
)@graphql-tools/schema
, @graphql-tools/utils
, graphql-tools
)@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
)@next/bundle-analyzer
, @next/font
, eslint-config-next
, next
)@prisma/client
, prisma
)@testing-library/jest-dom
, @testing-library/react
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@types/jest
, babel-jest
, jest
, ts-jest
)docker-compose.yml
Dockerfile.backend
.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
.node-version
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
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:
I don't know for sure how those 2 plugins are able to work together well but I'm trying.
as The Guild recommends graphql-yoga over graphql-helix
I'm thinking about using spinners-react
https://github.com/adexin/spinners-react
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.