@hyper-fetch/graphql 9.8.0 → 9.9.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 +40 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# 🎡 Hyper Fetch GraphQL
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<b>GraphQL adapter for HyperFetch. Typed queries
|
|
4
|
+
<b>GraphQL adapter for HyperFetch. Typed queries and mutations over HTTP.</b>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
|
|
34
34
|
## 📖 About
|
|
35
35
|
|
|
36
|
-
This adapter connects HyperFetch to GraphQL APIs. You get typed queries
|
|
36
|
+
This adapter connects HyperFetch to GraphQL APIs over HTTP. You get typed queries and mutations that work with
|
|
37
37
|
HyperFetch's caching, queuing, and React hooks — the same request patterns you use for REST, but with GraphQL
|
|
38
|
-
operations.
|
|
38
|
+
operations. Subscriptions are not supported.
|
|
39
39
|
|
|
40
40
|
## 🎯 Key Capabilities
|
|
41
41
|
|
|
42
|
-
- 🎡 **GraphQL meets HyperFetch** — Typed queries
|
|
42
|
+
- 🎡 **GraphQL meets HyperFetch** — Typed queries and mutations with cache and queue support
|
|
43
43
|
- 🔮 **End-to-end types** — Full TypeScript types for operations, variables, and responses
|
|
44
44
|
- 📡 **Any GraphQL server** — Compatible with Apollo, Yoga, Hasura, and any spec-compliant endpoint
|
|
45
45
|
- ⚛️ **React-ready** — Use `useFetch` and `useSubmit` for GraphQL operations in components
|
|
@@ -48,19 +48,19 @@ operations.
|
|
|
48
48
|
## 🚀 Quick Start
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
npm install @hyper-fetch/core @hyper-fetch/graphql
|
|
51
|
+
npm install @hyper-fetch/core @hyper-fetch/graphql graphql-tag
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
55
|
import { createClient } from "@hyper-fetch/core";
|
|
56
|
-
import {
|
|
56
|
+
import { GraphqlAdapter } from "@hyper-fetch/graphql";
|
|
57
57
|
|
|
58
|
-
const client = createClient({ url: "https://api.example.com/graphql" }).setAdapter(
|
|
58
|
+
const client = createClient({ url: "https://api.example.com/graphql" }).setAdapter(GraphqlAdapter());
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
## 📚 Documentation
|
|
62
62
|
|
|
63
|
-
- [GraphQL Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-graphql)
|
|
63
|
+
- [GraphQL Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-graphql/overview)
|
|
64
64
|
- [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
|
|
65
65
|
- [API Reference](https://hyperfetch.bettertyped.com/api/)
|
|
66
66
|
|
|
@@ -68,32 +68,31 @@ const client = createClient({ url: "https://api.example.com/graphql" }).setAdapt
|
|
|
68
68
|
|
|
69
69
|
### Query
|
|
70
70
|
|
|
71
|
+
The query goes in `endpoint` as a `gql` document.
|
|
72
|
+
|
|
71
73
|
```ts
|
|
74
|
+
import gql from "graphql-tag";
|
|
75
|
+
|
|
72
76
|
interface UsersResponse {
|
|
73
77
|
users: { id: string; name: string; email: string }[];
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
const getUsers = client.createRequest<{ response: UsersResponse }>()({
|
|
77
|
-
endpoint:
|
|
78
|
-
|
|
80
|
+
const getUsers = client.createRequest<{ response: UsersResponse; payload: { limit: number } }>()({
|
|
81
|
+
endpoint: gql`
|
|
82
|
+
query GetUsers($limit: Int) {
|
|
83
|
+
users(limit: $limit) {
|
|
84
|
+
id
|
|
85
|
+
name
|
|
86
|
+
email
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
79
90
|
});
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
query: `
|
|
84
|
-
query GetUsers($limit: Int) {
|
|
85
|
-
users(limit: $limit) {
|
|
86
|
-
id
|
|
87
|
-
name
|
|
88
|
-
email
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
`,
|
|
92
|
-
variables: { limit: 10 },
|
|
93
|
-
})
|
|
94
|
-
.send();
|
|
92
|
+
// The payload is sent as the GraphQL variables
|
|
93
|
+
const { data } = await getUsers.send({ payload: { limit: 10 } });
|
|
95
94
|
|
|
96
|
-
console.log(data
|
|
95
|
+
console.log(data?.users);
|
|
97
96
|
```
|
|
98
97
|
|
|
99
98
|
### Mutation
|
|
@@ -105,26 +104,23 @@ interface CreateUserResponse {
|
|
|
105
104
|
|
|
106
105
|
const createUser = client.createRequest<{
|
|
107
106
|
response: CreateUserResponse;
|
|
107
|
+
payload: { name: string; email: string };
|
|
108
108
|
}>()({
|
|
109
|
-
endpoint:
|
|
110
|
-
|
|
109
|
+
endpoint: gql`
|
|
110
|
+
mutation CreateUser($name: String!, $email: String!) {
|
|
111
|
+
createUser(name: $name, email: $email) {
|
|
112
|
+
id
|
|
113
|
+
name
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
111
117
|
});
|
|
112
118
|
|
|
113
|
-
const { data } = await createUser
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
mutation CreateUser($name: String!, $email: String!) {
|
|
117
|
-
createUser(name: $name, email: $email) {
|
|
118
|
-
id
|
|
119
|
-
name
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
`,
|
|
123
|
-
variables: { name: "Jane", email: "jane@example.com" },
|
|
124
|
-
})
|
|
125
|
-
.send();
|
|
119
|
+
const { data } = await createUser.send({
|
|
120
|
+
payload: { name: "Jane", email: "jane@example.com" },
|
|
121
|
+
});
|
|
126
122
|
|
|
127
|
-
console.log("Created:", data
|
|
123
|
+
console.log("Created:", data?.createUser.name);
|
|
128
124
|
```
|
|
129
125
|
|
|
130
126
|
### With React hooks
|
|
@@ -133,11 +129,7 @@ console.log("Created:", data.createUser.name);
|
|
|
133
129
|
import { useFetch } from "@hyper-fetch/react";
|
|
134
130
|
|
|
135
131
|
const UserList = () => {
|
|
136
|
-
const { data, loading } = useFetch(
|
|
137
|
-
getUsers.setData({
|
|
138
|
-
query: `{ users { id name } }`,
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
132
|
+
const { data, loading } = useFetch(getUsers.setPayload({ limit: 10 }));
|
|
141
133
|
|
|
142
134
|
if (loading) return <p>Loading...</p>;
|
|
143
135
|
return (
|
|
@@ -152,4 +144,4 @@ const UserList = () => {
|
|
|
152
144
|
|
|
153
145
|
## License
|
|
154
146
|
|
|
155
|
-
[
|
|
147
|
+
[Apache-2.0](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": "9.
|
|
3
|
+
"version": "9.9.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/",
|