Skip to content

Commit

Permalink
handle glob in loaders and return Source[] instead of Source (#3157)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ardatan and n1ru4l authored Jul 7, 2021
1 parent c6c382b commit af9a78d
Show file tree
Hide file tree
Showing 31 changed files with 414 additions and 576 deletions.
20 changes: 20 additions & 0 deletions .changeset/blue-ducks-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@graphql-tools/load': major
'@graphql-tools/apollo-engine-loader': major
'@graphql-tools/code-file-loader': major
'@graphql-tools/git-loader': major
'@graphql-tools/github-loader': major
'@graphql-tools/graphql-file-loader': major
'@graphql-tools/json-file-loader': major
'@graphql-tools/module-loader': major
'@graphql-tools/url-loader': major
'@graphql-tools/utils': major
---

BREAKING CHANGE

- Now each loader handles glob patterns internally and returns an array of `Source` object instead of single `Source`

- GraphQL Tag Pluck now respects code locations and returns graphql-js `Source` objects for each found code block

- Thanks to the one above, `CodeFileLoader` now returns different `Source` objects for each found SDL code block.
5 changes: 5 additions & 0 deletions .changeset/khaki-balloons-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/code-file-loader': minor
---

include rawSDL in Source of plucked files
6 changes: 1 addition & 5 deletions packages/load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@
"graphql": "^14.0.0 || ^15.0.0"
},
"devDependencies": {
"@types/is-glob": "4.0.2",
"@types/valid-url": "1.0.3",
"graphql-tag": "2.12.5",
"graphql-type-json": "0.3.2"
},
"dependencies": {
"@graphql-tools/utils": "^7.5.0",
"@graphql-tools/merge": "^6.2.12",
"import-from": "4.0.0",
"is-glob": "4.0.1",
"p-limit": "3.1.0",
"tslib": "~2.3.0",
"valid-url": "1.0.9"
"tslib": "~2.3.0"
},
"publishConfig": {
"access": "public",
Expand Down
19 changes: 10 additions & 9 deletions packages/load/src/load-typedefs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Source, SingleFileOptions, Loader, compareStrings } from '@graphql-tools/utils';
import { Source, BaseLoaderOptions, Loader, compareStrings, asArray } from '@graphql-tools/utils';
import { normalizePointers } from './utils/pointers';
import { applyDefaultOptions } from './load-typedefs/options';
import { collectSources, collectSourcesSync } from './load-typedefs/collect-sources';
Expand All @@ -7,12 +7,11 @@ import { useLimit } from './utils/helpers';

const CONCURRENCY_LIMIT = 100;

export type LoadTypedefsOptions<ExtraConfig = { [key: string]: any }> = SingleFileOptions &
export type LoadTypedefsOptions<ExtraConfig = { [key: string]: any }> = BaseLoaderOptions &
ExtraConfig & {
cache?: { [key: string]: Source };
loaders: Loader[];
filterKinds?: string[];
ignore?: string | string[];
sort?: boolean;
};

Expand All @@ -29,8 +28,10 @@ export async function loadTypedefs<AdditionalConfig = Record<string, unknown>>(
pointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[],
options: LoadTypedefsOptions<Partial<AdditionalConfig>>
): Promise<Source[]> {
const pointerOptionMap = normalizePointers(pointerOrPointers);
const globOptions: any = {};
const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);

options.ignore = asArray(options.ignore || []);
options.ignore.push(...ignore);

applyDefaultOptions<AdditionalConfig>(options);

Expand All @@ -50,7 +51,6 @@ export async function loadTypedefs<AdditionalConfig = Record<string, unknown>>(
parseSource({
partialSource,
options,
globOptions,
pointerOptionMap,
addValidSource(source) {
validSources.push(source);
Expand All @@ -74,8 +74,10 @@ export function loadTypedefsSync<AdditionalConfig = Record<string, unknown>>(
pointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[],
options: LoadTypedefsOptions<Partial<AdditionalConfig>>
): Source[] {
const pointerOptionMap = normalizePointers(pointerOrPointers);
const globOptions: any = {};
const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);

options.ignore = asArray(options.ignore || []);
options.ignore.push(...ignore);

applyDefaultOptions<AdditionalConfig>(options);

Expand All @@ -90,7 +92,6 @@ export function loadTypedefsSync<AdditionalConfig = Record<string, unknown>>(
parseSource({
partialSource,
options,
globOptions,
pointerOptionMap,
addValidSource(source) {
validSources.push(source);
Expand Down
Loading

0 comments on commit af9a78d

Please sign in to comment.