Skip to content

Commit

Permalink
feat(overmind-graphql): initialize typing improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kaserer authored and christianalfoni committed Jan 23, 2021
1 parent 6db1de6 commit 9d73403
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"tslib": "1.10.0",
"vscode": "^1.1.36",
"vue": "3.0.0-rc.10",
"ws": "7.0.0"
"ws": "7.0.0",
"cross-fetch": "3.0.6"
},
"devDependencies": {
"@babel/core": "7.4.5",
Expand Down
1 change: 1 addition & 0 deletions packages/node_modules/overmind-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"dependencies": {
"@absinthe/socket": "^0.2.1",
"cross-fetch": "^3.0.6",
"graphql": "^14.5.8",
"graphql-request": "^3.1.0",
"graphql-tag": "^2.10.3",
Expand Down
17 changes: 11 additions & 6 deletions packages/node_modules/overmind-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as withAbsintheSocket from '@absinthe/socket';
import { GraphQLClient } from 'graphql-request';
import {
Headers as HttpHeaders,
RequestInit as Options,
} from 'graphql-request/dist/types.dom';
import { RequestInit } from 'graphql-request/dist/types.dom';
import { print } from 'graphql/language/printer';
import { Socket as PhoenixSocket } from 'phoenix';
import { Headers } from 'cross-fetch';

import gqlTag from 'graphql-tag';


// Fix for issue in version 3.1.0 of graphql-request: https://github.com/prisma-labs/graphql-request/issues/206
// @ts-ignore
global.Headers = global.Headers || Headers;

export interface Query<Result extends any, Payload extends any = void> {
(payload: Payload): Result;
}
Expand All @@ -35,8 +37,8 @@ interface Subscription {

type Http = {
endpoint: string;
headers?: () => HttpHeaders;
options?: Options;
headers?: () => RequestInit['headers'];
options?: RequestInit;
};

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

if (_clients[_http.endpoint]) {
console.log("SET HEADERS")
_clients[_http.endpoint].setHeaders(headers);
} else {
console.log("HEADERS", typeof headers, headers)
console.log("HEADERS ALREADY SET", headers)
_clients[_http.endpoint] = new GraphQLClient(_http.endpoint, {
..._http.options,
headers,
Expand Down

0 comments on commit 9d73403

Please sign in to comment.