-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: backport stuff from real-world projects
- Loading branch information
1 parent
8f007c4
commit f085f04
Showing
25 changed files
with
736 additions
and
1,097 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { logger } from "@nuxt/kit"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare global { | ||
type PartialBy<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
type SinglePropertyType<T> = { [K in keyof T]: { [P in K]: T[K] } }[keyof T]; | ||
} | ||
|
||
export { type PartialBy, type SinglePropertyType }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const pageInfoFragment = graphql(` | ||
fragment PageInfo on PageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
endCursor | ||
} | ||
`); | ||
|
||
export type CursorPagination = { | ||
after: string | null; | ||
before: string | null; | ||
first: number | null; | ||
last: number | null; | ||
}; | ||
|
||
export function useCursorPagination(stateName: string, pageInfo: Ref<PageInfoFragment | null | undefined>, perPage = 10) { | ||
const cursorPagination = useState<CursorPagination>(stateName, () => ({ after: null, before: null, first: perPage, last: null })); | ||
|
||
function firstPage() { | ||
Object.assign(cursorPagination.value, { after: null, before: null, first: perPage, last: null }); | ||
} | ||
|
||
function previousPage() { | ||
if (!pageInfo.value?.hasPreviousPage) return; | ||
Object.assign(cursorPagination.value, { after: null, before: pageInfo.value.startCursor, first: null, last: perPage }); | ||
} | ||
|
||
function nextPage() { | ||
if (!pageInfo.value?.hasNextPage) return; | ||
Object.assign(cursorPagination.value, { after: pageInfo.value.endCursor, before: null, first: perPage, last: null }); | ||
} | ||
|
||
return { cursorPagination, firstPage, previousPage, nextPage }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./types/app-info"; | ||
export * from "./types/auth-user"; | ||
export * from "./types/scalars"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { AuthRole } from "@prisma/client"; | ||
|
||
// AuthRole type and filter | ||
export const AuthRoleEnumType = builder.enumType(AuthRole, { name: "AuthRole" }); | ||
|
||
export const AuthRoleFilter = builder.prismaFilter(AuthRole, { | ||
ops: ["equals", "in", "notIn"], | ||
}); | ||
|
||
// AuthUser Prisma node, Where and OrderBy inputs | ||
export const AuthUserPrismaNode = builder.prismaNode("AuthUser", { | ||
id: { field: "id" }, | ||
fields: (t) => ({ | ||
id: t.exposeID("id"), | ||
email: t.exposeString("email"), | ||
role: t.expose("role", { type: AuthRoleEnumType }), | ||
}), | ||
authScopes: { hasAuthRole: "ADMINISTRATOR" }, | ||
}); | ||
|
||
export const AuthUserUniqueFilter = builder.prismaWhereUnique("AuthUser", { | ||
fields: (t) => ({ | ||
email: t.field({ type: "String", required: true }), | ||
}), | ||
}); | ||
|
||
export const AuthUserFilter = builder.prismaWhere("AuthUser", { | ||
fields: (t) => ({ | ||
role: AuthRoleFilter, | ||
}), | ||
}); | ||
|
||
export const AuthUserOrderByInput = builder.prismaOrderBy("AuthUser", { | ||
fields: { | ||
email: true, | ||
role: true, | ||
}, | ||
}); | ||
|
||
export const AuthUserQueries = builder.queryFields((t) => ({ | ||
authUsers: t.prismaConnection({ | ||
type: "AuthUser", | ||
cursor: "id", | ||
args: { | ||
where: t.arg({ type: AuthUserFilter, required: true }), | ||
orderBy: t.arg({ type: AuthUserOrderByInput, required: true }), | ||
}, | ||
totalCount: async (_root, { where }, { prisma }) => await prisma.authUser.count({ where }), | ||
resolve: async (query, _root, { where, orderBy }, { prisma }) => await prisma.authUser.findMany({ ...query, where, orderBy }), | ||
authScopes: { hasAuthRole: "ADMINISTRATOR" }, | ||
}), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.