Skip to content

Commit

Permalink
Go
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Nov 9, 2022
1 parent 92d81e7 commit defe47f
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 53 deletions.
5 changes: 3 additions & 2 deletions packages/executors/graphql-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@
},
"dependencies": {
"@types/ws": "^8.0.0",
"ws": "8.11.0",
"isomorphic-ws": "5.0.0",
"@graphql-tools/utils": "9.1.0",
"@repeaterjs/repeater": "3.0.4",
"graphql-ws": "5.11.2",
"isomorphic-ws": "5.0.0",
"ws": "8.11.0"
"tslib": "^2.4.0"
},
"publishConfig": {
"directory": "dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/executors/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"@repeaterjs/repeater": "3.0.4",
"dset": "3.1.2",
"meros": "1.2.1",
"extract-files": "^11.0.0"
"extract-files": "^11.0.0",
"tslib": "^2.4.0"
},
"publishConfig": {
"directory": "dist",
Expand Down
2 changes: 2 additions & 0 deletions packages/executors/http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,5 @@ export function buildHTTPExecutor(

return executor;
}

export { isLiveQueryOperationDefinitionNode };
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { OperationDefinitionNode } from 'graphql';
export const isLiveQueryOperationDefinitionNode = memoize1(function isLiveQueryOperationDefinitionNode(
node: OperationDefinitionNode
) {
return node.directives?.some(directive => directive.name.value === 'live');
return node.operation === 'query' && node.directives?.some(directive => directive.name.value === 'live');
});
3 changes: 2 additions & 1 deletion packages/executors/legacy-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"@types/ws": "^8.0.0",
"@graphql-tools/utils": "9.1.0",
"isomorphic-ws": "5.0.0",
"ws": "8.11.0"
"ws": "8.11.0",
"tslib": "^2.4.0"
},
"publishConfig": {
"directory": "dist",
Expand Down
4 changes: 3 additions & 1 deletion packages/loaders/url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
"@graphql-tools/wrap": "9.2.11",
"@ardatan/sync-fetch": "0.0.1",
"@whatwg-node/fetch": "^0.5.0",
"isomorphic-ws": "^5.0.0",
"@types/ws": "^8.0.0",
"ws": "8.11.0",
"isomorphic-ws": "5.0.0",
"tslib": "^2.4.0",
"value-or-promise": "^1.0.11"
},
Expand Down
36 changes: 2 additions & 34 deletions packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ import {
ExecutionRequest,
parseGraphQLSDL,
getOperationASTFromRequest,
createGraphQLError,
ExecutionResult,
} from '@graphql-tools/utils';
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
import WebSocket from 'isomorphic-ws';
import { ValueOrPromise } from 'value-or-promise';
import { defaultAsyncFetch } from './defaultAsyncFetch.js';
import { defaultSyncFetch } from './defaultSyncFetch.js';
import { isLiveQueryOperationDefinitionNode } from './utils.js';
import { buildGraphQLWSExecutor } from '@graphql-tools/executor-graphql-ws';
import {
AsyncFetchFn,
buildHTTPExecutor,
FetchFn,
HTTPExecutorOptions,
SyncFetchFn,
isLiveQueryOperationDefinitionNode,
} from '@graphql-tools/executor-http';
import { buildWSLegacyExecutor } from '@graphql-tools/executor-legacy-ws';

Expand Down Expand Up @@ -145,37 +143,7 @@ export class UrlLoader implements Loader<LoadFromUrlOptions> {
ws: 'http',
});

const executor = buildHTTPExecutor(HTTP_URL, fetch as any, options);

if (options?.retry != null) {
return function retryExecutor(request: ExecutionRequest) {
let result: ExecutionResult<any> | undefined;
let attempt = 0;
function retryAttempt(): Promise<ExecutionResult<any>> | ExecutionResult<any> {
attempt++;
if (attempt > options!.retry!) {
if (result != null) {
return result;
}
return {
errors: [createGraphQLError('No response returned from fetch')],
};
}
return new ValueOrPromise(() => executor(request))
.then(res => {
result = res;
if (result?.errors?.length) {
return retryAttempt();
}
return result;
})
.resolve();
}
return retryAttempt();
};
}

return executor;
return buildHTTPExecutor(HTTP_URL, fetch as any, options);
}

buildWSExecutor(
Expand Down
12 changes: 0 additions & 12 deletions packages/loaders/url/src/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7542,7 +7542,7 @@ isomorphic-fetch@^3.0.0:
node-fetch "^2.6.1"
whatwg-fetch "^3.4.1"

isomorphic-ws@5.0.0, isomorphic-ws@^5.0.0:
isomorphic-ws@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz#e5529148912ecb9b451b46ed44d53dae1ce04bbf"
integrity sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==
Expand Down

0 comments on commit defe47f

Please sign in to comment.