@hyper-fetch/graphql 8.1.1 โ 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# ๐ก Hyper Fetch GraphQL
|
|
2
2
|
|
|
3
|
-
<p>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>GraphQL adapter for HyperFetch. Typed queries, mutations, and subscriptions.</b>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
4
8
|
<a href="https://bettertyped.com/">
|
|
5
9
|
<img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
|
|
6
10
|
</a>
|
|
@@ -13,58 +17,131 @@
|
|
|
13
17
|
<a href="https://www.npmjs.com/package/@hyper-fetch/graphql">
|
|
14
18
|
<img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/graphql.svg?logo=npm&color=e76f51" />
|
|
15
19
|
</a>
|
|
16
|
-
<a href="https://
|
|
17
|
-
<img src="https://custom-icon-badges.demolab.com/
|
|
20
|
+
<a href="https://www.npmjs.com/package/@hyper-fetch/graphql">
|
|
21
|
+
<img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/graphql?logoColor=fff&logo=trending-up" />
|
|
18
22
|
</a>
|
|
19
23
|
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
20
|
-
<img src="https://custom-icon-badges.demolab.com/badge
|
|
24
|
+
<img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
|
|
21
25
|
</a>
|
|
22
|
-
<a href="https://
|
|
26
|
+
<a href="https://bundlephobia.com/package/@hyper-fetch/graphql">
|
|
23
27
|
<img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/graphql?color=64BC4B&logo=package" />
|
|
24
28
|
</a>
|
|
29
|
+
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
30
|
+
<img src="https://img.shields.io/badge/graphql-e10098?logo=graphql&logoColor=white" alt="GraphQL" />
|
|
31
|
+
</a>
|
|
25
32
|
</p>
|
|
26
33
|
|
|
27
|
-
## About
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
๐ก
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
34
|
+
## ๐ About
|
|
35
|
+
|
|
36
|
+
This adapter connects HyperFetch to GraphQL APIs. You get typed queries, mutations, and subscriptions that work with HyperFetch's caching, queuing, and React hooks โ the same request patterns you use for REST, but with GraphQL operations.
|
|
37
|
+
|
|
38
|
+
## ๐ฏ Key Capabilities
|
|
39
|
+
|
|
40
|
+
- ๐ก **GraphQL meets HyperFetch** โ Typed queries, mutations, and subscriptions with cache and queue support
|
|
41
|
+
- ๐ฎ **End-to-end types** โ Full TypeScript types for operations, variables, and responses
|
|
42
|
+
- ๐ก **Any GraphQL server** โ Compatible with Apollo, Yoga, Hasura, and any spec-compliant endpoint
|
|
43
|
+
- โ๏ธ **React-ready** โ Use `useFetch` and `useSubmit` for GraphQL operations in components
|
|
44
|
+
- ๐พ **Smart caching included** โ Cache and offline support work the same as REST โ no extra config
|
|
45
|
+
|
|
46
|
+
## ๐ Quick Start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @hyper-fetch/core @hyper-fetch/graphql
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { createClient } from "@hyper-fetch/core";
|
|
54
|
+
import { GraphQLAdapter } from "@hyper-fetch/graphql";
|
|
55
|
+
|
|
56
|
+
const client = createClient({ url: "https://api.example.com/graphql" }).setAdapter(GraphQLAdapter());
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## ๐ Documentation
|
|
60
|
+
|
|
61
|
+
- [GraphQL Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-graphql)
|
|
62
|
+
- [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
|
|
63
|
+
- [API Reference](https://hyperfetch.bettertyped.com/api/)
|
|
64
|
+
|
|
65
|
+
## ๐ก Examples
|
|
66
|
+
|
|
67
|
+
### Query
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
interface UsersResponse {
|
|
71
|
+
users: { id: string; name: string; email: string }[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getUsers = client.createRequest<{ response: UsersResponse }>()({
|
|
75
|
+
endpoint: "",
|
|
76
|
+
method: "POST",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const { data } = await getUsers
|
|
80
|
+
.setData({
|
|
81
|
+
query: `
|
|
82
|
+
query GetUsers($limit: Int) {
|
|
83
|
+
users(limit: $limit) {
|
|
84
|
+
id
|
|
85
|
+
name
|
|
86
|
+
email
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
variables: { limit: 10 },
|
|
91
|
+
})
|
|
92
|
+
.send();
|
|
93
|
+
|
|
94
|
+
console.log(data.users);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Mutation
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
interface CreateUserResponse {
|
|
101
|
+
createUser: { id: string; name: string };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const createUser = client.createRequest<{
|
|
105
|
+
response: CreateUserResponse;
|
|
106
|
+
}>()({
|
|
107
|
+
endpoint: "",
|
|
108
|
+
method: "POST",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const { data } = await createUser
|
|
112
|
+
.setData({
|
|
113
|
+
query: `
|
|
114
|
+
mutation CreateUser($name: String!, $email: String!) {
|
|
115
|
+
createUser(name: $name, email: $email) {
|
|
116
|
+
id
|
|
117
|
+
name
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
variables: { name: "Jane", email: "jane@example.com" },
|
|
122
|
+
})
|
|
123
|
+
.send();
|
|
124
|
+
|
|
125
|
+
console.log("Created:", data.createUser.name);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### With React hooks
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { useFetch } from "@hyper-fetch/react";
|
|
132
|
+
|
|
133
|
+
const UserList = () => {
|
|
134
|
+
const { data, loading } = useFetch(
|
|
135
|
+
getUsers.setData({
|
|
136
|
+
query: `{ users { id name } }`,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (loading) return <p>Loading...</p>;
|
|
141
|
+
return <ul>{data?.users.map((u) => <li key={u.id}>{u.name}</li>)}</ul>;
|
|
142
|
+
};
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
[MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/graphql",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "Simple graphql adapter",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|