Skip to content

Commit af9a78d

Browse files
ardatann1ru4l
andauthoredJul 7, 2021
handle glob in loaders and return Source[] instead of Source (#3157)
* Handle glob in loaders and return Source[] instead of Source * Fix TS * include rawSDL in Source of plucked files (#3161) Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
1 parent c6c382b commit af9a78d

31 files changed

+414
-576
lines changed
 

‎.changeset/blue-ducks-stare.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@graphql-tools/load': major
3+
'@graphql-tools/apollo-engine-loader': major
4+
'@graphql-tools/code-file-loader': major
5+
'@graphql-tools/git-loader': major
6+
'@graphql-tools/github-loader': major
7+
'@graphql-tools/graphql-file-loader': major
8+
'@graphql-tools/json-file-loader': major
9+
'@graphql-tools/module-loader': major
10+
'@graphql-tools/url-loader': major
11+
'@graphql-tools/utils': major
12+
---
13+
14+
BREAKING CHANGE
15+
16+
- Now each loader handles glob patterns internally and returns an array of `Source` object instead of single `Source`
17+
18+
- GraphQL Tag Pluck now respects code locations and returns graphql-js `Source` objects for each found code block
19+
20+
- Thanks to the one above, `CodeFileLoader` now returns different `Source` objects for each found SDL code block.

‎.changeset/khaki-balloons-check.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/code-file-loader': minor
3+
---
4+
5+
include rawSDL in Source of plucked files

‎packages/load/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,15 @@
3030
"graphql": "^14.0.0 || ^15.0.0"
3131
},
3232
"devDependencies": {
33-
"@types/is-glob": "4.0.2",
34-
"@types/valid-url": "1.0.3",
3533
"graphql-tag": "2.12.5",
3634
"graphql-type-json": "0.3.2"
3735
},
3836
"dependencies": {
3937
"@graphql-tools/utils": "^7.5.0",
4038
"@graphql-tools/merge": "^6.2.12",
4139
"import-from": "4.0.0",
42-
"is-glob": "4.0.1",
4340
"p-limit": "3.1.0",
44-
"tslib": "~2.3.0",
45-
"valid-url": "1.0.9"
41+
"tslib": "~2.3.0"
4642
},
4743
"publishConfig": {
4844
"access": "public",

‎packages/load/src/load-typedefs.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Source, SingleFileOptions, Loader, compareStrings } from '@graphql-tools/utils';
1+
import { Source, BaseLoaderOptions, Loader, compareStrings, asArray } from '@graphql-tools/utils';
22
import { normalizePointers } from './utils/pointers';
33
import { applyDefaultOptions } from './load-typedefs/options';
44
import { collectSources, collectSourcesSync } from './load-typedefs/collect-sources';
@@ -7,12 +7,11 @@ import { useLimit } from './utils/helpers';
77

88
const CONCURRENCY_LIMIT = 100;
99

10-
export type LoadTypedefsOptions<ExtraConfig = { [key: string]: any }> = SingleFileOptions &
10+
export type LoadTypedefsOptions<ExtraConfig = { [key: string]: any }> = BaseLoaderOptions &
1111
ExtraConfig & {
1212
cache?: { [key: string]: Source };
1313
loaders: Loader[];
1414
filterKinds?: string[];
15-
ignore?: string | string[];
1615
sort?: boolean;
1716
};
1817

@@ -29,8 +28,10 @@ export async function loadTypedefs<AdditionalConfig = Record<string, unknown>>(
2928
pointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[],
3029
options: LoadTypedefsOptions<Partial<AdditionalConfig>>
3130
): Promise<Source[]> {
32-
const pointerOptionMap = normalizePointers(pointerOrPointers);
33-
const globOptions: any = {};
31+
const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
32+
33+
options.ignore = asArray(options.ignore || []);
34+
options.ignore.push(...ignore);
3435

3536
applyDefaultOptions<AdditionalConfig>(options);
3637

@@ -50,7 +51,6 @@ export async function loadTypedefs<AdditionalConfig = Record<string, unknown>>(
5051
parseSource({
5152
partialSource,
5253
options,
53-
globOptions,
5454
pointerOptionMap,
5555
addValidSource(source) {
5656
validSources.push(source);
@@ -74,8 +74,10 @@ export function loadTypedefsSync<AdditionalConfig = Record<string, unknown>>(
7474
pointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[],
7575
options: LoadTypedefsOptions<Partial<AdditionalConfig>>
7676
): Source[] {
77-
const pointerOptionMap = normalizePointers(pointerOrPointers);
78-
const globOptions: any = {};
77+
const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
78+
79+
options.ignore = asArray(options.ignore || []);
80+
options.ignore.push(...ignore);
7981

8082
applyDefaultOptions<AdditionalConfig>(options);
8183

@@ -90,7 +92,6 @@ export function loadTypedefsSync<AdditionalConfig = Record<string, unknown>>(
9092
parseSource({
9193
partialSource,
9294
options,
93-
globOptions,
9495
pointerOptionMap,
9596
addValidSource(source) {
9697
validSources.push(source);

0 commit comments

Comments
 (0)
Please sign in to comment.