Skip to content

Commit f0ed482

Browse files
feat: add client type generation and watcher for GraphQL files
- Implemented client type generation in `client-codegen.ts` using GraphQL Code Generator. - Created a file watcher in `client-watcher.ts` to regenerate client types on file changes. - Updated `index.ts` to setup the client watcher during development. - Enhanced type definitions in `types.ts` to support client configuration options.
1 parent 4fbf61b commit f0ed482

File tree

10 files changed

+1297
-1
lines changed

10 files changed

+1297
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"@graphql-codegen/core": "^4.0.2",
3232
"@graphql-codegen/plugin-helpers": "^5.1.1",
3333
"@graphql-codegen/typescript": "^4.1.6",
34+
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
35+
"@graphql-codegen/typescript-operations": "^4.6.1",
3436
"@graphql-codegen/typescript-resolvers": "^4.5.1",
3537
"@graphql-tools/graphql-file-loader": "^8.0.20",
3638
"@graphql-tools/load": "^8.1.0",

playground/client/example.ts

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
mutation CreateUser($input: CreateUserInput!) {
2+
createUser(input: $input) {
3+
id
4+
name
5+
email
6+
createdAt
7+
}
8+
}
9+
10+
mutation AddTodo($title: String!) {
11+
addTodo(title: $title) {
12+
id
13+
title
14+
completed
15+
createdAt
16+
}
17+
}
18+
19+
mutation ToggleTodo($id: ID!) {
20+
toggleTodo(id: $id) {
21+
id
22+
title
23+
completed
24+
createdAt
25+
}
26+
}
27+
28+
mutation DeleteTodo($id: ID!) {
29+
deleteTodo(id: $id)
30+
}
31+
32+
mutation CreatePost($input: CreatePostInput!) {
33+
createPost(input: $input) {
34+
id
35+
title
36+
content
37+
authorId
38+
}
39+
}
40+
41+
mutation AddComment($input: AddCommentInput!) {
42+
addComment(input: $input) {
43+
id
44+
content
45+
postId
46+
authorId
47+
}
48+
}

playground/client/queries.graphql

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
query GetUsers {
2+
users {
3+
id
4+
name
5+
email
6+
createdAt
7+
}
8+
}
9+
10+
query GetUser($id: ID!) {
11+
user(id: $id) {
12+
id
13+
name
14+
email
15+
createdAt
16+
}
17+
}
18+
19+
query GetTodos {
20+
todos {
21+
id
22+
title
23+
completed
24+
createdAt
25+
}
26+
}
27+
28+
query GetPosts {
29+
posts {
30+
id
31+
title
32+
content
33+
authorId
34+
}
35+
}
36+
37+
query GetPostWithComments($postId: ID!) {
38+
post(id: $postId) {
39+
id
40+
title
41+
content
42+
authorId
43+
}
44+
comments(postId: $postId) {
45+
id
46+
content
47+
authorId
48+
}
49+
}

playground/nitro.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ export default defineNitroConfig({
1111
origin: '*',
1212
credentials: true,
1313
},
14+
client: {
15+
enabled: true,
16+
watchPatterns: [
17+
'client/**/*.graphql',
18+
'client/**/*.gql',
19+
],
20+
},
1421
},
1522
})

0 commit comments

Comments
 (0)