kapix-graphql-prisma-client
Advanced tools
Comparing version 1.0.46 to 1.0.47
@@ -1,2 +0,2 @@ | ||
import { G as i, A as o, B as s, C as t } from "./index-de934a3e.js"; | ||
import { G as i, A as o, B as s, C as t } from "./index-9a89de07.js"; | ||
import "lodash-es"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -7,3 +7,3 @@ { | ||
"type": "module", | ||
"version": "1.0.46", | ||
"version": "1.0.47", | ||
"author": "Sparda", | ||
@@ -10,0 +10,0 @@ "license": "LicenseRef-LICENSE", |
280
README.md
@@ -15,121 +15,229 @@ <p align='center'> | ||
## Checklist | ||
## kapix-graphql-prisma-client | ||
When you use this template, try follow the checklist to update your info properly | ||
This is a client-side library made for interacting with a Graphql/Prisma API backend. | ||
- [ ] Rename `name` field in `package.json` | ||
- [ ] Change the author name in `LICENSE` | ||
- [ ] Change the title, description etc... in `app-info.json` | ||
- [ ] Change the favicon in `public` | ||
This is primarily a [TypeScript](https://www.typescriptlang.org/) library. | ||
And, enjoy :) | ||
## Installation | ||
## Usage | ||
### Comands | ||
```start | ||
pnpm install | ||
npm install kapix-graphql-prisma-client | ||
``` | ||
### Build | ||
## Usage | ||
To Publish | ||
This library exposes TypeScript classes to build queries and mutation based on an `entitiesModels` object you have to describe with a `defineService()` function. | ||
```bash | ||
npm publish ./kapix-graphql-prisma-client | ||
``` | ||
This library is best used inside a downloaded [Kapix](https://www.kapix.fr/) Project where everything surrounding this will generated for you. | ||
And you will see the generated file in `dist` that ready to be served. | ||
### Example entitiesModels | ||
### Deploy on Netlify | ||
The following code describes a simple 2 tables schema where a User has a Post List. | ||
```typescript | ||
import type { NestedCreateInput, NestedListCreateInput, NestedUpdateInput, NestedListUpdateInput, WithOptional } from 'kapix-graphql-prisma-client-type' | ||
import { GraphqlRequestQueryMode, defineModel } from 'kapix-graphql-prisma-client' | ||
import { graphqlRequest } from '~/graphql' | ||
Go to [Netlify](https://app.netlify.com/start) and select your clone, `OK` along the way, and your App will be live in a minute. | ||
## Extension liste | ||
export const entitiesModels = defineModel({ | ||
name: 'YouCanPutANameHere', | ||
requestHandler: graphqlRequest | ||
}, (defineEntityModel, defineEntityName) => ({ | ||
user: defineEntityModel(defineEntityName<Kapix.Entity.IUser, IUser, IUserWhereUniqueInput, IUserCreateInput, IUserUpdateInput>('user'), { | ||
fields: { | ||
id: { | ||
mock: `uuid`, | ||
type: `string`, | ||
required: true, | ||
isPk: true | ||
}, | ||
posts: { | ||
isRelation: true, | ||
isList: true, | ||
mode: `lazy`, | ||
entityName: `post`, | ||
targetProperty: `user` | ||
} | ||
}, | ||
endpoints: { | ||
user: GraphqlRequestQueryMode.Get, | ||
users: GraphqlRequestQueryMode.List, | ||
count: GraphqlRequestQueryMode.Count, | ||
createOneUser: GraphqlRequestQueryMode.CreateOne, | ||
updateOneUser: GraphqlRequestQueryMode.UpdateOne, | ||
deleteOneUser: GraphqlRequestQueryMode.DeleteOne, | ||
createManyUser: GraphqlRequestQueryMode.CreateMany, | ||
updateManyUser: GraphqlRequestQueryMode.UpdateMany, | ||
deleteManyUser: GraphqlRequestQueryMode.DeleteMany | ||
} | ||
}), | ||
post: defineEntityModel(defineEntityName<Kapix.Entity.IPost, IPost, IPostWhereUniqueInput, IPostCreateInput, IPostUpdateInput>('post'), { | ||
fields: { | ||
id: { | ||
mock: `bigNumber`, | ||
type: `number`, | ||
required: true, | ||
isPk: true | ||
}, | ||
title: { | ||
mock: `userName`, | ||
type: `string` | ||
}, | ||
user: { | ||
isRelation: true, | ||
mode: `lazy`, | ||
targetProperty: `posts`, | ||
fks: [`userId`], | ||
required: true | ||
}, | ||
userId: { | ||
fetchByDefault: false, | ||
isFk: true, | ||
type: `string`, | ||
targetProperty: `id` | ||
} | ||
}, | ||
endpoints: { | ||
post: GraphqlRequestQueryMode.Get, | ||
posts: GraphqlRequestQueryMode.List, | ||
count: GraphqlRequestQueryMode.Count, | ||
createOnePost: GraphqlRequestQueryMode.CreateOne, | ||
updateOnePost: GraphqlRequestQueryMode.UpdateOne, | ||
deleteOnePost: GraphqlRequestQueryMode.DeleteOne, | ||
createManyPost: GraphqlRequestQueryMode.CreateMany, | ||
updateManyPost: GraphqlRequestQueryMode.UpdateMany, | ||
deleteManyPost: GraphqlRequestQueryMode.DeleteMany | ||
} | ||
}) | ||
})) | ||
The list of extension is in File .extension | ||
TypeScript Vue Plugin (Volar) | ||
export interface IUser extends Kapix.Entity.IUser {} | ||
export interface IUserWhereUniqueInput { | ||
id?: string | ||
} | ||
export interface IUserCreateInput extends WithOptional<Omit<IUser, 'posts'>, 'id' > { posts?: NestedListCreateInput<Omit<IPostCreateInput, 'user' | 'userId'>, IPostWhereUniqueInput> } | ||
export interface IUserUpdateInput extends Partial<Omit<IUser, 'posts'>> { posts?: NestedListUpdateInput<Omit<IPostUpdateInput, 'user' | 'userId'>, IPostCreateInput, IPostWhereUniqueInput> } | ||
export interface IPost extends Kapix.Entity.IPost {} | ||
export interface IPostWhereUniqueInput { id?: number } | ||
export interface IPostCreateInput extends WithOptional<Omit<IPost, 'user'>, 'title' | 'id' | 'userId'> { user: NestedCreateInput<Omit<IUserCreateInput, 'posts'>, IUserWhereUniqueInput> } | ||
export interface IPostUpdateInput extends Partial<Omit<IPost, 'user'>> { user?: NestedUpdateInput<Omit<IUserUpdateInput, 'posts'>, IUserCreateInput, IUserWhereUniqueInput> } | ||
## Features | ||
``` | ||
- β‘οΈ [Vue 3](https://github.com/vuejs/vue-next), [Vite 2](https://github.com/vitejs/vite), [pnpm](https://pnpm.js.org/), [yarn](https://yarnpkg.com/), [ESBuild](https://github.com/evanw/esbuild) - born with fastness | ||
### Queries | ||
- π [File based routing](./src/pages) | ||
A simple query to get a post: | ||
```typescript | ||
const fetchPost = await entitiesModels.Post.queries.post({ | ||
where: { | ||
id: postId | ||
}, | ||
select: { | ||
...entitiesModels.post.defaultSelect | ||
} | ||
}) | ||
``` | ||
This will return the Post object you wanted, just as if you were writing: | ||
```typescript | ||
` | ||
query { | ||
post( | ||
where: { | ||
id: '${postId}' | ||
} | ||
) { | ||
id | ||
title | ||
} | ||
} | ||
` | ||
``` | ||
- π¦ [Components auto importing](./src/components) | ||
But now you have typescript to guide you. | ||
- π [State Management via Pinia](https://pinia.esm.dev/) | ||
### Mutations | ||
- π [Layout system](./src/layouts) | ||
You can build a create input: | ||
- π² [PWA](https://github.com/antfu/vite-plugin-pwa) | ||
```typescript | ||
const postCreateInput = entitiesModels.post.factory.buildCreateInput({ | ||
title: 'firstPost' | ||
}) | ||
``` | ||
- π [Use icons from any icon sets, with no compromise](https://github.com/antfu/unplugin-icons) | ||
And then use it for your mutation: | ||
```typescript | ||
const createdPost = await entitiesModels.post.mutations.createOnePost({ | ||
data: postCreateInput, | ||
select: { | ||
...entitiesModels.post.defaultSelect, | ||
userId: true, | ||
user: true | ||
} | ||
}) | ||
- π [I18n ready](./locales) | ||
``` | ||
This is the equivalent of: | ||
```typescript | ||
` | ||
mutation { | ||
createOnePost( | ||
data: { | ||
title: '${title}' | ||
} | ||
) { | ||
id | ||
title | ||
userId | ||
user { | ||
id | ||
} | ||
} | ||
} | ||
` | ||
``` | ||
- π₯ Use the [new `<script setup>` syntax](https://github.com/vuejs/rfcs/pull/227) | ||
And the same for every endpoint and entity you have described in your `entitiesModel`. | ||
- π₯ [APIs auto importing](https://github.com/antfu/unplugin-auto-import) - use Composition API and others directly | ||
## Mocking | ||
- π¨ Server-side generation (SSG) via [vite-ssg](https://github.com/antfu/vite-ssg) | ||
There is also a built-in data mocking service with a pseudo local storage, that you can use to emulate a real server. | ||
- π¦Ύ TypeScript, of course | ||
To activate the mocking service, simply put `mockData: true` in the `defineService()` function args. | ||
- βοΈ E2E Testing with [Cypress](https://cypress.io/) on [GitHub Actions](https://github.com/features/actions) | ||
There are multiple other options you can give to customize the mocking, that you can pass like so: | ||
```typescript | ||
mockData: true, | ||
config: { | ||
mock: { | ||
maxItems | ||
percentageOfNullWhenFieldNotRequired | ||
randNumberOfItemsOptions | ||
values | ||
} | ||
} | ||
``` | ||
- βοΈ Deploy on Netlify, zero-config | ||
An example that will create 10 Post objects that will exist in the pseudo local storage: | ||
<br> | ||
```typescript | ||
const rideOffers = await entitiesModels.post.factory.mockItems({ | ||
id: true, | ||
title: true, | ||
user: { | ||
id: true | ||
} | ||
}, { | ||
min: 10, | ||
max: 10 | ||
}) | ||
``` | ||
## Pre-packed | ||
You can perform every action you want on these objects, as if it were a real server, so you can query and mutate on these created objects. | ||
### Icons | ||
## License | ||
- [Iconify](https://iconify.design) - use icons from any icon sets [πIcΓ΄nes](https://icones.netlify.app/) | ||
- [`unplugin-icons`](https://github.com/antfu/unplugin-icons) - icons as Vue components | ||
[MIT License](https://opensource.org/license/mit/) | ||
### Plugins | ||
- [Vue Router](https://github.com/vuejs/vue-router) | ||
- [`vite-plugin-pages`](https://github.com/hannoeru/vite-plugin-pages) - file system based routing | ||
- [`vite-plugin-vue-layouts`](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) - layouts for pages | ||
- [Pinia](https://pinia.esm.dev) - Intuitive, type safe, light and flexible Store for Vue using the composition api | ||
- [`unplugin-vue-components`](https://github.com/antfu/unplugin-vue-components) - components auto import | ||
- [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - Directly use Vue Composition API and others without importing | ||
- [`vite-plugin-pwa`](https://github.com/antfu/vite-plugin-pwa) - PWA | ||
- [Vue I18n](https://github.com/intlify/vue-i18n-next) - Internationalization | ||
- [`vite-plugin-vue-i18n`](https://github.com/intlify/vite-plugin-vue-i18n) - Vite plugin for Vue I18n | ||
- [VueUse](https://github.com/antfu/vueuse) - collection of useful composition APIs | ||
- [`@vueuse/head`](https://github.com/vueuse/head) - manipulate document head reactively | ||
### Coding Style | ||
- Use Composition API with [`<script setup>` SFC syntax](https://github.com/vuejs/rfcs/pull/227) | ||
- [ESLint](https://eslint.org/) with [@antfu/eslint-config](https://github.com/antfu/eslint-config), single quotes, no semi. | ||
### Dev tools | ||
- [TypeScript](https://www.typescriptlang.org/) | ||
- [Cypress](https://cypress.io/) - E2E Testing | ||
- [yarn](https://yarnpkg.com/) - fast, disk space efficient package manager | ||
- [pnpm](https://pnpm.js.org/) - fast, disk space efficient package manager | ||
- [`vite-ssg`](https://github.com/antfu/vite-ssg) - Server-side generation | ||
- [critters](https://github.com/GoogleChromeLabs/critters) - Critical CSS | ||
- [Netlify](https://www.netlify.com/) - zero-config deployment | ||
- [VS Code Extensions](./.vscode/extensions.json) | ||
- [Vite](https://marketplace.visualstudio.com/items?itemName=antfu.vite) - Fire up Vite server automatically | ||
- [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) - Vue 3 `<script setup>` IDE support | ||
- [Iconify IntelliSense](https://marketplace.visualstudio.com/items?itemName=antfu.iconify) - Icon inline display and autocomplete | ||
- [i18n Ally](https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally) - All in one i18n support | ||
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) | ||
###### Community | ||
- [vitesse-addons](https://github.com/JohnCampionJr/vitesse-addons) by [@johncampionjr](https://github.com/johncampionjr) - additional options for integrations, including [Prettier](https://prettier.io) and [Storybook](https://storybook.js.org) | ||
- [vitesse-ssr-template](https://github.com/frandiox/vitesse-ssr-template) by [@frandiox](https://github.com/frandiox) - Vitesse with SSR | ||
- [vitespa](https://github.com/ctholho/vitespa) by [@ctholho](https://github.com/ctholho) - Like Vitesse but without SSG/SSR | ||
- [vitailse](https://github.com/zynth17/vitailse) by [@zynth17](https://github.com/zynth17) - Like Vitesse but with TailwindCSS | ||
- [vitesse-modernized-chrome-ext](https://github.com/xiaoluoboding/vitesse-modernized-chrome-ext) by [@xiaoluoboding](https://github.com/xiaoluoboding) - β‘οΈ Modernized Chrome Extension Manifest V3 Vite Starter Template | ||
- [vitesse-stackter-clean-architect](https://github.com/shamscorner/vitesse-stackter-clean-architect) by [@shamscorner](https://github.com/shamscorner) - A modular clean architecture pattern in vitesse template | ||
Copyright (c) 2020-2022 Stephane LASOUR |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3332392
242