@uniflowed/graphql 0.1.0 → 0.3.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/index.js +22 -6
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import type { FetchClient } from "@uniflowed/fetch";
|
|
21
21
|
import { Environment, Network, Observable, RecordSource, Store } from "relay-runtime";
|
|
22
|
+
import type { GraphQLResponse, RequestParameters, Variables } from "relay-runtime";
|
|
22
23
|
|
|
23
24
|
export type { Environment } from "relay-runtime";
|
|
24
25
|
|
|
@@ -80,17 +81,16 @@ export function createEnvironment(options: EnvironmentOptions): Environment {
|
|
|
80
81
|
* function and not one uf guesses at.
|
|
81
82
|
*/
|
|
82
83
|
function fetchOperation(options: EnvironmentOptions) {
|
|
83
|
-
return async function run(
|
|
84
|
-
|
|
84
|
+
return async function run(
|
|
85
|
+
request: RequestParameters,
|
|
86
|
+
variables: Variables,
|
|
87
|
+
): Promise<GraphQLResponse> {
|
|
85
88
|
// `raw` rather than `request`: a GraphQL endpoint answers 200 with an
|
|
86
89
|
// `errors` array, so the status is not the outcome and the body has to be
|
|
87
90
|
// read either way.
|
|
88
91
|
const response = await options.fetch.raw(options.endpoint, {
|
|
89
92
|
method: "POST",
|
|
90
|
-
headers:
|
|
91
|
-
accept: "application/graphql-response+json, application/json",
|
|
92
|
-
...(options.headers ?? {}),
|
|
93
|
-
},
|
|
93
|
+
headers: requestHeaders(options.headers),
|
|
94
94
|
body: {
|
|
95
95
|
query: request.text,
|
|
96
96
|
variables,
|
|
@@ -110,4 +110,20 @@ function fetchOperation(options: EnvironmentOptions) {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* GraphQL's `accept`, then the caller's headers, which win on a clash — a
|
|
115
|
+
* gateway that wants a different media type says so.
|
|
116
|
+
*/
|
|
117
|
+
function requestHeaders(given: { readonly [string]: string } | void): { [string]: string } {
|
|
118
|
+
const headers: { [string]: string } = {
|
|
119
|
+
accept: "application/graphql-response+json, application/json",
|
|
120
|
+
};
|
|
121
|
+
if (given != null) {
|
|
122
|
+
for (const name of Object.keys(given)) {
|
|
123
|
+
headers[name] = given[name];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return headers;
|
|
127
|
+
}
|
|
128
|
+
|
|
113
129
|
export { Observable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniflowed/graphql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The Relay environment, without the boilerplate, for the Unified Toolchain for Flow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"!*.test.js"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@uniflowed/fetch": "0.
|
|
21
|
+
"@uniflowed/fetch": "0.3.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"relay-runtime": ">=20"
|