graphql-tag
Advanced tools
Comparing version 1.1.2 to 1.1.3
const gql = require('./'); | ||
// Takes `source` (the source GraphQL query string) | ||
// and `doc` (the parsed GraphQL document) and tacks on | ||
// the imported definitions. | ||
function expandImports(source, doc) { | ||
const lines = source.split('\n'); | ||
let outputCode = ""; | ||
lines.some((line) => { | ||
if (line[0] === '#' && line.slice(1).split(' ')[0] === 'import') { | ||
const importFile = line.slice(1).split(' ')[1]; | ||
const parseDocument = `require(${importFile})`; | ||
const appendDef = `doc.definitions = doc.definitions.concat(${parseDocument}.definitions);`; | ||
outputCode += appendDef + "\n"; | ||
} | ||
return (line.length !== 0 && line[0] !== '#'); | ||
}); | ||
return outputCode; | ||
} | ||
module.exports = function(source) { | ||
this.cacheable(); | ||
return `module.exports = ${JSON.stringify(gql`${source}`)};`; | ||
const doc = gql`${source}`; | ||
const outputCode = `const doc = ${JSON.stringify(doc)};`; | ||
const importOutputCode = expandImports(source, doc); | ||
return outputCode + "\n" + importOutputCode + "\n" + `module.exports = doc;`; | ||
}; |
{ | ||
"name": "graphql-tag", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A JavaScript template literal tag that parses GraphQL queries", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -92,2 +92,5 @@ # graphql-tag | ||
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). | ||
### Parser and printer | ||
@@ -94,0 +97,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114432
3228
107
1