graphql-tag 2.11.0 → 2.12.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/.github/dependabot.yml +9 -0
- package/.github/workflows/node.js.yml +29 -0
- package/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/lib/graphql-tag.umd.js +121 -179
- package/lib/graphql-tag.umd.js.map +1 -1
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +116 -0
- package/lib/index.js.map +1 -0
- package/lib/tests.cjs.js +383 -0
- package/lib/tests.cjs.js.map +1 -0
- package/lib/tests.d.ts +2 -0
- package/lib/tests.d.ts.map +1 -0
- package/lib/tests.js +267 -0
- package/lib/tests.js.map +1 -0
- package/loader.js +1 -1
- package/main.js +3 -0
- package/package.json +26 -15
- package/src/index.ts +160 -0
- package/{test/graphql.js → src/tests.ts} +46 -41
- package/tsconfig.json +21 -0
- package/index.d.ts +0 -20
- package/src/index.js +0 -180
- package/test/mocha.opts +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Please see the documentation for all configuration options:
|
|
2
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
3
|
+
|
|
4
|
+
version: 2
|
|
5
|
+
updates:
|
|
6
|
+
- package-ecosystem: "npm"
|
|
7
|
+
directory: "/" # Location of package manifests
|
|
8
|
+
schedule:
|
|
9
|
+
interval: "daily"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ main ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ main ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
node-version: [10.x, 12.x, 14.x, 15.x]
|
|
19
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v2
|
|
23
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
+
uses: actions/setup-node@v1
|
|
25
|
+
with:
|
|
26
|
+
node-version: ${{ matrix.node-version }}
|
|
27
|
+
- run: npm ci
|
|
28
|
+
- run: npm run build --if-present
|
|
29
|
+
- run: npm test
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Change log
|
|
2
2
|
|
|
3
|
+
### v2.12.0
|
|
4
|
+
|
|
5
|
+
* The `graphql-tag` repository has been converted to TypeScript, adding type safety and enabling both ECMAScript and CommonJS module exports. While these changes are intended to be as backwards-compatible as possible, we decided to bump the minor version to reflect the significant refactoring. <br/>
|
|
6
|
+
[@PowerKiKi](http://github.com/PowerKiKi) and [@benjamn](http://github.com/benjamn) in [#325](https://github.com/apollographql/graphql-tag/pull/325)
|
|
7
|
+
|
|
3
8
|
### v2.11.0 (2020-07-28)
|
|
4
9
|
|
|
5
10
|
* `package.json` `sideEffects` changes to clearly identify that `graphql-tag` doesn't have side effects. <br/>
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Helpful utilities for parsing GraphQL queries. Includes:
|
|
|
8
8
|
- `gql` A JavaScript template literal tag that parses GraphQL query strings into the standard GraphQL AST.
|
|
9
9
|
- `/loader` A webpack loader to preprocess queries
|
|
10
10
|
|
|
11
|
-
`graphql-tag` uses [the reference `graphql` library](https://github.com/graphql/graphql-js) under the hood as a peer dependency, so in addition to installing this module, you'll also have to install `graphql
|
|
11
|
+
`graphql-tag` uses [the reference `graphql` library](https://github.com/graphql/graphql-js) under the hood as a peer dependency, so in addition to installing this module, you'll also have to install `graphql`.
|
|
12
12
|
|
|
13
13
|
### gql
|
|
14
14
|
|
package/lib/graphql-tag.umd.js
CHANGED
|
@@ -1,189 +1,131 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('graphql')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'graphql'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['graphql-tag'] = {}, global.tslib, global.graphql));
|
|
5
|
+
}(this, (function (exports, tslib, graphql) { 'use strict';
|
|
6
|
+
|
|
7
|
+
var docCache = new Map();
|
|
8
|
+
var fragmentSourceMap = new Map();
|
|
9
|
+
var printFragmentWarnings = true;
|
|
10
|
+
var experimentalFragmentVariables = false;
|
|
11
|
+
function normalize(string) {
|
|
12
|
+
return string.replace(/[\s,]+/g, ' ').trim();
|
|
13
|
+
}
|
|
14
|
+
function cacheKeyFromLoc(loc) {
|
|
15
|
+
return normalize(loc.source.body.substring(loc.start, loc.end));
|
|
16
|
+
}
|
|
17
|
+
function processFragments(ast) {
|
|
18
|
+
var seenKeys = new Set();
|
|
19
|
+
var definitions = [];
|
|
20
|
+
ast.definitions.forEach(function (fragmentDefinition) {
|
|
21
|
+
if (fragmentDefinition.kind === 'FragmentDefinition') {
|
|
22
|
+
var fragmentName = fragmentDefinition.name.value;
|
|
23
|
+
var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);
|
|
24
|
+
var sourceKeySet = fragmentSourceMap.get(fragmentName);
|
|
25
|
+
if (sourceKeySet && !sourceKeySet.has(sourceKey)) {
|
|
26
|
+
if (printFragmentWarnings) {
|
|
27
|
+
console.warn("Warning: fragment with name " + fragmentName + " already exists.\n"
|
|
28
|
+
+ "graphql-tag enforces all fragment names across your application to be unique; read more about\n"
|
|
29
|
+
+ "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (!sourceKeySet) {
|
|
33
|
+
fragmentSourceMap.set(fragmentName, sourceKeySet = new Set);
|
|
34
|
+
}
|
|
35
|
+
sourceKeySet.add(sourceKey);
|
|
36
|
+
if (!seenKeys.has(sourceKey)) {
|
|
37
|
+
seenKeys.add(sourceKey);
|
|
38
|
+
definitions.push(fragmentDefinition);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
definitions.push(fragmentDefinition);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return tslib.__assign(tslib.__assign({}, ast), { definitions: definitions });
|
|
46
|
+
}
|
|
47
|
+
function stripLoc(doc) {
|
|
48
|
+
var workSet = new Set(doc.definitions);
|
|
49
|
+
workSet.forEach(function (node) {
|
|
50
|
+
if (node.loc)
|
|
51
|
+
delete node.loc;
|
|
52
|
+
Object.keys(node).forEach(function (key) {
|
|
53
|
+
var value = node[key];
|
|
54
|
+
if (value && typeof value === 'object') {
|
|
55
|
+
workSet.add(value);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
var loc = doc.loc;
|
|
60
|
+
if (loc) {
|
|
61
|
+
delete loc.startToken;
|
|
62
|
+
delete loc.endToken;
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
fragmentSourceMap[fragmentName][sourceKey] = true;
|
|
60
|
-
|
|
61
|
-
} else if (!fragmentSourceMap.hasOwnProperty(fragmentName)) {
|
|
62
|
-
fragmentSourceMap[fragmentName] = {};
|
|
63
|
-
fragmentSourceMap[fragmentName][sourceKey] = true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!astFragmentMap[sourceKey]) {
|
|
67
|
-
astFragmentMap[sourceKey] = true;
|
|
68
|
-
definitions.push(fragmentDefinition);
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
definitions.push(fragmentDefinition);
|
|
64
|
+
return doc;
|
|
72
65
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (docType === '[object Array]') {
|
|
87
|
-
return doc.map(function (d) {
|
|
88
|
-
return stripLoc(d, removeLocAtThisLevel);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (docType !== '[object Object]') {
|
|
93
|
-
throw new Error('Unexpected input.');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// We don't want to remove the root loc field so we can use it
|
|
97
|
-
// for fragment substitution (see below)
|
|
98
|
-
if (removeLocAtThisLevel && doc.loc) {
|
|
99
|
-
delete doc.loc;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// https://github.com/apollographql/graphql-tag/issues/40
|
|
103
|
-
if (doc.loc) {
|
|
104
|
-
delete doc.loc.startToken;
|
|
105
|
-
delete doc.loc.endToken;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var keys = Object.keys(doc);
|
|
109
|
-
var key;
|
|
110
|
-
var value;
|
|
111
|
-
var valueType;
|
|
112
|
-
|
|
113
|
-
for (key in keys) {
|
|
114
|
-
if (keys.hasOwnProperty(key)) {
|
|
115
|
-
value = doc[keys[key]];
|
|
116
|
-
valueType = Object.prototype.toString.call(value);
|
|
117
|
-
|
|
118
|
-
if (valueType === '[object Object]' || valueType === '[object Array]') {
|
|
119
|
-
doc[keys[key]] = stripLoc(value, true);
|
|
120
|
-
}
|
|
66
|
+
function parseDocument(source) {
|
|
67
|
+
var cacheKey = normalize(source);
|
|
68
|
+
if (!docCache.has(cacheKey)) {
|
|
69
|
+
var parsed = graphql.parse(source, {
|
|
70
|
+
experimentalFragmentVariables: experimentalFragmentVariables
|
|
71
|
+
});
|
|
72
|
+
if (!parsed || parsed.kind !== 'Document') {
|
|
73
|
+
throw new Error('Not a valid GraphQL document.');
|
|
74
|
+
}
|
|
75
|
+
docCache.set(cacheKey, stripLoc(processFragments(parsed)));
|
|
76
|
+
}
|
|
77
|
+
return docCache.get(cacheKey);
|
|
121
78
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// existing fragments of the same name
|
|
142
|
-
parsed = processFragments(parsed);
|
|
143
|
-
parsed = stripLoc(parsed, false);
|
|
144
|
-
docCache[cacheKey] = parsed;
|
|
145
|
-
|
|
146
|
-
return parsed;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function enableExperimentalFragmentVariables() {
|
|
150
|
-
experimentalFragmentVariables = true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function disableExperimentalFragmentVariables() {
|
|
154
|
-
experimentalFragmentVariables = false;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// XXX This should eventually disallow arbitrary string interpolation, like Relay does
|
|
158
|
-
function gql(/* arguments */) {
|
|
159
|
-
var args = Array.prototype.slice.call(arguments);
|
|
160
|
-
|
|
161
|
-
var literals = args[0];
|
|
162
|
-
|
|
163
|
-
// We always get literals[0] and then matching post literals for each arg given
|
|
164
|
-
var result = (typeof(literals) === "string") ? literals : literals[0];
|
|
165
|
-
|
|
166
|
-
for (var i = 1; i < args.length; i++) {
|
|
167
|
-
if (args[i] && args[i].kind && args[i].kind === 'Document') {
|
|
168
|
-
result += args[i].loc.source.body;
|
|
169
|
-
} else {
|
|
170
|
-
result += args[i];
|
|
79
|
+
function gql(literals) {
|
|
80
|
+
var args = [];
|
|
81
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
82
|
+
args[_i - 1] = arguments[_i];
|
|
83
|
+
}
|
|
84
|
+
if (typeof literals === 'string') {
|
|
85
|
+
literals = [literals];
|
|
86
|
+
}
|
|
87
|
+
var result = literals[0];
|
|
88
|
+
args.forEach(function (arg, i) {
|
|
89
|
+
if (arg && arg.kind === 'Document') {
|
|
90
|
+
result += arg.loc.source.body;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
result += arg;
|
|
94
|
+
}
|
|
95
|
+
result += literals[i + 1];
|
|
96
|
+
});
|
|
97
|
+
return parseDocument(result);
|
|
171
98
|
}
|
|
99
|
+
function resetCaches() {
|
|
100
|
+
docCache.clear();
|
|
101
|
+
fragmentSourceMap.clear();
|
|
102
|
+
}
|
|
103
|
+
function disableFragmentWarnings() {
|
|
104
|
+
printFragmentWarnings = false;
|
|
105
|
+
}
|
|
106
|
+
function enableExperimentalFragmentVariables() {
|
|
107
|
+
experimentalFragmentVariables = true;
|
|
108
|
+
}
|
|
109
|
+
function disableExperimentalFragmentVariables() {
|
|
110
|
+
experimentalFragmentVariables = false;
|
|
111
|
+
}
|
|
112
|
+
var index = Object.assign(gql, {
|
|
113
|
+
gql: gql,
|
|
114
|
+
"default": gql,
|
|
115
|
+
resetCaches: resetCaches,
|
|
116
|
+
disableFragmentWarnings: disableFragmentWarnings,
|
|
117
|
+
enableExperimentalFragmentVariables: enableExperimentalFragmentVariables,
|
|
118
|
+
disableExperimentalFragmentVariables: disableExperimentalFragmentVariables
|
|
119
|
+
});
|
|
172
120
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// Support typescript, which isn't as nice as Babel about default exports
|
|
180
|
-
gql.default = gql;
|
|
181
|
-
gql.resetCaches = resetCaches;
|
|
182
|
-
gql.disableFragmentWarnings = disableFragmentWarnings;
|
|
183
|
-
gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
|
|
184
|
-
gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;
|
|
121
|
+
exports.default = index;
|
|
122
|
+
exports.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;
|
|
123
|
+
exports.disableFragmentWarnings = disableFragmentWarnings;
|
|
124
|
+
exports.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
|
|
125
|
+
exports.gql = gql;
|
|
126
|
+
exports.resetCaches = resetCaches;
|
|
185
127
|
|
|
186
|
-
|
|
128
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
187
129
|
|
|
188
130
|
})));
|
|
189
131
|
//# sourceMappingURL=graphql-tag.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-tag.umd.js","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"graphql-tag.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { parse } from 'graphql';\n\nimport type {\n DocumentNode,\n DefinitionNode,\n Location,\n} from 'graphql/language/ast';\n\n// A map docString -> graphql document\nconst docCache = new Map<string, DocumentNode>();\n\n// A map fragmentName -> [normalized source]\nconst fragmentSourceMap = new Map<string, Set<string>>();\n\nlet printFragmentWarnings = true;\nlet experimentalFragmentVariables = false;\n\n// Strip insignificant whitespace\n// Note that this could do a lot more, such as reorder fields etc.\nfunction normalize(string: string) {\n return string.replace(/[\\s,]+/g, ' ').trim();\n}\n\nfunction cacheKeyFromLoc(loc: Location) {\n return normalize(loc.source.body.substring(loc.start, loc.end));\n}\n\n// Take a unstripped parsed document (query/mutation or even fragment), and\n// check all fragment definitions, checking for name->source uniqueness.\n// We also want to make sure only unique fragments exist in the document.\nfunction processFragments(ast: DocumentNode) {\n const seenKeys = new Set<string>();\n const definitions: DefinitionNode[] = [];\n\n ast.definitions.forEach(fragmentDefinition => {\n if (fragmentDefinition.kind === 'FragmentDefinition') {\n var fragmentName = fragmentDefinition.name.value;\n var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc!);\n\n // We know something about this fragment\n let sourceKeySet = fragmentSourceMap.get(fragmentName)!;\n if (sourceKeySet && !sourceKeySet.has(sourceKey)) {\n // this is a problem because the app developer is trying to register another fragment with\n // the same name as one previously registered. So, we tell them about it.\n if (printFragmentWarnings) {\n console.warn(\"Warning: fragment with name \" + fragmentName + \" already exists.\\n\"\n + \"graphql-tag enforces all fragment names across your application to be unique; read more about\\n\"\n + \"this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names\");\n }\n } else if (!sourceKeySet) {\n fragmentSourceMap.set(fragmentName, sourceKeySet = new Set);\n }\n\n sourceKeySet.add(sourceKey);\n\n if (!seenKeys.has(sourceKey)) {\n seenKeys.add(sourceKey);\n definitions.push(fragmentDefinition);\n }\n } else {\n definitions.push(fragmentDefinition);\n }\n });\n\n return {\n ...ast,\n definitions,\n };\n}\n\nfunction stripLoc(doc: DocumentNode) {\n const workSet = new Set<Record<string, any>>(doc.definitions);\n\n workSet.forEach(node => {\n if (node.loc) delete node.loc;\n Object.keys(node).forEach(key => {\n const value = node[key];\n if (value && typeof value === 'object') {\n workSet.add(value);\n }\n });\n });\n\n const loc = doc.loc as Record<string, any>;\n if (loc) {\n delete loc.startToken;\n delete loc.endToken;\n }\n\n return doc;\n}\n\nfunction parseDocument(source: string) {\n var cacheKey = normalize(source);\n if (!docCache.has(cacheKey)) {\n const parsed = parse(source, {\n experimentalFragmentVariables,\n });\n if (!parsed || parsed.kind !== 'Document') {\n throw new Error('Not a valid GraphQL document.');\n }\n docCache.set(\n cacheKey,\n // check that all \"new\" fragments inside the documents are consistent with\n // existing fragments of the same name\n stripLoc(processFragments(parsed)),\n );\n }\n return docCache.get(cacheKey)!;\n}\n\n// XXX This should eventually disallow arbitrary string interpolation, like Relay does\nexport function gql(\n literals: string | readonly string[],\n ...args: any[]\n) {\n\n if (typeof literals === 'string') {\n literals = [literals];\n }\n\n let result = literals[0];\n\n args.forEach((arg, i) => {\n if (arg && arg.kind === 'Document') {\n result += arg.loc.source.body;\n } else {\n result += arg;\n }\n result += literals[i + 1];\n });\n\n return parseDocument(result);\n}\n\nexport function resetCaches() {\n docCache.clear();\n fragmentSourceMap.clear();\n}\n\nexport function disableFragmentWarnings() {\n printFragmentWarnings = false;\n}\n\nexport function enableExperimentalFragmentVariables() {\n experimentalFragmentVariables = true;\n}\n\nexport function disableExperimentalFragmentVariables() {\n experimentalFragmentVariables = false;\n}\n\nexport default Object.assign(gql, {\n gql,\n default: gql,\n resetCaches,\n disableFragmentWarnings,\n enableExperimentalFragmentVariables,\n disableExperimentalFragmentVariables,\n});\n"],"names":["parse"],"mappings":";;;;;;IASA,IAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IAGjD,IAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEzD,IAAI,qBAAqB,GAAG,IAAI,CAAC;IACjC,IAAI,6BAA6B,GAAG,KAAK,CAAC;IAI1C,SAAS,SAAS,CAAC,MAAc;QAC/B,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,E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
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DocumentNode } from 'graphql/language/ast';
|
|
2
|
+
export declare function gql(literals: string | readonly string[], ...args: any[]): DocumentNode;
|
|
3
|
+
export declare function resetCaches(): void;
|
|
4
|
+
export declare function disableFragmentWarnings(): void;
|
|
5
|
+
export declare function enableExperimentalFragmentVariables(): void;
|
|
6
|
+
export declare function disableExperimentalFragmentVariables(): void;
|
|
7
|
+
declare const _default: typeof gql & {
|
|
8
|
+
gql: typeof gql;
|
|
9
|
+
default: typeof gql;
|
|
10
|
+
resetCaches: typeof resetCaches;
|
|
11
|
+
disableFragmentWarnings: typeof disableFragmentWarnings;
|
|
12
|
+
enableExperimentalFragmentVariables: typeof enableExperimentalFragmentVariables;
|
|
13
|
+
disableExperimentalFragmentVariables: typeof disableExperimentalFragmentVariables;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,sBAAsB,CAAC;AA0G9B,wBAAgB,GAAG,CACjB,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EACpC,GAAG,IAAI,EAAE,GAAG,EAAE,gBAmBf;AAED,wBAAgB,WAAW,SAG1B;AAED,wBAAgB,uBAAuB,SAEtC;AAED,wBAAgB,mCAAmC,SAElD;AAED,wBAAgB,oCAAoC,SAEnD;;;;;;;;;AAED,wBAOG"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { parse } from 'graphql';
|
|
3
|
+
var docCache = new Map();
|
|
4
|
+
var fragmentSourceMap = new Map();
|
|
5
|
+
var printFragmentWarnings = true;
|
|
6
|
+
var experimentalFragmentVariables = false;
|
|
7
|
+
function normalize(string) {
|
|
8
|
+
return string.replace(/[\s,]+/g, ' ').trim();
|
|
9
|
+
}
|
|
10
|
+
function cacheKeyFromLoc(loc) {
|
|
11
|
+
return normalize(loc.source.body.substring(loc.start, loc.end));
|
|
12
|
+
}
|
|
13
|
+
function processFragments(ast) {
|
|
14
|
+
var seenKeys = new Set();
|
|
15
|
+
var definitions = [];
|
|
16
|
+
ast.definitions.forEach(function (fragmentDefinition) {
|
|
17
|
+
if (fragmentDefinition.kind === 'FragmentDefinition') {
|
|
18
|
+
var fragmentName = fragmentDefinition.name.value;
|
|
19
|
+
var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);
|
|
20
|
+
var sourceKeySet = fragmentSourceMap.get(fragmentName);
|
|
21
|
+
if (sourceKeySet && !sourceKeySet.has(sourceKey)) {
|
|
22
|
+
if (printFragmentWarnings) {
|
|
23
|
+
console.warn("Warning: fragment with name " + fragmentName + " already exists.\n"
|
|
24
|
+
+ "graphql-tag enforces all fragment names across your application to be unique; read more about\n"
|
|
25
|
+
+ "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (!sourceKeySet) {
|
|
29
|
+
fragmentSourceMap.set(fragmentName, sourceKeySet = new Set);
|
|
30
|
+
}
|
|
31
|
+
sourceKeySet.add(sourceKey);
|
|
32
|
+
if (!seenKeys.has(sourceKey)) {
|
|
33
|
+
seenKeys.add(sourceKey);
|
|
34
|
+
definitions.push(fragmentDefinition);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
definitions.push(fragmentDefinition);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return __assign(__assign({}, ast), { definitions: definitions });
|
|
42
|
+
}
|
|
43
|
+
function stripLoc(doc) {
|
|
44
|
+
var workSet = new Set(doc.definitions);
|
|
45
|
+
workSet.forEach(function (node) {
|
|
46
|
+
if (node.loc)
|
|
47
|
+
delete node.loc;
|
|
48
|
+
Object.keys(node).forEach(function (key) {
|
|
49
|
+
var value = node[key];
|
|
50
|
+
if (value && typeof value === 'object') {
|
|
51
|
+
workSet.add(value);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
var loc = doc.loc;
|
|
56
|
+
if (loc) {
|
|
57
|
+
delete loc.startToken;
|
|
58
|
+
delete loc.endToken;
|
|
59
|
+
}
|
|
60
|
+
return doc;
|
|
61
|
+
}
|
|
62
|
+
function parseDocument(source) {
|
|
63
|
+
var cacheKey = normalize(source);
|
|
64
|
+
if (!docCache.has(cacheKey)) {
|
|
65
|
+
var parsed = parse(source, {
|
|
66
|
+
experimentalFragmentVariables: experimentalFragmentVariables
|
|
67
|
+
});
|
|
68
|
+
if (!parsed || parsed.kind !== 'Document') {
|
|
69
|
+
throw new Error('Not a valid GraphQL document.');
|
|
70
|
+
}
|
|
71
|
+
docCache.set(cacheKey, stripLoc(processFragments(parsed)));
|
|
72
|
+
}
|
|
73
|
+
return docCache.get(cacheKey);
|
|
74
|
+
}
|
|
75
|
+
export function gql(literals) {
|
|
76
|
+
var args = [];
|
|
77
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
78
|
+
args[_i - 1] = arguments[_i];
|
|
79
|
+
}
|
|
80
|
+
if (typeof literals === 'string') {
|
|
81
|
+
literals = [literals];
|
|
82
|
+
}
|
|
83
|
+
var result = literals[0];
|
|
84
|
+
args.forEach(function (arg, i) {
|
|
85
|
+
if (arg && arg.kind === 'Document') {
|
|
86
|
+
result += arg.loc.source.body;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
result += arg;
|
|
90
|
+
}
|
|
91
|
+
result += literals[i + 1];
|
|
92
|
+
});
|
|
93
|
+
return parseDocument(result);
|
|
94
|
+
}
|
|
95
|
+
export function resetCaches() {
|
|
96
|
+
docCache.clear();
|
|
97
|
+
fragmentSourceMap.clear();
|
|
98
|
+
}
|
|
99
|
+
export function disableFragmentWarnings() {
|
|
100
|
+
printFragmentWarnings = false;
|
|
101
|
+
}
|
|
102
|
+
export function enableExperimentalFragmentVariables() {
|
|
103
|
+
experimentalFragmentVariables = true;
|
|
104
|
+
}
|
|
105
|
+
export function disableExperimentalFragmentVariables() {
|
|
106
|
+
experimentalFragmentVariables = false;
|
|
107
|
+
}
|
|
108
|
+
export default Object.assign(gql, {
|
|
109
|
+
gql: gql,
|
|
110
|
+
"default": gql,
|
|
111
|
+
resetCaches: resetCaches,
|
|
112
|
+
disableFragmentWarnings: disableFragmentWarnings,
|
|
113
|
+
enableExperimentalFragmentVariables: enableExperimentalFragmentVariables,
|
|
114
|
+
disableExperimentalFragmentVariables: disableExperimentalFragmentVariables
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAShC,IAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;AAGjD,IAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;AAEzD,IAAI,qBAAqB,GAAG,IAAI,CAAC;AACjC,IAAI,6BAA6B,GAAG,KAAK,CAAC;AAI1C,SAAS,SAAS,CAAC,MAAc;IAC/B,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,eAAe,CAAC,GAAa;IACpC,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAKD,SAAS,gBAAgB,CAAC,GAAiB;IACzC,IAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,IAAM,WAAW,GAAqB,EAAE,CAAC;IAEzC,GAAG,CA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