graphql-tag 2.7.1 → 2.9.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/.github/ISSUE_TEMPLATE.md +18 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- package/.tav.yml +10 -0
- package/CHANGELOG.md +18 -2
- package/README.md +26 -1
- package/lib/graphql-tag.umd.js +12 -1
- package/lib/graphql-tag.umd.js.map +1 -1
- package/loader.js +16 -9
- package/package.json +6 -5
- package/src/index.js +12 -1
- package/test/graphql-v0.11.js +137 -0
- package/test/graphql-v0.12.js +138 -0
- package/test/graphql.js +465 -0
- package/test/mocha.opts +1 -0
- package/yarn.lock +333 -13
- package/.npmignore +0 -6
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
-->
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
-->
|
package/.tav.yml
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
# Change log
|
|
2
2
|
|
|
3
|
-
### v2.
|
|
3
|
+
### v2.9.0
|
|
4
|
+
* Remove duplicate exports in named exports by [wacii](https://github.com/wacii) in [#170](https://github.com/apollographql/graphql-tag/pull/170)
|
|
5
|
+
* Add `experimentalFragmentVariables` compatibility by [lucasconstantino](https://github.com/lucasconstantino) in [#167](https://github.com/apollographql/graphql-tag/pull/167/)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
### v2.8.0
|
|
8
|
+
|
|
9
|
+
* Update `graphql` to ^0.13, support testing all compatible versions [jnwng](https://github.com/jnwng) in
|
|
10
|
+
[PR #156](https://github.com/apollographql/graphql-tag/pull/156)
|
|
11
|
+
* Export single queries as both default and named [stonexer](https://github.com/stonexer) in
|
|
12
|
+
[PR #154](https://github.com/apollographql/graphql-tag/pull/154)
|
|
13
|
+
|
|
14
|
+
### v2.7.{0,1,2,3}
|
|
15
|
+
|
|
16
|
+
* Merge and then revert [PR #141](https://github.com/apollographql/graphql-tag/pull/141) due to errors being thrown
|
|
17
|
+
|
|
18
|
+
### v2.6.1
|
|
19
|
+
|
|
20
|
+
* Accept `graphql@^0.12.0` as peerDependency [jnwng](https://github.com/jnwng)
|
|
21
|
+
addressing [#134](https://github.com/apollographql/graphql-tag/issues/134)
|
|
6
22
|
|
|
7
23
|
### v2.6.0
|
|
8
24
|
|
package/README.md
CHANGED
|
@@ -72,17 +72,24 @@ GraphQL queries can be compiled at build time using [babel-plugin-graphql-tag](h
|
|
|
72
72
|
Try this custom transformer to pre-compile your GraphQL queries in TypeScript: [ts-transform-graphql-tag](https://github.com/firede/ts-transform-graphql-tag).
|
|
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-inline-import-graphql-ast](https://www.npmjs.com/package/babel-plugin-inline-import-graphql-ast) will allow one to import graphql files directly into your JavaScript by preprocessing GraphQL queries into ASTs at compile-time.
|
|
76
77
|
|
|
77
78
|
E.g.:
|
|
78
79
|
```javascript
|
|
79
80
|
import myImportedQuery from './productsQuery.graphql'
|
|
80
|
-
|
|
81
|
+
|
|
81
82
|
class ProductsPage extends React.Component {
|
|
82
83
|
...
|
|
83
84
|
}
|
|
84
85
|
```
|
|
85
86
|
|
|
87
|
+
#### Create-React-App
|
|
88
|
+
|
|
89
|
+
`create-react-app@2.0.0` will [support the ability to preprocess queries](https://github.com/facebook/create-react-app/pull/3909) using `graphql-tag/loader` without the need to eject.
|
|
90
|
+
|
|
91
|
+
If you're using an older version of `create-react-app`, check out [react-app-rewire-inline-import-graphql-ast](https://www.npmjs.com/package/react-app-rewire-inline-import-graphql-ast) to preprocess queries without needing to eject.
|
|
92
|
+
|
|
86
93
|
### Webpack preprocessing with `graphql-tag/loader`
|
|
87
94
|
|
|
88
95
|
This package also includes a [webpack loader](https://webpack.js.org/concepts/loaders). There are many benefits over this approach, which saves GraphQL ASTs processing time on client-side and enable queries to be separated from script over `.graphql` files.
|
|
@@ -139,3 +146,21 @@ import { disableFragmentWarnings } from 'graphql-tag';
|
|
|
139
146
|
|
|
140
147
|
disableFragmentWarnings()
|
|
141
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
|
+
```
|
|
165
|
+
|
|
166
|
+
|
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 =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;IACjC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;GACtC;;;;EAID,IAAI,oBAAoB,IAAI,GAAG,CAAC,GAAG,EAAE;IACnC,OAAO,GAAG,CAAC,GAAG,CAAC;GAChB;;;EAGD,IAAI,GAAG,CAAC,GAAG,EAAE;IACX,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1B,OAAO,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;GACzB;;EAED,IAAI,IAAI,GAAG,MAAM,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,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;;;;AAIzB,SAAS,SAAS,CAAC,MAAM,EAAE;EACzB,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;CAC9C;;;AAGD,IAAI,QAAQ,GAAG,EAAE,CAAC;;;AAGlB,IAAI,iBAAiB,GAAG,EAAE,CAAC;;AAE3B,SAAS,eAAe,CAAC,GAAG,EAAE;EAC5B,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;CACjE;;;AAGD,SAAS,WAAW,GAAG;EACrB,QAAQ,GAAG,EAAE,CAAC;EACd,iBAAiB,GAAG,EAAE,CAAC;CACxB;;;;;AAKD,IAAI,qBAAqB,GAAG,IAAI,CAAC;AACjC,SAAS,gBAAgB,CAAC,GAAG,EAAE;EAC7B,IAAI,cAAc,GAAG,EAAE,CAAC;EACxB,IAAI,WAAW,GAAG,EAAE,CAAC;;EAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IAC/C,IAAI,kBAAkB,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;;IAE5C,IAAI,kBAAkB,CAAC,IAAI,KAAK,oBAAoB,EAAE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AI,CAAC,CAAC,CAAC,CAAC;KACnB;;IAED,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;GACvB;;EAED,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;CAC9B;;;AAGD,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC;AAClB,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;AAC9B,GAAG,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AACtD,GAAG,CAAC,mCAAmC,GAAG,mCAAmC,CAAC;AAC9E,GAAG,CAAC,oCAAoC,GAAG,oCAAoC,CAAC;;AAEhF,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC;;;;"}
|
package/loader.js
CHANGED
|
@@ -60,12 +60,12 @@ module.exports = function(source) {
|
|
|
60
60
|
return accum;
|
|
61
61
|
}, 0);
|
|
62
62
|
|
|
63
|
-
if (operationCount
|
|
63
|
+
if (operationCount < 1) {
|
|
64
64
|
outputCode += `
|
|
65
65
|
module.exports = doc;
|
|
66
66
|
`
|
|
67
67
|
} else {
|
|
68
|
-
outputCode
|
|
68
|
+
outputCode += `
|
|
69
69
|
// Collect any fragment/type references from a node, adding them to the refs Set
|
|
70
70
|
function collectFragmentReferences(node, refs) {
|
|
71
71
|
if (node.kind === "FragmentSpread") {
|
|
@@ -112,14 +112,17 @@ module.exports = function(source) {
|
|
|
112
112
|
return op.name ? op.name.value == name : false;
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
function oneQuery(doc, operationName) {
|
|
117
117
|
// Copy the DocumentNode, but clear out the definitions
|
|
118
|
-
var newDoc =
|
|
118
|
+
var newDoc = {
|
|
119
|
+
kind: doc.kind,
|
|
120
|
+
definitions: [findOperation(doc, operationName)]
|
|
121
|
+
};
|
|
122
|
+
if (doc.hasOwnProperty("loc")) {
|
|
123
|
+
newDoc.loc = doc.loc;
|
|
124
|
+
}
|
|
119
125
|
|
|
120
|
-
var op = findOperation(doc, operationName);
|
|
121
|
-
newDoc.definitions = [op];
|
|
122
|
-
|
|
123
126
|
// Now, for the operation we're running, find any fragments referenced by
|
|
124
127
|
// it or the fragments it references
|
|
125
128
|
var opRefs = definitionRefs[operationName] || new Set();
|
|
@@ -146,7 +149,7 @@ module.exports = function(source) {
|
|
|
146
149
|
newDoc.definitions.push(op);
|
|
147
150
|
}
|
|
148
151
|
});
|
|
149
|
-
|
|
152
|
+
|
|
150
153
|
return newDoc;
|
|
151
154
|
}
|
|
152
155
|
|
|
@@ -156,7 +159,11 @@ module.exports = function(source) {
|
|
|
156
159
|
for (const op of doc.definitions) {
|
|
157
160
|
if (op.kind === "OperationDefinition") {
|
|
158
161
|
if (!op.name) {
|
|
159
|
-
|
|
162
|
+
if (operationCount > 1) {
|
|
163
|
+
throw "Query/mutation names are required for a document with multiple definitions";
|
|
164
|
+
} else {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
const opName = op.name.value;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-tag",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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",
|
|
7
7
|
"jsnext:main": "./src/index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"bundle": "rollup -c && cp src/index.js.flow lib/graphql-tag.umd.js.flow",
|
|
10
|
-
"test": "mocha --
|
|
10
|
+
"test": "mocha test/graphql.js test/graphql-v0.12.js && tav --ci --compat",
|
|
11
11
|
"prepublish": "npm run bundle"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
@@ -25,11 +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": "^0.13.0",
|
|
29
29
|
"mocha": "^3.4.1",
|
|
30
|
-
"rollup": "^0.45.0"
|
|
30
|
+
"rollup": "^0.45.0",
|
|
31
|
+
"test-all-versions": "^3.3.2"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0"
|
|
34
|
+
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0"
|
|
34
35
|
}
|
|
35
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;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const gqlRequire = require("../src");
|
|
2
|
+
const gqlDefault = require("../src").default;
|
|
3
|
+
const assert = require("chai").assert;
|
|
4
|
+
|
|
5
|
+
[gqlRequire, gqlDefault].forEach((gql, i) => {
|
|
6
|
+
describe(`gql ${i}`, () => {
|
|
7
|
+
it("is correct for a simple query", () => {
|
|
8
|
+
const ast = gql`
|
|
9
|
+
{
|
|
10
|
+
user(id: 5) {
|
|
11
|
+
firstName
|
|
12
|
+
lastName
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
assert.equal(ast.kind, "Document");
|
|
18
|
+
assert.deepEqual(ast.definitions, [
|
|
19
|
+
{
|
|
20
|
+
kind: "OperationDefinition",
|
|
21
|
+
operation: "query",
|
|
22
|
+
name: null,
|
|
23
|
+
variableDefinitions: null,
|
|
24
|
+
directives: [],
|
|
25
|
+
selectionSet: {
|
|
26
|
+
kind: "SelectionSet",
|
|
27
|
+
selections: [
|
|
28
|
+
{
|
|
29
|
+
kind: "Field",
|
|
30
|
+
alias: null,
|
|
31
|
+
name: {
|
|
32
|
+
kind: "Name",
|
|
33
|
+
value: "user"
|
|
34
|
+
},
|
|
35
|
+
arguments: [
|
|
36
|
+
{
|
|
37
|
+
kind: "Argument",
|
|
38
|
+
name: {
|
|
39
|
+
kind: "Name",
|
|
40
|
+
value: "id"
|
|
41
|
+
},
|
|
42
|
+
value: {
|
|
43
|
+
kind: "IntValue",
|
|
44
|
+
value: "5"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
directives: [],
|
|
49
|
+
selectionSet: {
|
|
50
|
+
kind: "SelectionSet",
|
|
51
|
+
selections: [
|
|
52
|
+
{
|
|
53
|
+
kind: "Field",
|
|
54
|
+
alias: null,
|
|
55
|
+
name: {
|
|
56
|
+
kind: "Name",
|
|
57
|
+
value: "firstName"
|
|
58
|
+
},
|
|
59
|
+
arguments: [],
|
|
60
|
+
directives: [],
|
|
61
|
+
selectionSet: null
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
kind: "Field",
|
|
65
|
+
alias: null,
|
|
66
|
+
name: {
|
|
67
|
+
kind: "Name",
|
|
68
|
+
value: "lastName"
|
|
69
|
+
},
|
|
70
|
+
arguments: [],
|
|
71
|
+
directives: [],
|
|
72
|
+
selectionSet: null
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
it("is correct for a fragment", () => {
|
|
83
|
+
const ast = gql`
|
|
84
|
+
fragment UserFragment on User {
|
|
85
|
+
firstName
|
|
86
|
+
lastName
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
assert.equal(ast.kind, "Document");
|
|
91
|
+
assert.deepEqual(ast.definitions, [
|
|
92
|
+
{
|
|
93
|
+
kind: "FragmentDefinition",
|
|
94
|
+
name: {
|
|
95
|
+
kind: "Name",
|
|
96
|
+
value: "UserFragment"
|
|
97
|
+
},
|
|
98
|
+
typeCondition: {
|
|
99
|
+
kind: "NamedType",
|
|
100
|
+
name: {
|
|
101
|
+
kind: "Name",
|
|
102
|
+
value: "User"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
directives: [],
|
|
106
|
+
selectionSet: {
|
|
107
|
+
kind: "SelectionSet",
|
|
108
|
+
selections: [
|
|
109
|
+
{
|
|
110
|
+
kind: "Field",
|
|
111
|
+
alias: null,
|
|
112
|
+
name: {
|
|
113
|
+
kind: "Name",
|
|
114
|
+
value: "firstName"
|
|
115
|
+
},
|
|
116
|
+
arguments: [],
|
|
117
|
+
directives: [],
|
|
118
|
+
selectionSet: null
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
kind: "Field",
|
|
122
|
+
alias: null,
|
|
123
|
+
name: {
|
|
124
|
+
kind: "Name",
|
|
125
|
+
value: "lastName"
|
|
126
|
+
},
|
|
127
|
+
arguments: [],
|
|
128
|
+
directives: [],
|
|
129
|
+
selectionSet: null
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const gqlRequire = require("../src");
|
|
2
|
+
const gqlDefault = require("../src").default;
|
|
3
|
+
const assert = require("chai").assert;
|
|
4
|
+
|
|
5
|
+
[gqlRequire, gqlDefault].forEach((gql, i) => {
|
|
6
|
+
describe(`gql ${i}`, () => {
|
|
7
|
+
it("is correct for a simple query", () => {
|
|
8
|
+
const ast = gql`
|
|
9
|
+
{
|
|
10
|
+
user(id: 5) {
|
|
11
|
+
firstName
|
|
12
|
+
lastName
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
assert.equal(ast.kind, "Document");
|
|
18
|
+
assert.deepEqual(ast.definitions, [
|
|
19
|
+
{
|
|
20
|
+
kind: "OperationDefinition",
|
|
21
|
+
operation: "query",
|
|
22
|
+
name: undefined,
|
|
23
|
+
variableDefinitions: [],
|
|
24
|
+
directives: [],
|
|
25
|
+
selectionSet: {
|
|
26
|
+
kind: "SelectionSet",
|
|
27
|
+
selections: [
|
|
28
|
+
{
|
|
29
|
+
kind: "Field",
|
|
30
|
+
alias: undefined,
|
|
31
|
+
name: {
|
|
32
|
+
kind: "Name",
|
|
33
|
+
value: "user"
|
|
34
|
+
},
|
|
35
|
+
arguments: [
|
|
36
|
+
{
|
|
37
|
+
kind: "Argument",
|
|
38
|
+
name: {
|
|
39
|
+
kind: "Name",
|
|
40
|
+
value: "id"
|
|
41
|
+
},
|
|
42
|
+
value: {
|
|
43
|
+
kind: "IntValue",
|
|
44
|
+
value: "5"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
directives: [],
|
|
49
|
+
selectionSet: {
|
|
50
|
+
kind: "SelectionSet",
|
|
51
|
+
selections: [
|
|
52
|
+
{
|
|
53
|
+
kind: "Field",
|
|
54
|
+
alias: undefined,
|
|
55
|
+
name: {
|
|
56
|
+
kind: "Name",
|
|
57
|
+
value: "firstName"
|
|
58
|
+
},
|
|
59
|
+
arguments: [],
|
|
60
|
+
directives: [],
|
|
61
|
+
selectionSet: undefined
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
kind: "Field",
|
|
65
|
+
alias: undefined,
|
|
66
|
+
name: {
|
|
67
|
+
kind: "Name",
|
|
68
|
+
value: "lastName"
|
|
69
|
+
},
|
|
70
|
+
arguments: [],
|
|
71
|
+
directives: [],
|
|
72
|
+
selectionSet: undefined
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("is correct for a fragment", () => {
|
|
84
|
+
const ast = gql`
|
|
85
|
+
fragment UserFragment on User {
|
|
86
|
+
firstName
|
|
87
|
+
lastName
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
assert.equal(ast.kind, "Document");
|
|
92
|
+
assert.deepEqual(ast.definitions, [
|
|
93
|
+
{
|
|
94
|
+
kind: "FragmentDefinition",
|
|
95
|
+
name: {
|
|
96
|
+
kind: "Name",
|
|
97
|
+
value: "UserFragment"
|
|
98
|
+
},
|
|
99
|
+
typeCondition: {
|
|
100
|
+
kind: "NamedType",
|
|
101
|
+
name: {
|
|
102
|
+
kind: "Name",
|
|
103
|
+
value: "User"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
directives: [],
|
|
107
|
+
selectionSet: {
|
|
108
|
+
kind: "SelectionSet",
|
|
109
|
+
selections: [
|
|
110
|
+
{
|
|
111
|
+
kind: "Field",
|
|
112
|
+
alias: undefined,
|
|
113
|
+
name: {
|
|
114
|
+
kind: "Name",
|
|
115
|
+
value: "firstName"
|
|
116
|
+
},
|
|
117
|
+
arguments: [],
|
|
118
|
+
directives: [],
|
|
119
|
+
selectionSet: undefined
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
kind: "Field",
|
|
123
|
+
alias: undefined,
|
|
124
|
+
name: {
|
|
125
|
+
kind: "Name",
|
|
126
|
+
value: "lastName"
|
|
127
|
+
},
|
|
128
|
+
arguments: [],
|
|
129
|
+
directives: [],
|
|
130
|
+
selectionSet: undefined
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|