@graphql-tools/external-fragment-loader 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ import type { DocumentNode } from 'graphql';
2
+ import type { Loader, Source } from '@graphql-tools/utils';
3
+ import type { ExternalFragmentLoaderOptions } from './options.js';
4
+ /**
5
+ * Custom-loader entry point for `@graphql-tools/load`.
6
+ *
7
+ * Custom loaders must return a single DocumentNode (or Source). By default,
8
+ * use the synchronous resolver so this entry point works for both
9
+ * `loadTypedefs` and `loadTypedefsSync`. Set `options.async` to use the
10
+ * asynchronous resolver from an asynchronous load call.
11
+ */
12
+ type AsyncExternalFragmentLoaderOptions = ExternalFragmentLoaderOptions & {
13
+ async: true;
14
+ };
15
+ type SyncExternalFragmentLoaderOptions = ExternalFragmentLoaderOptions & {
16
+ async?: false;
17
+ };
18
+ export default function externalFragmentLoader(_pointer: string, options: AsyncExternalFragmentLoaderOptions): Promise<DocumentNode>;
19
+ export default function externalFragmentLoader(_pointer: string, options: SyncExternalFragmentLoaderOptions): DocumentNode;
20
+ export default function externalFragmentLoader(_pointer: string, options: ExternalFragmentLoaderOptions): DocumentNode | Promise<DocumentNode>;
21
+ export declare class ExternalFragmentLoader implements Loader<ExternalFragmentLoaderOptions> {
22
+ load(_pointer: string, options: ExternalFragmentLoaderOptions): Promise<Source[]>;
23
+ loadSync(_pointer: string, options: ExternalFragmentLoaderOptions): Source[];
24
+ }
25
+ export {};
@@ -0,0 +1,100 @@
1
+ import type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
2
+ import type { BaseLoaderOptions } from '@graphql-tools/utils';
3
+ export interface ExternalFragmentLoaderOptions extends BaseLoaderOptions {
4
+ /**
5
+ * Absolute path to the target package directory whose fragments we're resolving.
6
+ * This is the package that has missing fragment spreads referencing other packages.
7
+ */
8
+ packageDir: string;
9
+ /**
10
+ * Directories where dependency packages can be found.
11
+ * Each entry is an absolute path to a directory containing package folders.
12
+ *
13
+ * @example ['/path/to/monorepo/packages', '/path/to/monorepo/libs', '/path/to/node_modules']
14
+ */
15
+ externalPackagesDirs: string[];
16
+ /**
17
+ * Whether the default function export should use the asynchronous resolver.
18
+ * Use this with asynchronous loading APIs such as Codegen or `loadDocuments`.
19
+ * The synchronous loading API cannot consume the Promise returned in async mode.
20
+ * The class loader's `load` and `loadSync` methods select their path explicitly.
21
+ * @default false
22
+ */
23
+ async?: boolean;
24
+ /**
25
+ * Directories within each package to scan for GraphQL fragments.
26
+ * @default ['src']
27
+ */
28
+ scanInternalDirs?: string[];
29
+ /**
30
+ * File extensions to scan for GraphQL fragments (without the dot).
31
+ * @default ['ts', 'tsx', 'js', 'jsx', 'graphql', 'gql']
32
+ */
33
+ extensions?: string[];
34
+ /**
35
+ * Glob patterns to exclude when scanning packages.
36
+ * @default ['**\/__generated__/**', '**\/node_modules/**']
37
+ */
38
+ excludePatterns?: string[];
39
+ /**
40
+ * Optional filter function to decide which dependencies from `package.json`
41
+ * should be considered as potential packages with fragments based on their package name.
42
+ * Return true to include the dependency in the search.
43
+ * @default () => true (all dependencies are considered)
44
+ *
45
+ * @example (name) => name.startsWith('my-org-')
46
+ */
47
+ packageNameFilter?: (packageName: string) => boolean;
48
+ /**
49
+ * Optional filter to decide whether a dependency package should be scanned
50
+ * for GraphQL fragments based on its package.json dependencies.
51
+ * Return true to scan the package.
52
+ *
53
+ * Unlike `packageNameFilter`, packages rejected by this filter are still
54
+ * traversed for their own transitive dependencies — they are just not scanned
55
+ * for fragment definitions.
56
+ *
57
+ * @example (deps) => '@apollo/client' in deps
58
+ */
59
+ packageDependencyFilter?: (dependencies: Record<string, string>) => boolean;
60
+ /**
61
+ * Optional predicate to filter which files should be scanned for fragments.
62
+ * Receives the file content as a string. Return true to include the file.
63
+ * Useful to skip code files that don't use a GraphQL tag or a GraphQL magic comment.
64
+ *
65
+ * @example (content, filePath) =>
66
+ * /\.(graphql|gql)$/.test(filePath) ||
67
+ * /\b(?:gql|graphql)\s*`/.test(content) ||
68
+ * /\/\*\s*graphql\s*\*\//i.test(content)
69
+ */
70
+ fileContentFilter?: (content: string, filePath: string) => boolean;
71
+ /**
72
+ * Whether to include devDependencies when scanning for transitive deps.
73
+ * @default true
74
+ */
75
+ includeDevDependencies?: boolean;
76
+ /**
77
+ * Options for graphql-tag-pluck when extracting GraphQL from code files.
78
+ */
79
+ pluckConfig?: GraphQLTagPluckOptions;
80
+ /**
81
+ * Time-to-live for cache entries in milliseconds.
82
+ * Set this for long-running processes (e.g. watch mode) so stale entries
83
+ * are automatically evicted. External package maps include parsed sources
84
+ * and are shared by resolver calls; a `packageDir` package map is not retained
85
+ * unless that package was already cached as an external dependency. Cache
86
+ * configuration is shared by all resolver calls in this module. Calls with
87
+ * a different value recreate all memoized caches, discard their existing
88
+ * entries, and apply the new value to later calls.
89
+ * @default Infinity (cache forever)
90
+ */
91
+ cacheTTL?: number;
92
+ /**
93
+ * When true, invalidate cached data for the target package specified by `packageDir`
94
+ * before each resolution call, including its fragment map and package.json
95
+ * dependency metadata. Useful in watch mode to refresh the package being
96
+ * edited while reusing dependency caches.
97
+ * @default false
98
+ */
99
+ invalidateTargetPackageCache?: boolean;
100
+ }
@@ -0,0 +1,100 @@
1
+ import type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
2
+ import type { BaseLoaderOptions } from '@graphql-tools/utils';
3
+ export interface ExternalFragmentLoaderOptions extends BaseLoaderOptions {
4
+ /**
5
+ * Absolute path to the target package directory whose fragments we're resolving.
6
+ * This is the package that has missing fragment spreads referencing other packages.
7
+ */
8
+ packageDir: string;
9
+ /**
10
+ * Directories where dependency packages can be found.
11
+ * Each entry is an absolute path to a directory containing package folders.
12
+ *
13
+ * @example ['/path/to/monorepo/packages', '/path/to/monorepo/libs', '/path/to/node_modules']
14
+ */
15
+ externalPackagesDirs: string[];
16
+ /**
17
+ * Whether the default function export should use the asynchronous resolver.
18
+ * Use this with asynchronous loading APIs such as Codegen or `loadDocuments`.
19
+ * The synchronous loading API cannot consume the Promise returned in async mode.
20
+ * The class loader's `load` and `loadSync` methods select their path explicitly.
21
+ * @default false
22
+ */
23
+ async?: boolean;
24
+ /**
25
+ * Directories within each package to scan for GraphQL fragments.
26
+ * @default ['src']
27
+ */
28
+ scanInternalDirs?: string[];
29
+ /**
30
+ * File extensions to scan for GraphQL fragments (without the dot).
31
+ * @default ['ts', 'tsx', 'js', 'jsx', 'graphql', 'gql']
32
+ */
33
+ extensions?: string[];
34
+ /**
35
+ * Glob patterns to exclude when scanning packages.
36
+ * @default ['**\/__generated__/**', '**\/node_modules/**']
37
+ */
38
+ excludePatterns?: string[];
39
+ /**
40
+ * Optional filter function to decide which dependencies from `package.json`
41
+ * should be considered as potential packages with fragments based on their package name.
42
+ * Return true to include the dependency in the search.
43
+ * @default () => true (all dependencies are considered)
44
+ *
45
+ * @example (name) => name.startsWith('my-org-')
46
+ */
47
+ packageNameFilter?: (packageName: string) => boolean;
48
+ /**
49
+ * Optional filter to decide whether a dependency package should be scanned
50
+ * for GraphQL fragments based on its package.json dependencies.
51
+ * Return true to scan the package.
52
+ *
53
+ * Unlike `packageNameFilter`, packages rejected by this filter are still
54
+ * traversed for their own transitive dependencies — they are just not scanned
55
+ * for fragment definitions.
56
+ *
57
+ * @example (deps) => '@apollo/client' in deps
58
+ */
59
+ packageDependencyFilter?: (dependencies: Record<string, string>) => boolean;
60
+ /**
61
+ * Optional predicate to filter which files should be scanned for fragments.
62
+ * Receives the file content as a string. Return true to include the file.
63
+ * Useful to skip code files that don't use a GraphQL tag or a GraphQL magic comment.
64
+ *
65
+ * @example (content, filePath) =>
66
+ * /\.(graphql|gql)$/.test(filePath) ||
67
+ * /\b(?:gql|graphql)\s*`/.test(content) ||
68
+ * /\/\*\s*graphql\s*\*\//i.test(content)
69
+ */
70
+ fileContentFilter?: (content: string, filePath: string) => boolean;
71
+ /**
72
+ * Whether to include devDependencies when scanning for transitive deps.
73
+ * @default true
74
+ */
75
+ includeDevDependencies?: boolean;
76
+ /**
77
+ * Options for graphql-tag-pluck when extracting GraphQL from code files.
78
+ */
79
+ pluckConfig?: GraphQLTagPluckOptions;
80
+ /**
81
+ * Time-to-live for cache entries in milliseconds.
82
+ * Set this for long-running processes (e.g. watch mode) so stale entries
83
+ * are automatically evicted. External package maps include parsed sources
84
+ * and are shared by resolver calls; a `packageDir` package map is not retained
85
+ * unless that package was already cached as an external dependency. Cache
86
+ * configuration is shared by all resolver calls in this module. Calls with
87
+ * a different value recreate all memoized caches, discard their existing
88
+ * entries, and apply the new value to later calls.
89
+ * @default Infinity (cache forever)
90
+ */
91
+ cacheTTL?: number;
92
+ /**
93
+ * When true, invalidate cached data for the target package specified by `packageDir`
94
+ * before each resolution call, including its fragment map and package.json
95
+ * dependency metadata. Useful in watch mode to refresh the package being
96
+ * edited while reusing dependency caches.
97
+ * @default false
98
+ */
99
+ invalidateTargetPackageCache?: boolean;
100
+ }
@@ -0,0 +1,57 @@
1
+ import { type DocumentNode } from 'graphql';
2
+ import { type GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
3
+ interface FragmentInfo {
4
+ name: string;
5
+ typeCondition: string;
6
+ }
7
+ interface ParsedSource {
8
+ rawSDL: string;
9
+ document: DocumentNode;
10
+ }
11
+ export interface PackageFragmentMap {
12
+ fragments: Map<string, {
13
+ filePath: string;
14
+ typeCondition: string;
15
+ }>;
16
+ spreadsPerFile: Map<string, Set<string>>;
17
+ defsPerFile: Map<string, FragmentInfo[]>;
18
+ }
19
+ export interface ResolvedExternalFile {
20
+ filePath: string;
21
+ definitions: FragmentInfo[];
22
+ packageName: string;
23
+ }
24
+ interface ResolvedExternalFileWithSources extends ResolvedExternalFile {
25
+ sources: ParsedSource[];
26
+ }
27
+ export interface ExternalFragmentResolverOptions {
28
+ packageDir: string;
29
+ externalPackagesDirs: string[];
30
+ packageNameFilter?: (packageName: string) => boolean;
31
+ packageDependencyFilter?: (dependencies: Record<string, string>) => boolean;
32
+ includeDevDependencies?: boolean;
33
+ scanInternalDirs?: string[];
34
+ extensions?: string[];
35
+ excludePatterns?: string[];
36
+ pluckConfig?: GraphQLTagPluckOptions;
37
+ fileContentFilter?: (content: string, filePath: string) => boolean;
38
+ cacheTTL?: number;
39
+ invalidateTargetPackageCache?: boolean;
40
+ }
41
+ /**
42
+ * Clears all internal caches.
43
+ */
44
+ export declare function clearCache(): void;
45
+ /**
46
+ * Resolves cross-package GraphQL fragment dependencies across external packages.
47
+ * Async version — reads files in parallel for better performance on large codebases.
48
+ */
49
+ export declare function resolveExternalFragmentsWithSources(options: ExternalFragmentResolverOptions, filterToRequiredFragments?: boolean): Promise<ResolvedExternalFileWithSources[]>;
50
+ export declare function resolveExternalFragments(options: ExternalFragmentResolverOptions): Promise<ResolvedExternalFile[]>;
51
+ /**
52
+ * Resolves cross-package GraphQL fragment dependencies across external packages.
53
+ * Sync version.
54
+ */
55
+ export declare function resolveExternalFragmentsSyncWithSources(options: ExternalFragmentResolverOptions, filterToRequiredFragments?: boolean): ResolvedExternalFileWithSources[];
56
+ export declare function resolveExternalFragmentsSync(options: ExternalFragmentResolverOptions): ResolvedExternalFile[];
57
+ export {};
@@ -0,0 +1,57 @@
1
+ import { type DocumentNode } from 'graphql';
2
+ import { type GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
3
+ interface FragmentInfo {
4
+ name: string;
5
+ typeCondition: string;
6
+ }
7
+ interface ParsedSource {
8
+ rawSDL: string;
9
+ document: DocumentNode;
10
+ }
11
+ export interface PackageFragmentMap {
12
+ fragments: Map<string, {
13
+ filePath: string;
14
+ typeCondition: string;
15
+ }>;
16
+ spreadsPerFile: Map<string, Set<string>>;
17
+ defsPerFile: Map<string, FragmentInfo[]>;
18
+ }
19
+ export interface ResolvedExternalFile {
20
+ filePath: string;
21
+ definitions: FragmentInfo[];
22
+ packageName: string;
23
+ }
24
+ interface ResolvedExternalFileWithSources extends ResolvedExternalFile {
25
+ sources: ParsedSource[];
26
+ }
27
+ export interface ExternalFragmentResolverOptions {
28
+ packageDir: string;
29
+ externalPackagesDirs: string[];
30
+ packageNameFilter?: (packageName: string) => boolean;
31
+ packageDependencyFilter?: (dependencies: Record<string, string>) => boolean;
32
+ includeDevDependencies?: boolean;
33
+ scanInternalDirs?: string[];
34
+ extensions?: string[];
35
+ excludePatterns?: string[];
36
+ pluckConfig?: GraphQLTagPluckOptions;
37
+ fileContentFilter?: (content: string, filePath: string) => boolean;
38
+ cacheTTL?: number;
39
+ invalidateTargetPackageCache?: boolean;
40
+ }
41
+ /**
42
+ * Clears all internal caches.
43
+ */
44
+ export declare function clearCache(): void;
45
+ /**
46
+ * Resolves cross-package GraphQL fragment dependencies across external packages.
47
+ * Async version — reads files in parallel for better performance on large codebases.
48
+ */
49
+ export declare function resolveExternalFragmentsWithSources(options: ExternalFragmentResolverOptions, filterToRequiredFragments?: boolean): Promise<ResolvedExternalFileWithSources[]>;
50
+ export declare function resolveExternalFragments(options: ExternalFragmentResolverOptions): Promise<ResolvedExternalFile[]>;
51
+ /**
52
+ * Resolves cross-package GraphQL fragment dependencies across external packages.
53
+ * Sync version.
54
+ */
55
+ export declare function resolveExternalFragmentsSyncWithSources(options: ExternalFragmentResolverOptions, filterToRequiredFragments?: boolean): ResolvedExternalFileWithSources[];
56
+ export declare function resolveExternalFragmentsSync(options: ExternalFragmentResolverOptions): ResolvedExternalFile[];
57
+ export {};