Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-tag

Package Overview
Dependencies
Maintainers
4
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-tag - npm Package Compare versions

Comparing version 2.12.3 to 2.12.4

5

CHANGELOG.md
# Change log
### v2.12.4 (2021-04-29)
* Allow fragments to be imported by name when using the webpack loader. <br/>
[@dobesv](https://github.com/dobesv) in [#257](https://github.com/apollographql/graphql-tag/pull/257)
### v2.12.2

@@ -4,0 +9,0 @@

@@ -218,2 +218,11 @@ 'use strict';

chai.assert.equal(Q3[2].name.value, 'F2');
var F1 = module.exports.F1.definitions;
var F2 = module.exports.F2.definitions;
var F3 = module.exports.F3.definitions;
chai.assert.equal(F1.length, 1);
chai.assert.equal(F1[0].name.value, 'F1');
chai.assert.equal(F2.length, 1);
chai.assert.equal(F2[0].name.value, 'F2');
chai.assert.equal(F3.length, 1);
chai.assert.equal(F3[0].name.value, 'F3');
});

@@ -234,2 +243,14 @@ it('tracks fragment dependencies across nested fragments', function () {

chai.assert.equal(Q2.length, 1);
var F11 = module.exports.F11.definitions;
var F22 = module.exports.F22.definitions;
var F33 = module.exports.F33.definitions;
chai.assert.equal(F11.length, 1);
chai.assert.equal(F11[0].name.value, 'F11');
chai.assert.equal(F22.length, 2);
chai.assert.equal(F22[0].name.value, 'F22');
chai.assert.equal(F22[1].name.value, 'F11');
chai.assert.equal(F33.length, 3);
chai.assert.equal(F33[0].name.value, 'F33');
chai.assert.equal(F33[1].name.value, 'F22');
chai.assert.equal(F33[2].name.value, 'F11');
});

@@ -236,0 +257,0 @@ it('correctly imports other files through the webpack loader', function () {

@@ -97,2 +97,11 @@ import { __makeTemplateObject } from "tslib";

assert.equal(Q3[2].name.value, 'F2');
var F1 = module.exports.F1.definitions;
var F2 = module.exports.F2.definitions;
var F3 = module.exports.F3.definitions;
assert.equal(F1.length, 1);
assert.equal(F1[0].name.value, 'F1');
assert.equal(F2.length, 1);
assert.equal(F2[0].name.value, 'F2');
assert.equal(F3.length, 1);
assert.equal(F3[0].name.value, 'F3');
});

@@ -113,2 +122,14 @@ it('tracks fragment dependencies across nested fragments', function () {

assert.equal(Q2.length, 1);
var F11 = module.exports.F11.definitions;
var F22 = module.exports.F22.definitions;
var F33 = module.exports.F33.definitions;
assert.equal(F11.length, 1);
assert.equal(F11[0].name.value, 'F11');
assert.equal(F22.length, 2);
assert.equal(F22[0].name.value, 'F22');
assert.equal(F22[1].name.value, 'F11');
assert.equal(F33.length, 3);
assert.equal(F33[0].name.value, 'F33');
assert.equal(F33[1].name.value, 'F22');
assert.equal(F33[2].name.value, 'F11');
});

@@ -115,0 +136,0 @@ it('correctly imports other files through the webpack loader', function () {

6

loader.js

@@ -56,3 +56,3 @@ "use strict";

let operationCount = doc.definitions.reduce(function(accum, op) {
if (op.kind === "OperationDefinition") {
if (op.kind === "OperationDefinition" || op.kind === "FragmentDefinition") {
return accum + 1;

@@ -165,3 +165,3 @@ }

}
module.exports = doc;

@@ -171,3 +171,3 @@ `

for (const op of doc.definitions) {
if (op.kind === "OperationDefinition") {
if (op.kind === "OperationDefinition" || op.kind === "FragmentDefinition") {
if (!op.name) {

@@ -174,0 +174,0 @@ if (operationCount > 1) {

{
"name": "graphql-tag",
"version": "2.12.3",
"version": "2.12.4",
"description": "A JavaScript template literal tag that parses GraphQL queries",

@@ -50,3 +50,3 @@ "main": "./main.js",

"test-all-versions": "^5.0.1",
"typescript": "^4.1.3"
"typescript": "^4.2.4"
},

@@ -53,0 +53,0 @@ "peerDependencies": {

@@ -196,2 +196,27 @@ # graphql-tag

#### Support for fragments
With the webpack loader, you can import fragments by name:
In a file called `query.gql`:
```graphql
fragment MyFragment1 on MyType1 {
...
}
fragment MyFragment2 on MyType2 {
...
}
```
And in your JavaScript:
```javascript
import { MyFragment1, MyFragment2 } from 'query.gql'
```
Note: If your fragment references other fragments, the resulting document will
have multiple fragments in it. In this case you must still specify the fragment name when using the fragment. For example, with `@apollo/client` you would specify the `fragmentName` option when using the fragment for cache operations.
### Warnings

@@ -198,0 +223,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc