graphql-tag 2.9.0 → 2.10.1
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/CHANGELOG.md +7 -0
- package/LICENSE +1 -1
- package/README.md +17 -1
- package/lib/graphql-tag.umd.js +12 -1
- package/lib/graphql-tag.umd.js.map +1 -1
- package/loader.js +13 -4
- package/package.json +3 -3
- package/src/index.js +12 -1
- package/test/graphql.js +10 -0
- package/.editorconfig +0 -7
- package/.flowconfig +0 -8
- package/.github/ISSUE_TEMPLATE.md +0 -18
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- package/yarn.lock +0 -1141
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# Change log
|
|
2
2
|
|
|
3
|
+
### v2.10.0
|
|
4
|
+
* Add support for `graphql@14` by [timsuchanek](https://github.com/timsuchanek) in [#210](https://github.com/apollographql/graphql-tag/pull/210), [#211](https://github.com/apollographql/graphql-tag/pull/211)
|
|
5
|
+
|
|
6
|
+
### v2.9.1
|
|
7
|
+
* Fix IE11 support by using a regular for-loop by [vitorbal](https://github.com/vitorbal) in [#176](https://github.com/apollographql/graphql-tag/pull/176)
|
|
8
|
+
|
|
3
9
|
### v2.9.0
|
|
4
10
|
* Remove duplicate exports in named exports by [wacii](https://github.com/wacii) in [#170](https://github.com/apollographql/graphql-tag/pull/170)
|
|
11
|
+
* Add `experimentalFragmentVariables` compatibility by [lucasconstantino](https://github.com/lucasconstantino) in [#167](https://github.com/apollographql/graphql-tag/pull/167/)
|
|
5
12
|
|
|
6
13
|
### v2.8.0
|
|
7
14
|
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2015 -
|
|
3
|
+
Copyright (c) 2015 - 2018 Meteor Development Group, Inc.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ Try this custom transformer to pre-compile your GraphQL queries in TypeScript: [
|
|
|
73
73
|
|
|
74
74
|
#### React Native, Next.js
|
|
75
75
|
|
|
76
|
-
Additionally, in certain situations, preprocessing queries via the webpack loader is not possible. [babel-plugin-
|
|
76
|
+
Additionally, in certain situations, preprocessing queries via the webpack loader is not possible. [babel-plugin-import-graphql](https://www.npmjs.com/package/babel-plugin-import-graphql) will allow one to import graphql files directly into your JavaScript by preprocessing GraphQL queries into ASTs at compile-time.
|
|
77
77
|
|
|
78
78
|
E.g.:
|
|
79
79
|
```javascript
|
|
@@ -146,3 +146,19 @@ import { disableFragmentWarnings } from 'graphql-tag';
|
|
|
146
146
|
|
|
147
147
|
disableFragmentWarnings()
|
|
148
148
|
```
|
|
149
|
+
|
|
150
|
+
### Experimental Fragment Variables
|
|
151
|
+
|
|
152
|
+
This package exports an `experimentalFragmentVariables` flag that allows you to use experimental support for [parameterized fragments](https://github.com/facebook/graphql/issues/204).
|
|
153
|
+
|
|
154
|
+
You can enable / disable this with:
|
|
155
|
+
```js
|
|
156
|
+
import { enableExperimentalFragmentVariables, disableExperimentalFragmentVariables } from 'graphql-tag';
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Enabling this feature allows you declare documents of the form
|
|
160
|
+
```graphql
|
|
161
|
+
fragment SomeFragment ($arg: String!) on SomeType {
|
|
162
|
+
someField
|
|
163
|
+
}
|
|
164
|
+
```
|
package/lib/graphql-tag.umd.js
CHANGED
|
@@ -124,6 +124,7 @@ function stripLoc(doc, removeLocAtThisLevel) {
|
|
|
124
124
|
return doc;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
var experimentalFragmentVariables = false;
|
|
127
128
|
function parseDocument(doc) {
|
|
128
129
|
var cacheKey = normalize(doc);
|
|
129
130
|
|
|
@@ -131,7 +132,7 @@ function parseDocument(doc) {
|
|
|
131
132
|
return docCache[cacheKey];
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
var parsed = parse(doc);
|
|
135
|
+
var parsed = parse(doc, { experimentalFragmentVariables: experimentalFragmentVariables });
|
|
135
136
|
if (!parsed || parsed.kind !== 'Document') {
|
|
136
137
|
throw new Error('Not a valid GraphQL document.');
|
|
137
138
|
}
|
|
@@ -145,6 +146,14 @@ function parseDocument(doc) {
|
|
|
145
146
|
return parsed;
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
function enableExperimentalFragmentVariables() {
|
|
150
|
+
experimentalFragmentVariables = true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function disableExperimentalFragmentVariables() {
|
|
154
|
+
experimentalFragmentVariables = false;
|
|
155
|
+
}
|
|
156
|
+
|
|
148
157
|
// XXX This should eventually disallow arbitrary string interpolation, like Relay does
|
|
149
158
|
function gql(/* arguments */) {
|
|
150
159
|
var args = Array.prototype.slice.call(arguments);
|
|
@@ -171,6 +180,8 @@ function gql(/* arguments */) {
|
|
|
171
180
|
gql.default = gql;
|
|
172
181
|
gql.resetCaches = resetCaches;
|
|
173
182
|
gql.disableFragmentWarnings = disableFragmentWarnings;
|
|
183
|
+
gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
|
|
184
|
+
gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;
|
|
174
185
|
|
|
175
186
|
module.exports = gql;
|
|
176
187
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-tag.umd.js","sources":["../src/index.js"],"sourcesContent":["var parser = require('graphql/language/parser');\n\nvar parse = parser.parse;\n\n// Strip insignificant whitespace\n// Note that this could do a lot more, such as reorder fields etc.\nfunction normalize(string) {\n return string.replace(/[\\s,]+/g, ' ').trim();\n}\n\n// A map docString -> graphql document\nvar docCache = {};\n\n// A map fragmentName -> [normalized source]\nvar fragmentSourceMap = {};\n\nfunction cacheKeyFromLoc(loc) {\n return normalize(loc.source.body.substring(loc.start, loc.end));\n}\n\n// For testing.\nfunction resetCaches() {\n docCache = {};\n fragmentSourceMap = {};\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.\nvar printFragmentWarnings = true;\nfunction processFragments(ast) {\n var astFragmentMap = {};\n var definitions = [];\n\n for (var i = 0; i < ast.definitions.length; i++) {\n var fragmentDefinition = ast.definitions[i];\n\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 if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) {\n\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\n fragmentSourceMap[fragmentName][sourceKey] = true;\n\n } else if (!fragmentSourceMap.hasOwnProperty(fragmentName)) {\n fragmentSourceMap[fragmentName] = {};\n fragmentSourceMap[fragmentName][sourceKey] = true;\n }\n\n if (!astFragmentMap[sourceKey]) {\n astFragmentMap[sourceKey] = true;\n definitions.push(fragmentDefinition);\n }\n } else {\n definitions.push(fragmentDefinition);\n }\n }\n\n ast.definitions = definitions;\n return ast;\n}\n\nfunction disableFragmentWarnings() {\n printFragmentWarnings = false;\n}\n\nfunction stripLoc(doc, removeLocAtThisLevel) {\n var docType = Object.prototype.toString.call(doc);\n\n if (docType === '[object Array]') {\n return doc.map(function (d) {\n return stripLoc(d, removeLocAtThisLevel);\n });\n }\n\n if (docType !== '[object Object]') {\n throw new Error('Unexpected input.');\n }\n\n // We don't want to remove the root loc field so we can use it\n // for fragment substitution (see below)\n if (removeLocAtThisLevel && doc.loc) {\n delete doc.loc;\n }\n\n // https://github.com/apollographql/graphql-tag/issues/40\n if (doc.loc) {\n delete doc.loc.startToken;\n delete doc.loc.endToken;\n }\n\n var keys = Object.keys(doc);\n var key;\n var value;\n var valueType;\n\n for (key in keys) {\n if (keys.hasOwnProperty(key)) {\n value = doc[keys[key]];\n valueType = Object.prototype.toString.call(value);\n\n if (valueType === '[object Object]' || valueType === '[object Array]') {\n doc[keys[key]] = stripLoc(value, true);\n }\n }\n }\n\n return doc;\n}\n\nfunction parseDocument(doc) {\n var cacheKey = normalize(doc);\n\n if (docCache[cacheKey]) {\n return docCache[cacheKey];\n }\n\n var parsed = parse(doc);\n if (!parsed || parsed.kind !== 'Document') {\n throw new Error('Not a valid GraphQL document.');\n }\n\n // check that all \"new\" fragments inside the documents are consistent with\n // existing fragments of the same name\n parsed = processFragments(parsed);\n parsed = stripLoc(parsed, false);\n docCache[cacheKey] = parsed;\n\n return parsed;\n}\n\n// XXX This should eventually disallow arbitrary string interpolation, like Relay does\nfunction gql(/* arguments */) {\n var args = Array.prototype.slice.call(arguments);\n\n var literals = args[0];\n\n // We always get literals[0] and then matching post literals for each arg given\n var result = (typeof(literals) === \"string\") ? literals : literals[0];\n\n for (var i = 1; i < args.length; i++) {\n if (args[i] && args[i].kind && args[i].kind === 'Document') {\n result += args[i].loc.source.body;\n } else {\n result += args[i];\n }\n\n result += literals[i];\n }\n\n return parseDocument(result);\n}\n\n// Support typescript, which isn't as nice as Babel about default exports\ngql.default = gql;\ngql.resetCaches = resetCaches;\ngql.disableFragmentWarnings = disableFragmentWarnings;\n\nmodule.exports = gql;\n"],"names":[],"mappings":";;;;;;AAAA,IAAI,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;;AAEhD,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;;;;AAIzB,SAAS,SAAS,CAAC,MAAM,EAAE;EACzB,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EA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AAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;EAC5B,IAAI,GAAG,CAAC;EACR,IAAI,KAAK,CAAC;EACV,IAAI,SAAS,CAAC;;EAEd,KAAK,GAAG,IAAI,IAAI,EAAE;IAChB,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;MAC5B,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;MACvB,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;MAElD,IAAI,SAAS,KAAK,iBAAiB,IAAI,SAAS,KAAK,gBAAgB,EAAE;QACrE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;OACxC;KACF;GACF;;EAED,OAAO,GAAG,CAAC;CACZ;;AAED,SAAS,aAAa,CAAC,GAAG,EAAE;EAC1B,IAAI,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;;EAE9B,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE;IACtB,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC;GAC3B;;EAED,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"graphql-tag.umd.js","sources":["../src/index.js"],"sourcesContent":["var parser = require('graphql/language/parser');\n\nvar parse = parser.parse;\n\n// Strip insignificant whitespace\n// Note that this could do a lot more, such as reorder fields etc.\nfunction normalize(string) {\n return string.replace(/[\\s,]+/g, ' ').trim();\n}\n\n// A map docString -> graphql document\nvar docCache = {};\n\n// A map fragmentName -> [normalized source]\nvar fragmentSourceMap = {};\n\nfunction cacheKeyFromLoc(loc) {\n return normalize(loc.source.body.substring(loc.start, loc.end));\n}\n\n// For testing.\nfunction resetCaches() {\n docCache = {};\n fragmentSourceMap = {};\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.\nvar printFragmentWarnings = true;\nfunction processFragments(ast) {\n var astFragmentMap = {};\n var definitions = [];\n\n for (var i = 0; i < ast.definitions.length; i++) {\n var fragmentDefinition = ast.definitions[i];\n\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 if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) {\n\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\n fragmentSourceMap[fragmentName][sourceKey] = true;\n\n } else if (!fragmentSourceMap.hasOwnProperty(fragmentName)) {\n fragmentSourceMap[fragmentName] = {};\n fragmentSourceMap[fragmentName][sourceKey] = true;\n }\n\n if (!astFragmentMap[sourceKey]) {\n astFragmentMap[sourceKey] = true;\n definitions.push(fragmentDefinition);\n }\n } else {\n definitions.push(fragmentDefinition);\n }\n }\n\n ast.definitions = definitions;\n return ast;\n}\n\nfunction disableFragmentWarnings() {\n printFragmentWarnings = false;\n}\n\nfunction stripLoc(doc, removeLocAtThisLevel) {\n var docType = Object.prototype.toString.call(doc);\n\n if (docType === '[object Array]') {\n return doc.map(function (d) {\n return stripLoc(d, removeLocAtThisLevel);\n });\n }\n\n if (docType !== '[object Object]') {\n throw new Error('Unexpected input.');\n }\n\n // We don't want to remove the root loc field so we can use it\n // for fragment substitution (see below)\n if (removeLocAtThisLevel && doc.loc) {\n delete doc.loc;\n }\n\n // https://github.com/apollographql/graphql-tag/issues/40\n if (doc.loc) {\n delete doc.loc.startToken;\n delete doc.loc.endToken;\n }\n\n var keys = Object.keys(doc);\n var key;\n var value;\n var valueType;\n\n for (key in keys) {\n if (keys.hasOwnProperty(key)) {\n value = doc[keys[key]];\n valueType = Object.prototype.toString.call(value);\n\n if (valueType === '[object Object]' || valueType === '[object Array]') {\n doc[keys[key]] = stripLoc(value, true);\n }\n }\n }\n\n return doc;\n}\n\nvar experimentalFragmentVariables = false;\nfunction parseDocument(doc) {\n var cacheKey = normalize(doc);\n\n if (docCache[cacheKey]) {\n return docCache[cacheKey];\n }\n\n var parsed = parse(doc, { experimentalFragmentVariables: experimentalFragmentVariables });\n if (!parsed || parsed.kind !== 'Document') {\n throw new Error('Not a valid GraphQL document.');\n }\n\n // check that all \"new\" fragments inside the documents are consistent with\n // existing fragments of the same name\n parsed = processFragments(parsed);\n parsed = stripLoc(parsed, false);\n docCache[cacheKey] = parsed;\n\n return parsed;\n}\n\nfunction enableExperimentalFragmentVariables() {\n experimentalFragmentVariables = true;\n}\n\nfunction disableExperimentalFragmentVariables() {\n experimentalFragmentVariables = false;\n}\n\n// XXX This should eventually disallow arbitrary string interpolation, like Relay does\nfunction gql(/* arguments */) {\n var args = Array.prototype.slice.call(arguments);\n\n var literals = args[0];\n\n // We always get literals[0] and then matching post literals for each arg given\n var result = (typeof(literals) === \"string\") ? literals : literals[0];\n\n for (var i = 1; i < args.length; i++) {\n if (args[i] && args[i].kind && args[i].kind === 'Document') {\n result += args[i].loc.source.body;\n } else {\n result += args[i];\n }\n\n result += literals[i];\n }\n\n return parseDocument(result);\n}\n\n// Support typescript, which isn't as nice as Babel about default exports\ngql.default = gql;\ngql.resetCaches = resetCaches;\ngql.disableFragmentWarnings = disableFragmentWarnings;\ngql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;\ngql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;\n\nmodule.exports = gql;\n"],"names":[],"mappings":";;;;;;AAAA,IAAI,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;;AAEhD,IAAI,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AAC9E,GAAG,CAAC,oCAAoC,GAAG,oCAAoC,CAAC;;AAEhF,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC;;;;"}
|
package/loader.js
CHANGED
|
@@ -108,9 +108,12 @@ module.exports = function(source) {
|
|
|
108
108
|
})();
|
|
109
109
|
|
|
110
110
|
function findOperation(doc, name) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
for (var i = 0; i < doc.definitions.length; i++) {
|
|
112
|
+
var element = doc.definitions[i];
|
|
113
|
+
if (element.name && element.name.value == name) {
|
|
114
|
+
return element;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
function oneQuery(doc, operationName) {
|
|
@@ -127,7 +130,13 @@ module.exports = function(source) {
|
|
|
127
130
|
// it or the fragments it references
|
|
128
131
|
var opRefs = definitionRefs[operationName] || new Set();
|
|
129
132
|
var allRefs = new Set();
|
|
130
|
-
var newRefs = new Set(
|
|
133
|
+
var newRefs = new Set();
|
|
134
|
+
|
|
135
|
+
// IE 11 doesn't support "new Set(iterable)", so we add the members of opRefs to newRefs one by one
|
|
136
|
+
opRefs.forEach(function(refName) {
|
|
137
|
+
newRefs.add(refName);
|
|
138
|
+
});
|
|
139
|
+
|
|
131
140
|
while (newRefs.size > 0) {
|
|
132
141
|
var prevRefs = newRefs;
|
|
133
142
|
newRefs = new Set();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-tag",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"description": "A JavaScript template literal tag that parses GraphQL queries",
|
|
5
5
|
"main": "./lib/graphql-tag.umd.js",
|
|
6
6
|
"module": "./src/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"babel-preset-es2015": "^6.9.0",
|
|
26
26
|
"babel-register": "^6.9.0",
|
|
27
27
|
"chai": "^4.0.2",
|
|
28
|
-
"graphql": "^0.
|
|
28
|
+
"graphql": "^14.0.2",
|
|
29
29
|
"mocha": "^3.4.1",
|
|
30
30
|
"rollup": "^0.45.0",
|
|
31
31
|
"test-all-versions": "^3.3.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0"
|
|
34
|
+
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/index.js
CHANGED
|
@@ -118,6 +118,7 @@ function stripLoc(doc, removeLocAtThisLevel) {
|
|
|
118
118
|
return doc;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
var experimentalFragmentVariables = false;
|
|
121
122
|
function parseDocument(doc) {
|
|
122
123
|
var cacheKey = normalize(doc);
|
|
123
124
|
|
|
@@ -125,7 +126,7 @@ function parseDocument(doc) {
|
|
|
125
126
|
return docCache[cacheKey];
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
var parsed = parse(doc);
|
|
129
|
+
var parsed = parse(doc, { experimentalFragmentVariables: experimentalFragmentVariables });
|
|
129
130
|
if (!parsed || parsed.kind !== 'Document') {
|
|
130
131
|
throw new Error('Not a valid GraphQL document.');
|
|
131
132
|
}
|
|
@@ -139,6 +140,14 @@ function parseDocument(doc) {
|
|
|
139
140
|
return parsed;
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
function enableExperimentalFragmentVariables() {
|
|
144
|
+
experimentalFragmentVariables = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function disableExperimentalFragmentVariables() {
|
|
148
|
+
experimentalFragmentVariables = false;
|
|
149
|
+
}
|
|
150
|
+
|
|
142
151
|
// XXX This should eventually disallow arbitrary string interpolation, like Relay does
|
|
143
152
|
function gql(/* arguments */) {
|
|
144
153
|
var args = Array.prototype.slice.call(arguments);
|
|
@@ -165,5 +174,7 @@ function gql(/* arguments */) {
|
|
|
165
174
|
gql.default = gql;
|
|
166
175
|
gql.resetCaches = resetCaches;
|
|
167
176
|
gql.disableFragmentWarnings = disableFragmentWarnings;
|
|
177
|
+
gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
|
|
178
|
+
gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;
|
|
168
179
|
|
|
169
180
|
module.exports = gql;
|
package/test/graphql.js
CHANGED
|
@@ -83,6 +83,16 @@ const assert = require('chai').assert;
|
|
|
83
83
|
assert.equal(module.exports.Q2.definitions.length, 1);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
+
it('parses fragments with variable definitions', () => {
|
|
87
|
+
gql.enableExperimentalFragmentVariables();
|
|
88
|
+
|
|
89
|
+
const parsed = gql`fragment A ($arg: String!) on Type { testQuery }`;
|
|
90
|
+
assert.equal(parsed.kind, 'Document');
|
|
91
|
+
assert.exists(parsed.definitions[0].variableDefinitions);
|
|
92
|
+
|
|
93
|
+
gql.disableExperimentalFragmentVariables()
|
|
94
|
+
});
|
|
95
|
+
|
|
86
96
|
// see https://github.com/apollographql/graphql-tag/issues/168
|
|
87
97
|
it('does not nest queries needlessly in named exports', () => {
|
|
88
98
|
const jsSource = loader.call({ cacheable() {} }, `
|
package/.editorconfig
DELETED
package/.flowconfig
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
**Issue Labels**
|
|
4
|
-
|
|
5
|
-
<!--
|
|
6
|
-
While not necessary, you can help organize our issues by labeling this issue when you open it. To add a label automatically, simply [x] mark the appropriate box below:
|
|
7
|
-
-->
|
|
8
|
-
|
|
9
|
-
- [ ] has-reproduction
|
|
10
|
-
- [ ] feature
|
|
11
|
-
- [ ] docs
|
|
12
|
-
- [ ] blocking
|
|
13
|
-
- [ ] good first issue
|
|
14
|
-
|
|
15
|
-
<!--
|
|
16
|
-
You are also able to add labels by placing /label on a new line
|
|
17
|
-
followed by the label you would like to add. ex: /label discussion
|
|
18
|
-
-->
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
**Pull Request Labels**
|
|
2
|
-
|
|
3
|
-
<!--
|
|
4
|
-
While not necessary, you can help organize our pull requests by labeling this pull request when you open it. To add a label automatically, simply [x] mark the appropriate box below:
|
|
5
|
-
-->
|
|
6
|
-
|
|
7
|
-
- [ ] feature
|
|
8
|
-
- [ ] blocking
|
|
9
|
-
- [ ] docs
|
|
10
|
-
|
|
11
|
-
<!--
|
|
12
|
-
You are also able to add labels by placing /label on a new line
|
|
13
|
-
followed by the label you would like to add. ex: /label discussion
|
|
14
|
-
-->
|