Skip to content

Commit b08313d

Browse files
Michael Kasererchristianalfoni
authored andcommitted
feat(overmind-graphql): initialize typing improved
1 parent d37f0af commit b08313d

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"tslib": "1.10.0",
6262
"vscode": "^1.1.36",
6363
"vue": "3.0.0-rc.10",
64-
"ws": "7.0.0"
64+
"ws": "7.0.0",
65+
"cross-fetch": "3.0.6"
6566
},
6667
"devDependencies": {
6768
"@babel/core": "7.4.5",

packages/node_modules/overmind-graphql/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
],
3333
"dependencies": {
3434
"@absinthe/socket": "^0.2.1",
35+
"cross-fetch": "^3.0.6",
3536
"graphql": "^14.5.8",
3637
"graphql-request": "^3.1.0",
3738
"graphql-tag": "^2.10.3",

packages/node_modules/overmind-graphql/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as withAbsintheSocket from '@absinthe/socket';
22
import { GraphQLClient } from 'graphql-request';
3-
import {
4-
Headers as HttpHeaders,
5-
RequestInit as Options,
6-
} from 'graphql-request/dist/types.dom';
3+
import { RequestInit } from 'graphql-request/dist/types.dom';
74
import { print } from 'graphql/language/printer';
85
import { Socket as PhoenixSocket } from 'phoenix';
6+
import { Headers } from 'cross-fetch';
97

108
import gqlTag from 'graphql-tag';
119

1210

11+
// Fix for issue in version 3.1.0 of graphql-request: https://github.com/prisma-labs/graphql-request/issues/206
12+
// @ts-ignore
13+
global.Headers = global.Headers || Headers;
14+
1315
export interface Query<Result extends any, Payload extends any = void> {
1416
(payload: Payload): Result;
1517
}
@@ -35,8 +37,8 @@ interface Subscription {
3537

3638
type Http = {
3739
endpoint: string;
38-
headers?: () => HttpHeaders;
39-
options?: Options;
40+
headers?: () => RequestInit['headers'];
41+
options?: RequestInit;
4042
};
4143

4244
type Ws =
@@ -117,8 +119,11 @@ export const graphql: <T extends Queries>(
117119
: {};
118120

119121
if (_clients[_http.endpoint]) {
122+
console.log("SET HEADERS")
120123
_clients[_http.endpoint].setHeaders(headers);
121124
} else {
125+
console.log("HEADERS", typeof headers, headers)
126+
console.log("HEADERS ALREADY SET", headers)
122127
_clients[_http.endpoint] = new GraphQLClient(_http.endpoint, {
123128
..._http.options,
124129
headers,

0 commit comments

Comments
 (0)