8000 Merge pull request #5 from wheatjs/feat/query-generation · wheatjs/vite-plugin-vue-gql@aedf19e · GitHub
[go: up one dir, main page]

Skip to content

Commit aedf19e

Browse files
authored
Merge pull request #5 from wheatjs/feat/query-generation
feat: Rewrite & clientHandleSupport
2 parents 75fbfab + ebb5edd commit aedf19e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7471
-1286
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import { ref } from 'vue'
104104
import { useQuery } from 'vql'
105105
106106
const name = ref('Evan')
107-
const { data } = useQuery({ name })
107+
const { data } = useQuery({ variables: { name } })
108108
</script>
109109

110110
<template>...</template>
@@ -125,7 +125,7 @@ import { ref } from 'vue'
125125
import { useQuery } from 'vql'
126126
127127
const name = ref('Evan')
128-
const { data } = useQuery('users', { name })
128+
const { data } = useQuery('users', { variables: { name } })
129129
</script>
130130

131131
<template>...</template>
@@ -224,7 +224,7 @@ import { ref } from 'vue'
224224
import { useQuery } from 'vql'
225225
226226
const name = ref('RADWIMPS')
227-
const { data } = useQuery({ name })
227+
const { data } = useQuery({ variables: { name } })
228228
</script>
229229

230230
<template>...</template>

client.d.ts

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,51 @@
1+
import type { Ref } from 'vue'
2+
import type {
3+
UseQueryArgs,
4+
UseQueryResponse,
5+
UseMutationResponse,
6+
UseSubscriptionResponse,
7+
UseSubscriptionArgs,
8+
ClientHandle,
9+
} from '@urql/vue'
10+
11+
declare type MaybeRef<T> = T | Ref<T>
12+
13+
declare module 'virtual:gql-generation' {
14+
export const generated: string[]
15+
}
16+
17+
interface VqlClientHandle {
18+
useQuery<T = any, V = object>(_args: Omit<UseQueryArgs<T, V>, 'query'>): UseQueryResponse<T, V>
19+
useQuery<T = any, V = object>(name: string, _args: Omit<UseQueryArgs<T, V>, 'query'>): UseQueryResponse<T, V>
20+
useMutation<T = any, V = any>(): UseMutationResponse<T, V>
21+
useMutation<T = any, V = any>(name: string): UseMutationResponse<T, V>
22+
useSubscription<T = any, R = T, V = object>(_args: Omit<UseSubscriptionArgs<T, V>, 'query'>, handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
23+
useSubscription<T = any, R = T, V = object>(name: string, _args: Omit<UseSubscriptionArgs<T, V>, 'query'>, handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
24+
}
25+
126
declare module 'vql' {
2-
import type {
3-
UseQueryArgs,
4-
UseQueryResponse,
5-
UseMutationResponse,
6-
UseSubscriptionResponse,
7-
UseSubscriptionArgs,
8-
} from '@urql/vue'
9-
10-
declare type UseQueryOptions = Omit<UseQueryArgs, 'variables'>
11-
12-
// Query
13-
export function useQuery<T = any, V = any>(
14-
variables?: UseQueryArgs.variables<T, V> | null,
15-
options?: Partial<UseQueryOptions<T, V>>): UseQueryResponse<T, V>
16-
17-
export function useQuery<T = any, V = any>(
18-
queryName?: string,
19-
variables: UseQueryArgs.variables<T, V>,
20-
options?: Partial<UseQueryOptions<T, V>>): UseQueryResponse<T, V>
21-
22-
// Mutation
23-
export function useMutation<T = any, V = any>(query?: string): UseMutationResponse<T, V>
24-
25-
// Subscriptions
26-
export function useSubscription<T = any, R = T, V = object>(
27-
variables: UseSubscriptionArgs.variables<T, V>,
28-
_args?: Partial<UseSubscriptionArgs<T, V>>,
29-
handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
30-
31-
export function useSubscription<T = any, R = T, V = object>(
32-
queryName: string,
33-
variables: UseSubscriptionArgs.variables<T, V>,
34-
_args?: Partial<UseSubscriptionArgs<T, V>>,
35-
handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
27+
export declare function useClientHandle(): VqlClientHandle
28+
29+
export declare function useQuery<T = any, V = object>(_args: Omit<UseQueryArgs<T, V>, 'query'>): UseQueryResponse<T, V>
30+
export declare function useQuery<T = any, V = object>(name: string, _args: Omit<UseQueryArgs<T, V>, 'query'>): UseQueryResponse<T, V>
31+
32+
export declare function useMutation<T = any, V = any>(): UseMutationResponse<T, V>
33+
export declare function useMutation<T = any, V = any>(name: string): UseMutationResponse<T, V>
34+
35+
export declare function useSubscription<T = any, R = T, V = object>(_args: Omit<UseSubscriptionArgs<T, V>, 'query'>, handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
36+
export declare function useSubscription<T = any, R = T, V = object>(name: string, _args: Omit<UseSubscriptionArgs<T, V>, 'query'>, handler?: MaybeRef<SubscriptionHandler<T, R>>): UseSubscriptionResponse<T, R, V>
3637
}
38+
39+
// declare module 'vql-gen' {
40+
41+
// export interface UseQueryDynamicVariable {
42+
// for: string
43+
// variables: MaybeRef<V>
44+
// }
45+
46+
// export interface UseDyanmicQueryArgs<T, V> extends Omit<UseQueryArgs<T, V>, ['query', 'variables']> {
47+
// variables: UseQueryDynamicVariable<V>
48+
// }
49+
50+
// export declare function useQuery<T = any, V = object>(_args: UseDyanmicQueryArgs<T, V>): UseQueryResponse<T, V>
51+
// }

docs/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
public

docs/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@antfu"
3+
}

docs/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.vite-ssg-dist
3+
.vite-ssg-temp
4+
*.local
5+
dist
6+
dist-ssr
7+
node_modules
8+
# intellij stuff
9+
.idea/

docs/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

docs/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
7+
<link rel="apple-touch-icon" href="/pwa-192x192.png">
8+
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9">
9+
<meta name="msapplication-TileColor" content="#00aba9">
10+
<meta name="theme-color" content="#ffffff">
11+
</head>
12+
<body>
13+
<div id="app"></div>
14+
<script>
15+
(function() {
16+
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
17+
const setting = localStorage.getItem('color-schema') || 'auto'
18+
if (setting === 'dark' || (prefersDark && setting !== 'light'))
19+
document.documentElement.classList.toggle('dark', true)
20+
})()
21+
</script>
22+
<script type="module" src="/src/main.ts"></script>
23+
</body>
24+
</html>

docs/netlify.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[build.environment]
2+
NPM_FLAGS = "--prefix=/dev/null"
3+
NODE_VERSION = "14"
4+
5+
[build]
6+
publish = "dist"
7+
command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"
8+
9+
[[redirects]]
10+
from = "/*"
11+
to = "/index.html"
12+
status = 200
13+
14+
[[headers]]
15+
for = "/manifest.webmanifest"
16+
[headers.values]
17+
Content-Type = "application/manifest+json"

docs/package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "vite --port 3333 --open",
5+
"build": "cross-env NODE_ENV=production vite-ssg build",
6+
"preview": "vite preview",
7+
"preview-https": "serve dist"
8+
},
9+
"dependencies": {
10+
"@urql/vue": "0.4.0",
11+
"@vueuse/core": "^4.8.1",
12+
"@vueuse/head": "^0.5.1",
13+
"markdown-it": "^12.0.6",
14+
"nprogress": "^0.2.0",
15+
"prism-theme-vars": "^0.2.2",
16+
"vue": "^3.0.11",
17+
"vue-i18n": "^9.1.3",
18+
"vue-router": "^4.0.6"
19+
},
20+
"devDependencies": {
21+
"@antfu/eslint-config": "^0.6.2",
22+
"@iconify/json": "^1.1.328",
23+
"@intlify/vite-plugin-vue-i18n": "^2.1.2",
24+
"@types/markdown-it": "^12.0.1",
25+
"@types/nprogress": "^0.2.0",
26+
"@typescript-eslint/eslint-plugin": "^4.21.0",
27+
"@vitejs/plugin-vue": "^1.2.1",
28+
"@vue/compiler-sfc": "^3.0.11",
29+
"@vue/server-renderer": "^3.0.11",
30+
"cross-env": "^7.0.3",
31+
"eslint": "^7.24.0",
32+
"https-localhost": "^4.6.4",
33+
"markdown-it-prism": "^2.1.6",
34+
"pnpm": "^6.0.1",
35+
"typescript": "^4.2.4",
36+
"vite": "^2.1.5",
37+
"vite-plugin-components": "^0.8.3",
38+
"vite-plugin-icons": "^0.5.0",
39+
"vite-plugin-md": "^0.6.3",
40+
"vite-plugin-pages": "^0.9.3",
41+
"vite-plugin-pwa": "^0.7.0",
42+
"vite-plugin-vue-gql": "workspace:*",
43+
"vite-plugin-vue-layouts": "^0.2.2",
44+
"vite-plugin-windicss": "^0.14.0",
45+
"vite-ssg": "^0.9.2"
46+
}
47+
}

docs/public/_headers

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/assets/*
2+
cache-control: max-age=31536000
3+
cache-control: immutable

0 commit comments

Comments
 (0)
0