@apollion-dsi/relay 0.27.2 → 0.28.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 +146 -0
- package/lib/chunks/chunk-54QV6DFY.esm.js +1 -0
- package/lib/chunks/chunk-FYOI5Q5V.esm.js +0 -0
- package/lib/chunks/chunk-GZONWSRB.esm.js +1 -0
- package/lib/chunks/chunk-KIA6YWO5.esm.js +1 -0
- package/lib/chunks/chunk-RMYDTZUF.esm.js +1 -0
- package/lib/chunks/chunk-XJA2SRQY.esm.js +1 -0
- package/lib/commitMutation/commitMutation.d.ts +15 -15
- package/lib/commitMutation/index.d.ts +4 -4
- package/lib/commitMutation/index.esm.js +1 -0
- package/lib/index.d.ts +10 -10
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/mutationUtils/index.d.ts +5 -5
- package/lib/mutationUtils/index.esm.js +1 -0
- package/lib/mutationUtils/mutationUtils.d.ts +60 -60
- package/lib/relayArgsInterface/index.d.ts +3 -3
- package/lib/relayArgsInterface/index.esm.js +1 -0
- package/lib/relayArgsInterface/relayArgsInterface.d.ts +106 -79
- package/lib/setupRelayEnvironment/executeEnvironment.d.ts +13 -13
- package/lib/setupRelayEnvironment/fetchQuery.d.ts +19 -19
- package/lib/setupRelayEnvironment/fetchWithRetries.d.ts +20 -20
- package/lib/setupRelayEnvironment/index.d.ts +11 -0
- package/lib/setupRelayEnvironment/index.esm.js +1 -0
- package/lib/setupRelayEnvironment/setupRelayEnvironment.d.ts +74 -57
- package/lib/setupRelayEnvironment/setupRelayEnvironment.helpers.d.ts +64 -56
- package/lib/setupRelayEnvironment/storage.d.ts +17 -17
- package/lib/setupRelayEnvironment/subscriptionHandler.d.ts +26 -20
- package/lib/useEnvironment/index.d.ts +5 -5
- package/lib/useEnvironment/index.esm.js +1 -0
- package/lib/useEnvironment/useEnvironment.d.ts +16 -16
- package/package.json +33 -6
- package/README.MD +0 -119
package/package.json
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollion-dsi/relay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Frontend services regarding Relay Environment",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.esm.js",
|
|
12
|
+
"require": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./setupRelayEnvironment": {
|
|
15
|
+
"types": "./lib/setupRelayEnvironment/index.d.ts",
|
|
16
|
+
"import": "./lib/setupRelayEnvironment/index.esm.js"
|
|
17
|
+
},
|
|
18
|
+
"./useEnvironment": {
|
|
19
|
+
"types": "./lib/useEnvironment/index.d.ts",
|
|
20
|
+
"import": "./lib/useEnvironment/index.esm.js"
|
|
21
|
+
},
|
|
22
|
+
"./relayArgsInterface": {
|
|
23
|
+
"types": "./lib/relayArgsInterface/index.d.ts",
|
|
24
|
+
"import": "./lib/relayArgsInterface/index.esm.js"
|
|
25
|
+
},
|
|
26
|
+
"./mutationUtils": {
|
|
27
|
+
"types": "./lib/mutationUtils/index.d.ts",
|
|
28
|
+
"import": "./lib/mutationUtils/index.esm.js"
|
|
29
|
+
},
|
|
30
|
+
"./commitMutation": {
|
|
31
|
+
"types": "./lib/commitMutation/index.d.ts",
|
|
32
|
+
"import": "./lib/commitMutation/index.esm.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
8
36
|
"files": [
|
|
9
37
|
"lib/**/*"
|
|
10
38
|
],
|
|
11
39
|
"license": "MIT",
|
|
12
40
|
"scripts": {
|
|
13
|
-
"prepare": "yarn build",
|
|
14
|
-
"pretest": "relay-compiler",
|
|
15
41
|
"audit-dependencies": "yarn npm audit --severity moderate --no-deprecations",
|
|
16
42
|
"coverage": "jest --coverage",
|
|
17
43
|
"lint": "eslint src --quiet",
|
|
@@ -21,10 +47,11 @@
|
|
|
21
47
|
"prettier": "prettier --check **/*.{ts,tsx} --ignore-path .gitignore --no-error-on-unmatched-pattern",
|
|
22
48
|
"format": "yarn prettier --write",
|
|
23
49
|
"validate": "./scripts/validate.sh",
|
|
24
|
-
"validate:tests": "jest --coverage",
|
|
50
|
+
"validate:tests": "relay-compiler && relay-compiler relay.persisted.config.json && jest --coverage",
|
|
25
51
|
"build": "node -e \"require('fs').rmSync('./lib',{recursive:true,force:true})\" && node ./esbuild && tsc --emitDeclarationOnly",
|
|
26
52
|
"test": "yarn validate",
|
|
27
|
-
"code:check": "yarn lint && yarn coverage"
|
|
53
|
+
"code:check": "yarn lint && yarn coverage",
|
|
54
|
+
"prepack": "node ../../scripts/release-preflight.js && yarn build"
|
|
28
55
|
},
|
|
29
56
|
"peerDependencies": {
|
|
30
57
|
"react": "^19.0.0"
|
|
@@ -40,7 +67,7 @@
|
|
|
40
67
|
"relay-test-utils": "^21.0.0"
|
|
41
68
|
},
|
|
42
69
|
"devDependencies": {
|
|
43
|
-
"@apollion-dsi/eslint-config": "0.
|
|
70
|
+
"@apollion-dsi/eslint-config": "0.10.0",
|
|
44
71
|
"@babel/core": "7.29.0",
|
|
45
72
|
"@babel/plugin-transform-class-properties": "7.27.1",
|
|
46
73
|
"@babel/plugin-transform-runtime": "7.29.0",
|
package/README.MD
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# @apollion-dsi/relay
|
|
2
|
-
|
|
3
|
-
Helpers para configurar e usar **Relay** (`react-relay` / `relay-runtime`)
|
|
4
|
-
no padrão do Apollion DS. Cobre criação de Environment com auth,
|
|
5
|
-
upload multipart, subscriptions via WebSocket e cookies de sessão.
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@apollion-dsi/relay)
|
|
8
|
-
|
|
9
|
-
## Stack
|
|
10
|
-
|
|
11
|
-
- **react-relay** 20.x
|
|
12
|
-
- **relay-runtime** 20.x
|
|
13
|
-
- **graphql** 15.x
|
|
14
|
-
- **graphql-ws** 6.x (subscriptions)
|
|
15
|
-
- **fetch-multipart-graphql** (uploads)
|
|
16
|
-
- **js-cookie** (sessão)
|
|
17
|
-
|
|
18
|
-
## Instalação
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
yarn add @apollion-dsi/relay react@19.2.6
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
> Para gerar artefatos Relay, o consumidor também precisa de
|
|
25
|
-
> `relay-compiler` como dev dependency e configurar `relay.config.js`.
|
|
26
|
-
|
|
27
|
-
## Uso básico
|
|
28
|
-
|
|
29
|
-
Crie um Relay Environment para a aplicação:
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import { CreateRelayEnvironment } from '@apollion-dsi/relay';
|
|
33
|
-
|
|
34
|
-
export const { Environment } = new CreateRelayEnvironment({
|
|
35
|
-
url: 'https://api.example.com/graphql',
|
|
36
|
-
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Depois, embrulhe a árvore React com `RelayEnvironmentProvider`:
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
import { RelayEnvironmentProvider } from 'react-relay';
|
|
43
|
-
import { Environment } from './relay';
|
|
44
|
-
import { App } from './app';
|
|
45
|
-
|
|
46
|
-
<RelayEnvironmentProvider environment={Environment}>
|
|
47
|
-
<App />
|
|
48
|
-
</RelayEnvironmentProvider>;
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Recursos do helper
|
|
52
|
-
|
|
53
|
-
- **Autenticação** em dois modos: `Bearer` (token JS) ou **cookie
|
|
54
|
-
httpOnly** (ver abaixo).
|
|
55
|
-
- **Multipart uploads** (`fetch-multipart-graphql`) — envie arquivos
|
|
56
|
-
diretamente em mutations.
|
|
57
|
-
- **Subscriptions** via `graphql-ws`.
|
|
58
|
-
- **Network retry / refresh** plugável.
|
|
59
|
-
|
|
60
|
-
## Autenticação: Bearer vs. cookie httpOnly
|
|
61
|
-
|
|
62
|
-
O Environment suporta dois modelos de auth via `authMode`.
|
|
63
|
-
|
|
64
|
-
### `authMode: 'bearer'` (default — retrocompat)
|
|
65
|
-
|
|
66
|
-
Lê o `sessionToken` do storage (`localStorage`/`cookie` JS-legível) e
|
|
67
|
-
injeta `Authorization: Bearer <token>` em cada request. A verificação de
|
|
68
|
-
sessão usa o probe `${authUrl}user/me`. Comportamento idêntico ao das
|
|
69
|
-
versões anteriores — consumidores existentes não precisam mudar nada.
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
new CreateRelayEnvironment({
|
|
73
|
-
url: 'https://api.example.com/graphql/',
|
|
74
|
-
authUrl: 'https://api.example.com/auth/',
|
|
75
|
-
useAuthorization: true, // injeta Bearer
|
|
76
|
-
storageType: 'cookie', // cookie JS-legível ou 'localStorage'
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### `authMode: 'cookie'` (sessão por cookie httpOnly — recomendado p/ SPA)
|
|
81
|
-
|
|
82
|
-
Modelo seguro: o token de sessão vive num cookie **httpOnly + SameSite**
|
|
83
|
-
(invisível ao JS, imune a XSS). O Environment **não** lê o token nem
|
|
84
|
-
injeta `Authorization` — `credentials: 'include'` (default neste modo)
|
|
85
|
-
faz o browser anexar o cookie automaticamente, inclusive cross-origin.
|
|
86
|
-
Em erro de auth (ex: 401), o refresh é disparado com `POST` em `authUrl`
|
|
87
|
-
e `credentials: 'include'` — **sem** probe a `user/me`.
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
new CreateRelayEnvironment({
|
|
91
|
-
url: 'https://api.example.com/graphql/',
|
|
92
|
-
authUrl: 'https://api.example.com/auth/refresh/', // alvo do refresh on-401
|
|
93
|
-
authMode: 'cookie',
|
|
94
|
-
redirectOnError: true,
|
|
95
|
-
loginRoute: '/login',
|
|
96
|
-
});
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Opções relacionadas:
|
|
100
|
-
|
|
101
|
-
| Opção | Default | O que faz |
|
|
102
|
-
|---|---|---|
|
|
103
|
-
| `authMode` | `'bearer'` | `'bearer'` (token + header) ou `'cookie'` (httpOnly). |
|
|
104
|
-
| `credentials` | cookie→`'include'`; bearer→omitido | `RequestCredentials` repassado aos fetches GraphQL e de refresh. Funciona nos dois modos. |
|
|
105
|
-
| `sessionCheckUrl` | modo-dependente | Sobrescreve a URL do probe; `false` desliga o probe (erro de auth → logout direto, sem request extra). |
|
|
106
|
-
|
|
107
|
-
## Scripts (workspace)
|
|
108
|
-
|
|
109
|
-
| Script | O que faz |
|
|
110
|
-
|---|---|
|
|
111
|
-
| `yarn workspace @apollion-dsi/relay run validate` | Lint + types + prettier + Jest + build. |
|
|
112
|
-
| `yarn workspace @apollion-dsi/relay run coverage` | Jest coverage. |
|
|
113
|
-
| `yarn workspace @apollion-dsi/relay run build` | esbuild + emit de types. |
|
|
114
|
-
| `yarn workspace @apollion-dsi/relay run audit-dependencies` | audit-ci. |
|
|
115
|
-
| `yarn workspace @apollion-dsi/relay run pretest` | `relay-compiler` (gera `__generated__` antes dos testes). |
|
|
116
|
-
|
|
117
|
-
## Licença
|
|
118
|
-
|
|
119
|
-
MIT.
|