graphql-query-parser 0.0.1 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/builder/fragmentBuilder.d.ts +27 -0
- package/dist/builder/fragmentBuilder.d.ts.map +1 -0
- package/dist/builder/fragmentBuilder.js +49 -0
- package/dist/builder/fragmentBuilder.js.map +1 -0
- package/dist/builder/graphQLQueryBuilder.d.ts +14 -0
- package/dist/builder/graphQLQueryBuilder.d.ts.map +1 -0
- package/dist/builder/graphQLQueryBuilder.js +22 -0
- package/dist/builder/graphQLQueryBuilder.js.map +1 -0
- package/dist/builder/index.d.ts +3 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +3 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/queryBuilder.d.ts +22 -0
- package/dist/builder/queryBuilder.d.ts.map +1 -0
- package/dist/builder/queryBuilder.js +33 -0
- package/dist/builder/queryBuilder.js.map +1 -0
- package/dist/builder/results.d.ts +28 -0
- package/dist/builder/results.d.ts.map +1 -0
- package/dist/builder/results.js +48 -0
- package/dist/builder/results.js.map +1 -0
- package/dist/cache/cache.d.ts +20 -0
- package/dist/cache/cache.d.ts.map +1 -0
- package/dist/cache/cache.js +48 -0
- package/dist/cache/cache.js.map +1 -0
- package/dist/cache/index.d.ts +5 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/indexCache.d.ts +27 -0
- package/dist/cache/indexCache.d.ts.map +1 -0
- package/dist/cache/indexCache.js +35 -0
- package/dist/cache/indexCache.js.map +1 -0
- package/dist/graphQLQueryParser.d.ts +13 -0
- package/dist/graphQLQueryParser.d.ts.map +1 -0
- package/dist/graphQLQueryParser.js +50 -0
- package/dist/graphQLQueryParser.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/graphql/fragment/fragmentExtractor.d.ts +16 -0
- package/dist/parser/graphql/fragment/fragmentExtractor.d.ts.map +1 -0
- package/dist/parser/graphql/fragment/fragmentExtractor.js +20 -0
- package/dist/parser/graphql/fragment/fragmentExtractor.js.map +1 -0
- package/dist/parser/graphql/fragment/fragmentParser.d.ts +19 -0
- package/dist/parser/graphql/fragment/fragmentParser.d.ts.map +1 -0
- package/{parser → dist/parser}/graphql/fragment/fragmentParser.js +20 -14
- package/dist/parser/graphql/fragment/fragmentParser.js.map +1 -0
- package/dist/parser/graphql/graphQLExtractor.d.ts +12 -0
- package/dist/parser/graphql/graphQLExtractor.d.ts.map +1 -0
- package/dist/parser/graphql/graphQLExtractor.js +2 -0
- package/dist/parser/graphql/graphQLParser.d.ts +12 -0
- package/dist/parser/graphql/graphQLParser.d.ts.map +1 -0
- package/dist/parser/graphql/graphQLParser.js +2 -0
- package/dist/parser/graphql/index.d.ts +5 -0
- package/dist/parser/graphql/index.d.ts.map +1 -0
- package/dist/parser/graphql/index.js +4 -0
- package/dist/parser/graphql/index.js.map +1 -0
- package/dist/parser/graphql/query/queryExtractor.d.ts +15 -0
- package/dist/parser/graphql/query/queryExtractor.d.ts.map +1 -0
- package/dist/parser/graphql/query/queryExtractor.js +19 -0
- package/dist/parser/graphql/query/queryExtractor.js.map +1 -0
- package/dist/parser/graphql/query/queryParser.d.ts +24 -0
- package/dist/parser/graphql/query/queryParser.d.ts.map +1 -0
- package/{parser → dist/parser}/graphql/query/queryParser.js +26 -18
- package/dist/parser/graphql/query/queryParser.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +3 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parseResults.d.ts +9 -0
- package/dist/parser/parseResults.d.ts.map +1 -0
- package/dist/parser/parseResults.js +2 -0
- package/dist/parser/parseResults.js.map +1 -0
- package/dist/parser/parser.d.ts +11 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +2 -0
- package/dist/parser/readStreamParser.d.ts +19 -0
- package/dist/parser/readStreamParser.d.ts.map +1 -0
- package/dist/parser/readStreamParser.js +52 -0
- package/dist/parser/readStreamParser.js.map +1 -0
- package/dist/reader/directory/directoryReader.d.ts +15 -0
- package/dist/reader/directory/directoryReader.d.ts.map +1 -0
- package/dist/reader/directory/directoryReader.js +25 -0
- package/dist/reader/directory/directoryReader.js.map +1 -0
- package/dist/reader/errors/unsupportedTypeError.d.ts +4 -0
- package/dist/reader/errors/unsupportedTypeError.d.ts.map +1 -0
- package/dist/reader/errors/unsupportedTypeError.js +12 -0
- package/dist/reader/errors/unsupportedTypeError.js.map +1 -0
- package/dist/reader/file/fileReader.d.ts +15 -0
- package/dist/reader/file/fileReader.d.ts.map +1 -0
- package/dist/reader/file/fileReader.js +20 -0
- package/dist/reader/file/fileReader.js.map +1 -0
- package/dist/reader/graphQLQueryReader.d.ts +24 -0
- package/dist/reader/graphQLQueryReader.d.ts.map +1 -0
- package/dist/reader/graphQLQueryReader.js +58 -0
- package/dist/reader/graphQLQueryReader.js.map +1 -0
- package/dist/reader/index.d.ts +3 -0
- package/dist/reader/index.d.ts.map +1 -0
- package/dist/reader/index.js +3 -0
- package/dist/reader/index.js.map +1 -0
- package/dist/reader/readFile.d.ts +14 -0
- package/dist/reader/readFile.d.ts.map +1 -0
- package/dist/reader/readFile.js +29 -0
- package/dist/reader/readFile.js.map +1 -0
- package/dist/reader/reader.d.ts +12 -0
- package/dist/reader/reader.d.ts.map +1 -0
- package/dist/reader/reader.js +2 -0
- package/dist/templates/fragmentTemplate.d.ts +11 -0
- package/dist/templates/fragmentTemplate.d.ts.map +1 -0
- package/{templates → dist/templates}/fragmentTemplate.js +6 -4
- package/dist/templates/fragmentTemplate.js.map +1 -0
- package/dist/templates/index.d.ts +4 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/queryTemplate.d.ts +12 -0
- package/dist/templates/queryTemplate.d.ts.map +1 -0
- package/{templates → dist/templates}/queryTemplate.js +9 -5
- package/dist/templates/queryTemplate.js.map +1 -0
- package/package.json +61 -38
- package/builder/fragmentBuilder.js +0 -32
- package/builder/fragmentBuilder.js.map +0 -1
- package/builder/graphQLQueryBuilder.js +0 -15
- package/builder/graphQLQueryBuilder.js.map +0 -1
- package/builder/index.js +0 -5
- package/builder/index.js.map +0 -1
- package/builder/queryBuilder.js +0 -18
- package/builder/queryBuilder.js.map +0 -1
- package/builder/results.js +0 -30
- package/builder/results.js.map +0 -1
- package/cache/cache.js +0 -30
- package/cache/cache.js.map +0 -1
- package/cache/index.js +0 -7
- package/cache/index.js.map +0 -1
- package/cache/indexCache.js +0 -18
- package/cache/indexCache.js.map +0 -1
- package/graphQLQueryParser.js +0 -39
- package/graphQLQueryParser.js.map +0 -1
- package/index.js +0 -5
- package/index.js.map +0 -1
- package/parser/graphql/fragment/fragmentExtractor.js +0 -13
- package/parser/graphql/fragment/fragmentExtractor.js.map +0 -1
- package/parser/graphql/fragment/fragmentParser.js.map +0 -1
- package/parser/graphql/graphQLExtractor.js +0 -3
- package/parser/graphql/graphQLParser.js +0 -3
- package/parser/graphql/index.js +0 -7
- package/parser/graphql/index.js.map +0 -1
- package/parser/graphql/query/queryExtractor.js +0 -13
- package/parser/graphql/query/queryExtractor.js.map +0 -1
- package/parser/graphql/query/queryParser.js.map +0 -1
- package/parser/index.js +0 -5
- package/parser/index.js.map +0 -1
- package/parser/parseResults.js +0 -3
- package/parser/parseResults.js.map +0 -1
- package/parser/parser.js +0 -3
- package/parser/readStreamParser.js +0 -53
- package/parser/readStreamParser.js.map +0 -1
- package/reader/directory/directoryReader.js +0 -21
- package/reader/directory/directoryReader.js.map +0 -1
- package/reader/errors/unsupportedTypeError.js +0 -15
- package/reader/errors/unsupportedTypeError.js.map +0 -1
- package/reader/file/fileReader.js +0 -16
- package/reader/file/fileReader.js.map +0 -1
- package/reader/graphQLQueryReader.js +0 -40
- package/reader/graphQLQueryReader.js.map +0 -1
- package/reader/index.js +0 -5
- package/reader/index.js.map +0 -1
- package/reader/readFile.js +0 -16
- package/reader/readFile.js.map +0 -1
- package/reader/reader.js +0 -3
- package/templates/fragmentTemplate.js.map +0 -1
- package/templates/index.js +0 -7
- package/templates/index.js.map +0 -1
- package/templates/queryTemplate.js.map +0 -1
- /package/{parser → dist/parser}/graphql/graphQLExtractor.js.map +0 -0
- /package/{parser → dist/parser}/graphql/graphQLParser.js.map +0 -0
- /package/{parser → dist/parser}/parser.js.map +0 -0
- /package/{reader → dist/reader}/reader.js.map +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Michael Sleevi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
GraphQL Query Parser
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
Simple utility for extracting GraphQL queries from multiple files
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://github.com/iveelsm/graphql-query-parser/actions/workflows/build.yml">
|
|
11
|
+
<img src="https://github.com/iveelsm/graphql-query-parser/actions/workflows/build.yml/badge.svg" alt="Build Status">
|
|
12
|
+
</a>
|
|
13
|
+
| <a href="https://codecov.io/gh/iveelsm/graphql-query-parser">
|
|
14
|
+
<img src="https://codecov.io/gh/iveelsm/graphql-query-parser/graph/badge.svg" alt="Coverage">
|
|
15
|
+
</a>
|
|
16
|
+
| <a href="https://www.npmjs.com/package/graphql-query-parser">
|
|
17
|
+
<img src="https://badge.fury.io/js/graphql-query-parser.svg" alt="NPM Version">
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install with npm globally:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
$ npm install --global graphql-query-parser
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or as a dependency for your project:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
$ npm install graphql-query-parser
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Links
|
|
36
|
+
|
|
37
|
+
- [Examples](./docs/EXAMPLES.md)
|
|
38
|
+
- [Contributing](./docs/CONTRIBUTING.md)
|
|
39
|
+
- [Changelog](./docs/CHANGELOG.md)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Cache } from "../cache/index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The Fragment Builder will:
|
|
4
|
+
* * Build a given fragment
|
|
5
|
+
* * Identify nested fragments
|
|
6
|
+
* * Ignores implicit fragments
|
|
7
|
+
*/
|
|
8
|
+
export default class FragmentBuilder {
|
|
9
|
+
private static fragmentRegex;
|
|
10
|
+
/**
|
|
11
|
+
* Builds the fragment result set
|
|
12
|
+
*
|
|
13
|
+
* @param query Query string to build fragments for
|
|
14
|
+
* @param cache Cache containing the fragments
|
|
15
|
+
*/
|
|
16
|
+
static build(query: string, cache: Cache): FragmentResults[];
|
|
17
|
+
private static parseFragment;
|
|
18
|
+
private static addFragments;
|
|
19
|
+
private static generateFragmentString;
|
|
20
|
+
private static getFragmentName;
|
|
21
|
+
}
|
|
22
|
+
interface FragmentResults {
|
|
23
|
+
name: string;
|
|
24
|
+
fragment: string;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=fragmentBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragmentBuilder.d.ts","sourceRoot":"","sources":["../../lib/builder/fragmentBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IACnC,OAAO,CAAC,MAAM,CAAC,aAAa,CAA8C;IAE1E;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,eAAe,EAAE;IAInE,OAAO,CAAC,MAAM,CAAC,aAAa;IAW5B,OAAO,CAAC,MAAM,CAAC,YAAY;IAkB3B,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAWrC,OAAO,CAAC,MAAM,CAAC,eAAe;CAS9B;AAED,UAAU,eAAe;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Fragment Builder will:
|
|
3
|
+
* * Build a given fragment
|
|
4
|
+
* * Identify nested fragments
|
|
5
|
+
* * Ignores implicit fragments
|
|
6
|
+
*/
|
|
7
|
+
export default class FragmentBuilder {
|
|
8
|
+
static fragmentRegex = /(.*[.]{3,}\s{0,})([^on\s{1,}][a-zA-Z]+)/g;
|
|
9
|
+
/**
|
|
10
|
+
* Builds the fragment result set
|
|
11
|
+
*
|
|
12
|
+
* @param query Query string to build fragments for
|
|
13
|
+
* @param cache Cache containing the fragments
|
|
14
|
+
*/
|
|
15
|
+
static build(query, cache) {
|
|
16
|
+
return this.addFragments(query, [], cache);
|
|
17
|
+
}
|
|
18
|
+
static parseFragment(results, fragmentName, cache) {
|
|
19
|
+
const fragment = this.generateFragmentString(fragmentName, cache);
|
|
20
|
+
results.push({ name: fragmentName, fragment: fragment });
|
|
21
|
+
results = this.addFragments(fragment, results, cache);
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
static addFragments(toMatch, results, cache) {
|
|
25
|
+
const fragmentIdentifiers = toMatch.match(this.fragmentRegex);
|
|
26
|
+
if (fragmentIdentifiers) {
|
|
27
|
+
fragmentIdentifiers.forEach((fragmentIdentifier) => {
|
|
28
|
+
const fragmentName = this.getFragmentName(fragmentIdentifier);
|
|
29
|
+
results.concat(this.parseFragment(results, fragmentName, cache));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
}
|
|
34
|
+
static generateFragmentString(fragmentName, cache) {
|
|
35
|
+
const fragment = cache.fragmentCache.get(fragmentName);
|
|
36
|
+
if (!fragment) {
|
|
37
|
+
throw new Error(`Fragment not found in cache: ${fragmentName}`);
|
|
38
|
+
}
|
|
39
|
+
return fragment.apply();
|
|
40
|
+
}
|
|
41
|
+
static getFragmentName(fragmentIdentifier) {
|
|
42
|
+
const match = this.fragmentRegex.exec(fragmentIdentifier);
|
|
43
|
+
if (!match) {
|
|
44
|
+
throw new Error(`Invalid fragment identifier: ${fragmentIdentifier}`);
|
|
45
|
+
}
|
|
46
|
+
return match[2];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=fragmentBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragmentBuilder.js","sourceRoot":"","sources":["../../lib/builder/fragmentBuilder.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAC3B,MAAM,CAAC,aAAa,GAAG,0CAA0C,CAAC;IAE1E;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,KAAY;QAC9C,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEO,MAAM,CAAC,aAAa,CAC3B,OAA0B,EAC1B,YAAoB,EACpB,KAAY;QAEZ,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QACzD,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,YAAY,CAC1B,OAAe,EACf,OAA0B,EAC1B,KAAY;QAEZ,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAE9D,IAAI,mBAAmB,EAAE,CAAC;YACzB,mBAAmB,CAAC,OAAO,CAAC,CAAC,kBAAkB,EAAE,EAAE;gBAClD,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;gBAC9D,OAAO,CAAC,MAAM,CACb,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CAChD,CAAC;YACH,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,MAAM,CAAC,sBAAsB,CACpC,YAAoB,EACpB,KAAY;QAEZ,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,gCAAgC,YAAY,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,kBAA0B;QACxD,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACd,gCAAgC,kBAAkB,EAAE,CACpD,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Cache } from "../cache/index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* This QueryBuilder is the interface for this package, it will be responsible for extracting all the queries possible.
|
|
4
|
+
*/
|
|
5
|
+
export default class GraphQLQueryBuilder {
|
|
6
|
+
/**
|
|
7
|
+
* Builds each query string based on what is present in the cache
|
|
8
|
+
*
|
|
9
|
+
* @param cache Cache of queries and fragments
|
|
10
|
+
* @param variables Variables to apply to queries
|
|
11
|
+
*/
|
|
12
|
+
static build(cache: Cache, variables: Record<string, any>): string[];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=graphQLQueryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphQLQueryBuilder.d.ts","sourceRoot":"","sources":["../../lib/builder/graphQLQueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK/C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACvC;;;;;OAKG;WACW,KAAK,CAClB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,EAAE;CAQX"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import QueryBuilder from "./queryBuilder.js";
|
|
2
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */
|
|
3
|
+
/**
|
|
4
|
+
* This QueryBuilder is the interface for this package, it will be responsible for extracting all the queries possible.
|
|
5
|
+
*/
|
|
6
|
+
export default class GraphQLQueryBuilder {
|
|
7
|
+
/**
|
|
8
|
+
* Builds each query string based on what is present in the cache
|
|
9
|
+
*
|
|
10
|
+
* @param cache Cache of queries and fragments
|
|
11
|
+
* @param variables Variables to apply to queries
|
|
12
|
+
*/
|
|
13
|
+
static build(cache, variables) {
|
|
14
|
+
const queries = [];
|
|
15
|
+
const entries = cache.queryCache.cache.entries();
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
queries.push(QueryBuilder.build(entry[1], cache, variables));
|
|
18
|
+
}
|
|
19
|
+
return queries;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=graphQLQueryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphQLQueryBuilder.js","sourceRoot":"","sources":["../../lib/builder/graphQLQueryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,kDAAkD;AAElD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACvC;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAClB,KAAY,EACZ,SAA8B;QAE9B,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,mBAAmB,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,mBAAmB,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Cache } from "../cache/index.ts";
|
|
2
|
+
import { QueryTemplate } from "../templates/index.ts";
|
|
3
|
+
/**
|
|
4
|
+
* QueryBuilder is responsible for building a given query from a template definition.
|
|
5
|
+
* The builder will:
|
|
6
|
+
* * Apply variables
|
|
7
|
+
* * Identify fragments
|
|
8
|
+
* * Add fragments to the results
|
|
9
|
+
*/
|
|
10
|
+
export default class QueryBuilder {
|
|
11
|
+
/**
|
|
12
|
+
* Builds a query from a template by doing the following:
|
|
13
|
+
* * Apply Variables from Configuration if necessary
|
|
14
|
+
* * Identifies fragments to add to the query and adds them if necessary
|
|
15
|
+
*
|
|
16
|
+
* @param query Query to build from
|
|
17
|
+
* @param cache Cache of information with fragments and queries
|
|
18
|
+
* @param variables Configured variable information that might yield a partial apply to the query
|
|
19
|
+
*/
|
|
20
|
+
static build(query: QueryTemplate, cache: Cache, variables: Record<string, any>): string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=queryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryBuilder.d.ts","sourceRoot":"","sources":["../../lib/builder/queryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAMtD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAChC;;;;;;;;OAQG;WACW,KAAK,CAClB,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM;CAUT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QueryTemplate } from "../templates/index.js";
|
|
2
|
+
import FragmentBuilder from "./fragmentBuilder.js";
|
|
3
|
+
import Results from "./results.js";
|
|
4
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */
|
|
5
|
+
/**
|
|
6
|
+
* QueryBuilder is responsible for building a given query from a template definition.
|
|
7
|
+
* The builder will:
|
|
8
|
+
* * Apply variables
|
|
9
|
+
* * Identify fragments
|
|
10
|
+
* * Add fragments to the results
|
|
11
|
+
*/
|
|
12
|
+
export default class QueryBuilder {
|
|
13
|
+
/**
|
|
14
|
+
* Builds a query from a template by doing the following:
|
|
15
|
+
* * Apply Variables from Configuration if necessary
|
|
16
|
+
* * Identifies fragments to add to the query and adds them if necessary
|
|
17
|
+
*
|
|
18
|
+
* @param query Query to build from
|
|
19
|
+
* @param cache Cache of information with fragments and queries
|
|
20
|
+
* @param variables Configured variable information that might yield a partial apply to the query
|
|
21
|
+
*/
|
|
22
|
+
static build(query, cache, variables) {
|
|
23
|
+
const results = new Results();
|
|
24
|
+
const queryString = query.apply(variables);
|
|
25
|
+
results.addQuery(query.cache(), queryString);
|
|
26
|
+
const builtFragments = FragmentBuilder.build(queryString, cache);
|
|
27
|
+
builtFragments.forEach((fragment) => {
|
|
28
|
+
results.addFragment(fragment.name, fragment.fragment);
|
|
29
|
+
});
|
|
30
|
+
return results.build();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=queryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryBuilder.js","sourceRoot":"","sources":["../../lib/builder/queryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,kDAAkD;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAChC;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CAClB,KAAoB,EACpB,KAAY,EACZ,SAA8B;QAE9B,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,eAAe,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACjE,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Results are a builder patter on top of a string result.
|
|
3
|
+
* The Results also identify which fragments are present so we don't duplicate
|
|
4
|
+
*/
|
|
5
|
+
export default class Results {
|
|
6
|
+
private result;
|
|
7
|
+
private currentTemplates;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Adds a query to the result string
|
|
11
|
+
*
|
|
12
|
+
* @param identifier Unique identifier for the set
|
|
13
|
+
* @param query Query string to add
|
|
14
|
+
*/
|
|
15
|
+
addQuery(identifier: string, query: string): Results;
|
|
16
|
+
/**
|
|
17
|
+
* Adds a fragment to the result string
|
|
18
|
+
*
|
|
19
|
+
* @param identifier Unique identifier for the set
|
|
20
|
+
* @param fragment Fragment string to add
|
|
21
|
+
*/
|
|
22
|
+
addFragment(identifier: string, fragment: string): Results;
|
|
23
|
+
/**
|
|
24
|
+
* Builds the result string for usage by a GraphQL client
|
|
25
|
+
*/
|
|
26
|
+
build(): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../lib/builder/results.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,gBAAgB,CAAmB;;IAU3C;;;;;OAKG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAQ3D;;;;;OAKG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQjE;;OAEG;IACI,KAAK,IAAI,MAAM;CAGtB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Results are a builder patter on top of a string result.
|
|
3
|
+
* The Results also identify which fragments are present so we don't duplicate
|
|
4
|
+
*/
|
|
5
|
+
export default class Results {
|
|
6
|
+
result;
|
|
7
|
+
currentTemplates;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.result = "";
|
|
10
|
+
this.currentTemplates = {
|
|
11
|
+
query: new Set(),
|
|
12
|
+
fragment: new Set(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds a query to the result string
|
|
17
|
+
*
|
|
18
|
+
* @param identifier Unique identifier for the set
|
|
19
|
+
* @param query Query string to add
|
|
20
|
+
*/
|
|
21
|
+
addQuery(identifier, query) {
|
|
22
|
+
if (!this.currentTemplates.query.has(identifier)) {
|
|
23
|
+
this.currentTemplates.query.add(identifier);
|
|
24
|
+
this.result += query += "\n\n";
|
|
25
|
+
}
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adds a fragment to the result string
|
|
30
|
+
*
|
|
31
|
+
* @param identifier Unique identifier for the set
|
|
32
|
+
* @param fragment Fragment string to add
|
|
33
|
+
*/
|
|
34
|
+
addFragment(identifier, fragment) {
|
|
35
|
+
if (!this.currentTemplates.fragment.has(identifier)) {
|
|
36
|
+
this.currentTemplates.fragment.add(identifier);
|
|
37
|
+
this.result += fragment += "\n\n";
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Builds the result string for usage by a GraphQL client
|
|
43
|
+
*/
|
|
44
|
+
build() {
|
|
45
|
+
return this.result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../lib/builder/results.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IACnB,MAAM,CAAS;IACf,gBAAgB,CAAmB;IAE3C;QACC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,gBAAgB,GAAG;YACvB,KAAK,EAAE,IAAI,GAAG,EAAE;YAChB,QAAQ,EAAE,IAAI,GAAG,EAAE;SACnB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,QAAQ,CAAC,UAAkB,EAAE,KAAa;QAChD,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC5C,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAC,UAAkB,EAAE,QAAgB;QACtD,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC/C,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACI,KAAK;QACX,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QueryTemplate, FragmentTemplate } from "../templates/index.ts";
|
|
2
|
+
import IndexCache from "./indexCache.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Cache is a container for all queries and framgnet chunks
|
|
5
|
+
*/
|
|
6
|
+
interface Cache {
|
|
7
|
+
queryCache: IndexCache<string, QueryTemplate>;
|
|
8
|
+
fragmentCache: IndexCache<string, FragmentTemplate>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds a cache by caching all the fragments and queries passed in
|
|
12
|
+
*
|
|
13
|
+
* @param fragments Fragments to build into the cache
|
|
14
|
+
* @param queries Queries to build into the cache
|
|
15
|
+
* @returns Cache will all the queries and fragments required
|
|
16
|
+
*/
|
|
17
|
+
declare function buildCache(fragments: FragmentTemplate[], queries: QueryTemplate[]): Cache;
|
|
18
|
+
export { buildCache };
|
|
19
|
+
export type { Cache };
|
|
20
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../lib/cache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC;;GAEG;AACH,UAAU,KAAK;IACd,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC9C,aAAa,EAAE,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CACpD;AAgCD;;;;;;GAMG;AACH,iBAAS,UAAU,CAClB,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,EAAE,aAAa,EAAE,GACtB,KAAK,CAQP;AAED,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,YAAY,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { QueryTemplate, FragmentTemplate } from "../templates/index.js";
|
|
2
|
+
import IndexCache from "./indexCache.js";
|
|
3
|
+
/**
|
|
4
|
+
* This will loop through a list of [[QueryTemplate]]s and cache the query for usage later on
|
|
5
|
+
*
|
|
6
|
+
* @param cache Cache will be pushing the values into
|
|
7
|
+
* @param queries Queries to cache
|
|
8
|
+
*/
|
|
9
|
+
function cacheQueries(cache, queries) {
|
|
10
|
+
queries.forEach((query) => {
|
|
11
|
+
if (query.cache() === null) {
|
|
12
|
+
throw new Error("Cache Key can not be Null");
|
|
13
|
+
}
|
|
14
|
+
cache.queryCache.put(query.cache(), query);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This will loop through a list of [[FragmentTemplate]]s and cache them for usage later on
|
|
19
|
+
*
|
|
20
|
+
* @param cache Cache will be pushing the values into
|
|
21
|
+
* @param fragments Fragments to cache
|
|
22
|
+
*/
|
|
23
|
+
function cacheFragments(cache, fragments) {
|
|
24
|
+
fragments.forEach((fragment) => {
|
|
25
|
+
if (fragment.cache() === null) {
|
|
26
|
+
throw new Error("Cache Key can not be Null");
|
|
27
|
+
}
|
|
28
|
+
cache.fragmentCache.put(fragment.cache(), fragment);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Builds a cache by caching all the fragments and queries passed in
|
|
33
|
+
*
|
|
34
|
+
* @param fragments Fragments to build into the cache
|
|
35
|
+
* @param queries Queries to build into the cache
|
|
36
|
+
* @returns Cache will all the queries and fragments required
|
|
37
|
+
*/
|
|
38
|
+
function buildCache(fragments, queries) {
|
|
39
|
+
const cache = {
|
|
40
|
+
queryCache: new IndexCache(),
|
|
41
|
+
fragmentCache: new IndexCache(),
|
|
42
|
+
};
|
|
43
|
+
cacheQueries(cache, queries);
|
|
44
|
+
cacheFragments(cache, fragments);
|
|
45
|
+
return cache;
|
|
46
|
+
}
|
|
47
|
+
export { buildCache };
|
|
48
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../lib/cache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAUzC;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAY,EAAE,OAAwB;IAC3D,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACzB,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAY,EAAE,SAA6B;IAClE,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC9B,IAAI,QAAQ,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,UAAU,CAClB,SAA6B,EAC7B,OAAwB;IAExB,MAAM,KAAK,GAAG;QACb,UAAU,EAAE,IAAI,UAAU,EAAyB;QACnD,aAAa,EAAE,IAAI,UAAU,EAA4B;KACzD,CAAC;IACF,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7B,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC;AACd,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AAClC,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexCache is an abstraction over caching mechanisms
|
|
3
|
+
*/
|
|
4
|
+
export default class IndexCache<K, V> {
|
|
5
|
+
cache: Map<K, V>;
|
|
6
|
+
constructor();
|
|
7
|
+
/**
|
|
8
|
+
* Puts a key value pair in the cache
|
|
9
|
+
*
|
|
10
|
+
* @param key Reference for the value
|
|
11
|
+
* @param value Value to store
|
|
12
|
+
*/
|
|
13
|
+
put(key: K, value: V): void;
|
|
14
|
+
/**
|
|
15
|
+
* Gets a value for a given key in the cache
|
|
16
|
+
*
|
|
17
|
+
* @param key Reference to the value
|
|
18
|
+
*/
|
|
19
|
+
get(key: K): V | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Removes a key value pair from the cache
|
|
22
|
+
*
|
|
23
|
+
* @param key Reference to the value
|
|
24
|
+
*/
|
|
25
|
+
remove(key: K): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=indexCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexCache.d.ts","sourceRoot":"","sources":["../../lib/cache/indexCache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;IAMxB;;;;;OAKG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAIlC;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAIjC;;;;OAIG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;CAG9B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexCache is an abstraction over caching mechanisms
|
|
3
|
+
*/
|
|
4
|
+
export default class IndexCache {
|
|
5
|
+
cache;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.cache = new Map();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Puts a key value pair in the cache
|
|
11
|
+
*
|
|
12
|
+
* @param key Reference for the value
|
|
13
|
+
* @param value Value to store
|
|
14
|
+
*/
|
|
15
|
+
put(key, value) {
|
|
16
|
+
this.cache.set(key, value);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Gets a value for a given key in the cache
|
|
20
|
+
*
|
|
21
|
+
* @param key Reference to the value
|
|
22
|
+
*/
|
|
23
|
+
get(key) {
|
|
24
|
+
return this.cache.get(key);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Removes a key value pair from the cache
|
|
28
|
+
*
|
|
29
|
+
* @param key Reference to the value
|
|
30
|
+
*/
|
|
31
|
+
remove(key) {
|
|
32
|
+
return this.cache.delete(key);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=indexCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexCache.js","sourceRoot":"","sources":["../../lib/cache/indexCache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IACvB,KAAK,CAAY;IAExB;QACC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAQ,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,GAAM,EAAE,KAAQ;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAM;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,GAAM;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Path = string | string[];
|
|
2
|
+
type Variables = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Parses all the information from the paths provided.
|
|
5
|
+
* This method will parse data in the form of fragments and queries.
|
|
6
|
+
* Then cache the data in order to construct many results for use by GraphQL clients
|
|
7
|
+
*
|
|
8
|
+
* @param paths Paths to parse information from
|
|
9
|
+
* @param variables Variables to apply to the queries
|
|
10
|
+
*/
|
|
11
|
+
declare function parse(paths: Path, variables?: Variables): Promise<string[]>;
|
|
12
|
+
export default parse;
|
|
13
|
+
//# sourceMappingURL=graphQLQueryParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphQLQueryParser.d.ts","sourceRoot":"","sources":["../lib/graphQLQueryParser.ts"],"names":[],"mappings":"AAQA,KAAK,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAC9B,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAMzC;;;;;;;GAOG;AACH,iBAAe,KAAK,CACnB,KAAK,EAAE,IAAI,EACX,SAAS,GAAE,SAAc,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC,CAanB;AA2BD,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReadStream } from "fs";
|
|
2
|
+
import GraphQLQueryBuilder from "./builder/index.js";
|
|
3
|
+
import { buildCache } from "./cache/index.js";
|
|
4
|
+
import { ReadStreamParser } from "./parser/index.js";
|
|
5
|
+
import GraphQLQueryReader from "./reader/index.js";
|
|
6
|
+
function isString(x) {
|
|
7
|
+
return typeof x === "string";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses all the information from the paths provided.
|
|
11
|
+
* This method will parse data in the form of fragments and queries.
|
|
12
|
+
* Then cache the data in order to construct many results for use by GraphQL clients
|
|
13
|
+
*
|
|
14
|
+
* @param paths Paths to parse information from
|
|
15
|
+
* @param variables Variables to apply to the queries
|
|
16
|
+
*/
|
|
17
|
+
async function parse(paths, variables = {}) {
|
|
18
|
+
const streams = read(paths, new GraphQLQueryReader());
|
|
19
|
+
const results = await Promise.all(parseStreams(streams, new ReadStreamParser()));
|
|
20
|
+
const fragments = results
|
|
21
|
+
.map((x) => x.fragmentResults)
|
|
22
|
+
.reduce((acc, x) => acc.concat(...x), []);
|
|
23
|
+
const queries = results
|
|
24
|
+
.map((x) => x.queryResults)
|
|
25
|
+
.reduce((acc, x) => acc.concat(...x), []);
|
|
26
|
+
const cache = buildCache(fragments, queries);
|
|
27
|
+
return GraphQLQueryBuilder.build(cache, variables);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads the information from the the path
|
|
31
|
+
*
|
|
32
|
+
* @param paths Single path or many paths
|
|
33
|
+
* @param reader Reads the results from the path information provided
|
|
34
|
+
*/
|
|
35
|
+
function read(paths, reader) {
|
|
36
|
+
return isString(paths)
|
|
37
|
+
? reader.read(paths)
|
|
38
|
+
: reader.readMany(paths);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parses all the read stream information to return template data
|
|
42
|
+
*
|
|
43
|
+
* @param streams Streams to parse from
|
|
44
|
+
* @param parser Parser to use when finding data from the streams
|
|
45
|
+
*/
|
|
46
|
+
function parseStreams(streams, parser) {
|
|
47
|
+
return parser.parse(streams);
|
|
48
|
+
}
|
|
49
|
+
export default parse;
|
|
50
|
+
//# sourceMappingURL=graphQLQueryParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphQLQueryParser.js","sourceRoot":"","sources":["../lib/graphQLQueryParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,OAAO,mBAAmB,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,kBAAkB,MAAM,mBAAmB,CAAC;AAKnD,SAAS,QAAQ,CAAC,CAAO;IACxB,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,KAAK,CACnB,KAAW,EACX,YAAuB,EAAE;IAEzB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,kBAAkB,EAAE,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,YAAY,CAAC,OAAO,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAC7C,CAAC;IACF,MAAM,SAAS,GAAG,OAAO;SACvB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;SAC7B,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,OAAO;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;SAC1B,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,SAAS,IAAI,CAAC,KAAW,EAAE,MAA0B;IACpD,OAAO,QAAQ,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC;QAC9B,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAiB,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CACpB,OAAqB,EACrB,MAAwB;IAExB,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,eAAe,KAAK,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAE5C,eAAe,KAAK,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAE5C,eAAe,KAAK,CAAC"}
|