graphql-tag 2.10.2 → 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 +20 -0
- package/README.md +131 -69
- 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 +28 -16
- 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,25 @@
|
|
|
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
|
+
|
|
8
|
+
### v2.11.0 (2020-07-28)
|
|
9
|
+
|
|
10
|
+
* `package.json` `sideEffects` changes to clearly identify that `graphql-tag` doesn't have side effects. <br/>
|
|
11
|
+
[@hwillson](http://github.com/hwillson) in [#313](https://github.com/apollographql/graphql-tag/pull/313)
|
|
12
|
+
|
|
13
|
+
### v2.10.4 (2020-07-08)
|
|
14
|
+
|
|
15
|
+
* Bump dev/peer deps to accommodate `graphql` 15. <br/>
|
|
16
|
+
[@adriencohen](https://github.com/adriencohen) in [#299](https://github.com/apollographql/graphql-tag/pull/299)
|
|
17
|
+
|
|
18
|
+
### v2.10.3 (2020-02-05)
|
|
19
|
+
|
|
20
|
+
* Further adjustments to the TS `index.d.ts` declaration file. <br/>
|
|
21
|
+
[@Guillaumez](https://github.com/Guillaumez) in [#289](https://github.com/apollographql/graphql-tag/pull/289)
|
|
22
|
+
|
|
3
23
|
### v2.10.2 (2020-02-04)
|
|
4
24
|
|
|
5
25
|
* Update/fix the existing TS `index.d.ts` declaration file. <br/>
|
package/README.md
CHANGED
|
@@ -8,11 +8,11 @@ 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
|
|
|
15
|
-
|
|
15
|
+
The `gql` template literal tag can be used to concisely write a GraphQL query that is parsed into a standard GraphQL AST. It is the recommended method for passing queries to [Apollo Client](https://github.com/apollographql/apollo-client). While it is primarily built for Apollo Client, it generates a generic GraphQL AST which can be used by any GraphQL client.
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
import gql from 'graphql-tag';
|
|
@@ -25,34 +25,68 @@ const query = gql`
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
`
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The above query now contains the following syntax tree.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
{
|
|
34
|
+
"kind": "Document",
|
|
35
|
+
"definitions": [
|
|
36
|
+
{
|
|
37
|
+
"kind": "OperationDefinition",
|
|
38
|
+
"operation": "query",
|
|
39
|
+
"name": null,
|
|
40
|
+
"variableDefinitions": null,
|
|
41
|
+
"directives": [],
|
|
42
|
+
"selectionSet": {
|
|
43
|
+
"kind": "SelectionSet",
|
|
44
|
+
"selections": [
|
|
45
|
+
{
|
|
46
|
+
"kind": "Field",
|
|
47
|
+
"alias": null,
|
|
48
|
+
"name": {
|
|
49
|
+
"kind": "Name",
|
|
50
|
+
"value": "user",
|
|
51
|
+
...
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Fragments
|
|
62
|
+
|
|
63
|
+
The `gql` tag can also be used to define reusable fragments, which can easily be added to queries or other fragments.
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import gql from 'graphql-tag';
|
|
28
67
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// {
|
|
36
|
-
// "kind": "OperationDefinition",
|
|
37
|
-
// "operation": "query",
|
|
38
|
-
// "name": null,
|
|
39
|
-
// "variableDefinitions": null,
|
|
40
|
-
// "directives": [],
|
|
41
|
-
// "selectionSet": {
|
|
42
|
-
// "kind": "SelectionSet",
|
|
43
|
-
// "selections": [
|
|
44
|
-
// {
|
|
45
|
-
// "kind": "Field",
|
|
46
|
-
// "alias": null,
|
|
47
|
-
// "name": {
|
|
48
|
-
// "kind": "Name",
|
|
49
|
-
// "value": "user",
|
|
50
|
-
// ...
|
|
68
|
+
const userFragment = gql`
|
|
69
|
+
fragment User_user on User {
|
|
70
|
+
firstName
|
|
71
|
+
lastName
|
|
72
|
+
}
|
|
73
|
+
`
|
|
51
74
|
```
|
|
52
75
|
|
|
53
|
-
|
|
76
|
+
The above `userFragment` document can be embedded in another document using a template literal placeholder.
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const query = gql`
|
|
80
|
+
{
|
|
81
|
+
user(id: 5) {
|
|
82
|
+
...User_user
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
${userFragment}
|
|
86
|
+
`
|
|
87
|
+
```
|
|
54
88
|
|
|
55
|
-
|
|
89
|
+
**Note:** _While it may seem redundant to have to both embed the `userFragment` variable in the template literal **AND** spread the `...User_user` fragment in the graphQL selection set, this requirement makes static analysis by tools such as `eslint-plugin-graphql` possible._
|
|
56
90
|
|
|
57
91
|
#### Why use this?
|
|
58
92
|
|
|
@@ -64,78 +98,100 @@ That's where this package comes in - it lets you write your queries with [ES2015
|
|
|
64
98
|
|
|
65
99
|
This package only has one feature - it caches previous parse results in a simple dictionary. This means that if you call the tag on the same query multiple times, it doesn't waste time parsing it again. It also means you can use `===` to compare queries to check if they are identical.
|
|
66
100
|
|
|
67
|
-
### Babel preprocessing
|
|
68
101
|
|
|
69
|
-
|
|
102
|
+
### Importing graphQL files
|
|
70
103
|
|
|
71
|
-
|
|
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).
|
|
104
|
+
_To add support for importing `.graphql`/`.gql` files, see [Webpack loading and preprocessing](#webpack-loading-and-preprocessing) below._
|
|
73
105
|
|
|
74
|
-
|
|
106
|
+
Given a file `MyQuery.graphql`
|
|
75
107
|
|
|
76
|
-
|
|
108
|
+
```graphql
|
|
109
|
+
query MyQuery {
|
|
110
|
+
...
|
|
111
|
+
}
|
|
112
|
+
```
|
|
77
113
|
|
|
78
|
-
|
|
79
|
-
```javascript
|
|
80
|
-
import myImportedQuery from './productsQuery.graphql'
|
|
114
|
+
If you have configured [the webpack graphql-tag/loader](#webpack-loading-and-preprocessing), you can import modules containing graphQL queries. The imported value will be the pre-built AST.
|
|
81
115
|
|
|
82
|
-
|
|
116
|
+
```graphql
|
|
117
|
+
import MyQuery from 'query.graphql'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### Importing queries by name
|
|
121
|
+
|
|
122
|
+
You can also import query and fragment documents by name.
|
|
123
|
+
|
|
124
|
+
```graphql
|
|
125
|
+
query MyQuery1 {
|
|
126
|
+
...
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
query MyQuery2 {
|
|
83
130
|
...
|
|
84
131
|
}
|
|
85
132
|
```
|
|
86
133
|
|
|
87
|
-
|
|
134
|
+
And in your JavaScript:
|
|
88
135
|
|
|
89
|
-
|
|
136
|
+
```javascript
|
|
137
|
+
import { MyQuery1, MyQuery2 } from 'query.graphql'
|
|
138
|
+
```
|
|
90
139
|
|
|
91
|
-
|
|
140
|
+
### Preprocessing queries and fragments
|
|
92
141
|
|
|
93
|
-
|
|
142
|
+
Preprocessing GraphQL queries and fragments into ASTs at build time can greatly improve load times.
|
|
94
143
|
|
|
95
|
-
|
|
144
|
+
#### Babel preprocessing
|
|
96
145
|
|
|
97
|
-
|
|
98
|
-
loaders: [
|
|
99
|
-
{
|
|
100
|
-
test: /\.(graphql|gql)$/,
|
|
101
|
-
exclude: /node_modules/,
|
|
102
|
-
loader: 'graphql-tag/loader'
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
```
|
|
146
|
+
GraphQL queries can be compiled at build time using [babel-plugin-graphql-tag](https://github.com/gajus/babel-plugin-graphql-tag). Pre-compiling queries decreases script initialization time and reduces bundle sizes by potentially removing the need for `graphql-tag` at runtime.
|
|
106
147
|
|
|
107
|
-
|
|
148
|
+
#### TypeScript preprocessing
|
|
108
149
|
|
|
109
|
-
|
|
110
|
-
import query from './query.graphql';
|
|
150
|
+
Try this custom transformer to pre-compile your GraphQL queries in TypeScript: [ts-transform-graphql-tag](https://github.com/firede/ts-transform-graphql-tag).
|
|
111
151
|
|
|
112
|
-
|
|
113
|
-
// {
|
|
114
|
-
// "kind": "Document",
|
|
115
|
-
// ...
|
|
116
|
-
```
|
|
152
|
+
#### React Native and Next.js preprocessing
|
|
117
153
|
|
|
118
|
-
|
|
154
|
+
Preprocessing queries via the webpack loader is not always possible. [babel-plugin-import-graphql](https://www.npmjs.com/package/babel-plugin-import-graphql) supports importing graphql files directly into your JavaScript by preprocessing GraphQL queries into ASTs at compile-time.
|
|
119
155
|
|
|
120
|
-
|
|
156
|
+
E.g.:
|
|
121
157
|
|
|
122
|
-
|
|
158
|
+
```javascript
|
|
159
|
+
import myImportedQuery from './productsQuery.graphql'
|
|
123
160
|
|
|
124
|
-
|
|
125
|
-
```graphql
|
|
126
|
-
query MyQuery1 {
|
|
161
|
+
class ProductsPage extends React.Component {
|
|
127
162
|
...
|
|
128
163
|
}
|
|
164
|
+
```
|
|
129
165
|
|
|
130
|
-
|
|
166
|
+
#### Webpack loading and preprocessing
|
|
167
|
+
|
|
168
|
+
Using the included `graphql-tag/loader` it is possible to maintain query logic that is separate from the rest of your application logic. With the loader configured, imported graphQL files will be converted to AST during the webpack build process.
|
|
169
|
+
|
|
170
|
+
_**Example webpack configuration**_
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
{
|
|
174
|
+
...
|
|
175
|
+
loaders: [
|
|
176
|
+
{
|
|
177
|
+
test: /\.(graphql|gql)$/,
|
|
178
|
+
exclude: /node_modules/,
|
|
179
|
+
loader: 'graphql-tag/loader'
|
|
180
|
+
}
|
|
181
|
+
],
|
|
131
182
|
...
|
|
132
183
|
}
|
|
133
184
|
```
|
|
134
185
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
186
|
+
#### Create React App
|
|
187
|
+
|
|
188
|
+
Preprocessing GraphQL imports is supported in **create-react-app** >= v2 using [evenchange4/graphql.macro](https://github.com/evenchange4/graphql.macro).
|
|
189
|
+
|
|
190
|
+
For **create-react-app** < v2, you'll either need to eject or use [react-app-rewire-inline-import-graphql-ast](https://www.npmjs.com/package/react-app-rewire-inline-import-graphql-ast).
|
|
191
|
+
|
|
192
|
+
#### Testing
|
|
193
|
+
|
|
194
|
+
Testing environments that don't support Webpack require additional configuration. For [Jest](https://facebook.github.io/jest/) use [jest-transform-graphql](https://github.com/remind101/jest-transform-graphql).
|
|
139
195
|
|
|
140
196
|
### Warnings
|
|
141
197
|
|
|
@@ -152,13 +208,19 @@ disableFragmentWarnings()
|
|
|
152
208
|
This package exports an `experimentalFragmentVariables` flag that allows you to use experimental support for [parameterized fragments](https://github.com/facebook/graphql/issues/204).
|
|
153
209
|
|
|
154
210
|
You can enable / disable this with:
|
|
211
|
+
|
|
155
212
|
```js
|
|
156
213
|
import { enableExperimentalFragmentVariables, disableExperimentalFragmentVariables } from 'graphql-tag';
|
|
157
214
|
```
|
|
158
215
|
|
|
159
216
|
Enabling this feature allows you declare documents of the form
|
|
217
|
+
|
|
160
218
|
```graphql
|
|
161
219
|
fragment SomeFragment ($arg: String!) on SomeType {
|
|
162
220
|
someField
|
|
163
221
|
}
|
|
164
222
|
```
|
|
223
|
+
|
|
224
|
+
### Resources
|
|
225
|
+
|
|
226
|
+
You can easily generate and explore a GraphQL AST on [astexplorer.net](https://astexplorer.net/#/drYr8X1rnP/1).
|
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
|