Skip to content

Commit

Permalink
chore: add urql demo & bumps version
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperse-net committed Dec 11, 2023
1 parent cad313e commit c79528b
Show file tree
Hide file tree
Showing 25 changed files with 8,250 additions and 225 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# next-mate

The tRPC framework based on next.js `app router` with `i18n`
The `next.js` based dev toolkits to help you setup fullstack infrastructure quickly

## patch-package

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"lint-staged": "15.2.0",
"npm-run-all": "4.1.5",
"patch-package": "^8.0.0",
"prettier": "3.1.0",
"prettier": "3.1.1",
"rimraf": "5.0.5",
"shell-quote": "1.8.1",
"typescript": "5.3.3"
Expand Down
12 changes: 6 additions & 6 deletions packages/next-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@
"@armit/eslint-config-bases": "^0.1.0",
"@flatjs/forge": "2.0.1",
"@types/node": "20.10.4",
"@vitest/coverage-istanbul": "1.0.2",
"@vitest/ui": "1.0.2",
"@vitest/coverage-istanbul": "1.0.4",
"@vitest/ui": "1.0.4",
"eslint": "8.55.0",
"lucia": "^2.7.4",
"next": "^14.0.4",
"npm-run-all": "4.1.5",
"prettier": "3.1.0",
"prettier": "3.1.1",
"react": "^18.2.0",
"rimraf": "5.0.5",
"rollup-plugin-preserve-directives": "0.2.0",
"ts-node": "10.9.1",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"vite": "5.0.6",
"vite": "5.0.7",
"vite-tsconfig-paths": "4.2.2",
"vitest": "1.0.2"
"vitest": "1.0.4"
},
"peerDependencies": {
"lucia": "^2.7.4",
Expand Down
14 changes: 7 additions & 7 deletions packages/next-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@
"@tanstack/react-query": "^4.x",
"@trpc/server": "^10.44.1",
"@types/node": "20.10.4",
"@vitest/coverage-istanbul": "1.0.2",
"@vitest/ui": "1.0.2",
"@vitest/coverage-istanbul": "1.0.4",
"@vitest/ui": "1.0.4",
"eslint": "8.55.0",
"next": "^14.0.4",
"npm-run-all": "4.1.5",
"prettier": "3.1.0",
"prettier": "3.1.1",
"react": "^18.2.0",
"rimraf": "5.0.5",
"rollup-plugin-preserve-directives": "0.2.0",
"ts-node": "10.9.1",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"vite": "5.0.6",
"vite": "5.0.7",
"vite-tsconfig-paths": "4.2.2",
"vitest": "1.0.2"
"vitest": "1.0.4"
},
"peerDependencies": {
"@tanstack/query-core": "^4.x",
"@tanstack/react-query": "^4.x",
"@trpc/server": "^10.43.3",
"@trpc/server": "^10.44.1",
"next": "^14.0.4",
"react": "^18.2.0"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/next-demo/apollo.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://github.com/apollographql/apollo/blob/main/docs/source/devtools/apollo-config.md
module.exports = {
client: {
service: {
name: 'shop',
// localSchemaFile: './schema-shop.json',
url: 'http://localhost:3001/shop-api',
},
includes: ['./src/data/**/*.ts'],
},
};
41 changes: 41 additions & 0 deletions packages/next-demo/codegen.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* https://the-guild.dev/graphql/codegen/docs/config-reference/config-field
* @type {import('@graphql-codegen/cli').CodegenConfig}
*/
module.exports = {
overwrite: true,
config: {
strict: true,
namingConvention: {
enumValues: 'keep',
},
skipTypeNameForRoot: true,
dedupeFragments: true,
inlineFragmentTypes: 'combine',
scalars: {
ID: 'string | number',
Money: 'number',
},
maybeValue: 'T',
deprecatedFieldsWithReason: true,
inputValueDeprecation: true,
},
generates: {
'src/generated-types.ts': {
schema: 'http://localhost:3001/shop-api',
documents: 'src/data/**/*.{ts,tsx}',
plugins: [
{
add: {
content: '/* eslint-disable */',
},
},
'typescript',
'typescript-operations',
],
},
},
hooks: {
afterAllFileWrite: ['prettier --write'],
},
};
21 changes: 15 additions & 6 deletions packages/next-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"fix-all-files": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --fix",
"next-lint": "next lint",
"codegen": "graphql-codegen --config codegen.cjs",
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --report-unused-disable-directives --report-unused-disable-directives src",
"build:twl": "twl -p \"**/globals.css\""
},
Expand All @@ -52,29 +53,37 @@
"@trpc/next": "^10.44.1",
"@trpc/react-query": "^10.44.1",
"@trpc/server": "^10.44.1",
"@urql/exchange-auth": "^2.1.6",
"@urql/next": "1.1.0",
"class-variance-authority": "0.7.0",
"clsx": "^2.0.0",
"graphql": "16.8.1",
"lucia": "^2.7.4",
"next": "^14.0.4",
"next-intl": "^3.3.1",
"next-runtime-env": "^3.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "7.48.2",
"react-hook-form": "7.49.0",
"server-only": "0.0.1",
"tailwind-merge": "^2.1.0",
"urql": "4.0.6",
"zod": "^3.22.4"
},
"devDependencies": {
"@armit/eslint-config-bases": "0.1.0",
"@changesets/cli": "2.27.1",
"@commitlint/cli": "18.4.3",
"@commitlint/config-conventional": "18.4.3",
"@hyperse-io/tailwind-layer": "^1.0.2",
"@graphql-codegen/add": "5.0.0",
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "4.0.1",
"@hyperse-io/tailwind-layer": "^1.0.3",
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.4",
"@types/prettier": "2.7.3",
"@types/react": "^18.2.42",
"@types/react": "^18.2.43",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"autoprefixer": "^10.4.16",
Expand All @@ -92,16 +101,16 @@
"eslint-plugin-tailwindcss": "3.13.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.32",
"prettier": "^3.1.0",
"prettier": "^3.1.1",
"prisma": "^5.7.0",
"size-limit": "11.0.1",
"start-server-and-test": "^2.0.3",
"tailwindcss": "^3.3.6",
"tsx": "^4.6.2",
"typescript": "^5.3.3",
"vite": "^5.0.6",
"vite": "^5.0.7",
"vite-tsconfig-paths": "4.2.2",
"vitest": "^1.0.2"
"vitest": "^1.0.4"
},
"engines": {
"node": ">=16.8"
Expand Down
20 changes: 12 additions & 8 deletions packages/next-demo/src/app/[locale]/post/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { HydrateClient } from '@hyperse-io/next-core';
import { notFound } from 'next/navigation';
import { rsc } from '@/server/rsc';
import { queryMe } from '@/data/queries/query-me';
import { type NextMeQuery } from '@/generated-types';
import { graphqlRsc, rsc } from '@/server/rsc';

type PageProps = {
params: { id: string };
searchParams: { [key: string]: string | string[] | undefined };
};

export default async function Page(props: PageProps) {
export default async function Page(props: PageProps<{ id: string }>) {
const post = await rsc.post.byId.fetch({ id: props.params.id });

if (!post) {
return notFound();
}

const { data } = await graphqlRsc.query<NextMeQuery>(queryMe, {});

return (
<HydrateClient state={await rsc.dehydrate()}>
<div className="p-4">
<article className="prose overflow-hidden rounded-md bg-white p-4 shadow-md">
<h1>{post.title}</h1>
<h1>
{post.title} : ID:{data?.me?.identifier}: locale:
{props.params.locale}
</h1>

{post.text.split('\n').map((line, i) => (
<p key={i}>{line}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function CreatePostForm() {
utils.post.list.invalidate();
},
});

return (
<form
onSubmit={async (e) => {
Expand Down
25 changes: 25 additions & 0 deletions packages/next-demo/src/data/fragments/fragment-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { gql } from 'urql';

export const FRAGMENT_ADDRESS = gql`
fragment Address on Address {
id
createdAt
updatedAt
fullName
company
streetLine1
streetLine2
province
country {
id
code
name
}
city
phoneNumber
customFields
postalCode
defaultBillingAddress
defaultShippingAddress
}
`;
12 changes: 12 additions & 0 deletions packages/next-demo/src/data/fragments/fragment-asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { gql } from 'urql';

export const FRAGMENT_ASSET = gql`
fragment Asset on Asset {
id
name
source
preview
width
height
}
`;
20 changes: 20 additions & 0 deletions packages/next-demo/src/data/fragments/fragment-customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { gql } from 'urql';
import { FRAGMENT_ADDRESS } from './fragment-address';

export const FRAGMENT_CUSTOMER = gql`
fragment Customer on Customer {
id
title
firstName
lastName
emailAddress
phoneNumber
customFields {
birthday
}
addresses {
...Address
}
}
${FRAGMENT_ADDRESS}
`;
3 changes: 3 additions & 0 deletions packages/next-demo/src/data/fragments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './fragment-address';
export * from './fragment-asset';
export * from './fragment-customer';
2 changes: 2 additions & 0 deletions packages/next-demo/src/data/mutations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './mutation-account';
export * from './mutation-address';
68 changes: 68 additions & 0 deletions packages/next-demo/src/data/mutations/mutation-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { gql } from 'urql';
import { FRAGMENT_CUSTOMER } from '../fragments';
/**
* Verify a Customer email address with the token sent to that address.
* Only applicable if authOptions.requireVerification is set to true.
* If the Customer was not registered with a password in the registerCustomerAccount mutation, the a password must be provided here.
*/
export const mutationVerifyCustomerAccount = gql`
mutation nextVerifyCustomerAccount($token: String!, $password: String) {
verifyCustomerAccount(password: $password, token: $token) {
__typename
... on CurrentUser {
id
}
... on ErrorResult {
errorCode
message
}
}
}
`;

export const mutationUpdateCustomer = gql`
mutation nextUpdateCustomer($input: UpdateCustomerInput!) {
updateCustomer(input: $input) {
...Customer
}
}
${FRAGMENT_CUSTOMER}
`;

export const mutationUpdateCustomerPassword = gql`
mutation nextUpdateCustomerPassword(
$currentPassword: String!
$newPassword: String!
) {
updateCustomerPassword(
currentPassword: $currentPassword
newPassword: $newPassword
) {
__typename
... on Success {
success
}
... on ErrorResult {
errorCode
message
}
}
}
`;

// https://www.vendure.io/docs/graphql-api/shop/object-types/#registercustomeraccountresult
export const mutationRegisterCustomerAccount = gql`
# Register a Customer account with the given credentials. There are three possible registration flows
mutation nextRegisterCustomerAccount($input: RegisterCustomerInput!) {
registerCustomerAccount(input: $input) {
__typename
... on Success {
success
}
... on ErrorResult {
errorCode
message
}
}
}
`;
Loading

0 comments on commit c79528b

Please sign in to comment.