From c7f83ba98c410c50b1385253e99da8d9ff19085b Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Mon, 29 May 2017 17:24:29 -0400 Subject: [PATCH 1/3] fix issue/61: split('/n') does not work on Windows --- loader.js | 7 ++++--- src/index.js | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/loader.js b/loader.js index a92f7a57..9127e831 100644 --- a/loader.js +++ b/loader.js @@ -1,12 +1,13 @@ "use strict"; +const os = require('os'); const gql = require('./src'); // 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'); + const lines = source.split(os.EOL); let outputCode = ` var names = {}; function unique(defs) { @@ -30,7 +31,7 @@ function expandImports(source, doc) { const importFile = line.slice(1).split(' ')[1]; const parseDocument = `require(${importFile})`; const appendDef = `doc.definitions = doc.definitions.concat(unique(${parseDocument}.definitions));`; - outputCode += appendDef + "\n"; + outputCode += appendDef + os.EOL; } return (line.length !== 0 && line[0] !== '#'); }); @@ -47,5 +48,5 @@ module.exports = function(source) { `; const importOutputCode = expandImports(source, doc); - return outputCode + "\n" + importOutputCode + "\n" + `module.exports = doc;`; + return outputCode + os.EOL + importOutputCode + os.EOL + `module.exports = doc;`; }; diff --git a/src/index.js b/src/index.js index 325fd44c..b3f766f1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +const os = require('os'); var parser = require('graphql/language/parser'); var parse = parser.parse; @@ -45,8 +46,8 @@ function processFragments(ast) { // this is a problem because the app developer is trying to register another fragment with // the same name as one previously registered. So, we tell them about it. if (printFragmentWarnings) { - console.warn("Warning: fragment with name " + fragmentName + " already exists.\n" - + "graphql-tag enforces all fragment names across your application to be unique; read more about\n" + console.warn("Warning: fragment with name " + fragmentName + " already exists." + os.EOL + + + "graphql-tag enforces all fragment names across your application to be unique; read more about" + os.EOL + + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); } From fc1304fa36254b8bb32263ddab978976e8835b9a Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Mon, 29 May 2017 17:34:45 -0400 Subject: [PATCH 2/3] remove redundant concat operator --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index b3f766f1..7469b589 100644 --- a/src/index.js +++ b/src/index.js @@ -47,8 +47,8 @@ function processFragments(ast) { // the same name as one previously registered. So, we tell them about it. if (printFragmentWarnings) { console.warn("Warning: fragment with name " + fragmentName + " already exists." + os.EOL + - + "graphql-tag enforces all fragment names across your application to be unique; read more about" + os.EOL + - + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); + "graphql-tag enforces all fragment names across your application to be unique; read more about" + os.EOL + + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); } fragmentSourceMap[fragmentName][sourceKey] = true; From d5fd8ee4a865e98d6967e7e59074a4b55921fa32 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Mon, 29 May 2017 18:53:16 -0400 Subject: [PATCH 3/3] revert src/index.js changes --- src/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 7469b589..325fd44c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,3 @@ -const os = require('os'); var parser = require('graphql/language/parser'); var parse = parser.parse; @@ -46,9 +45,9 @@ function processFragments(ast) { // this is a problem because the app developer is trying to register another fragment with // the same name as one previously registered. So, we tell them about it. if (printFragmentWarnings) { - console.warn("Warning: fragment with name " + fragmentName + " already exists." + os.EOL + - "graphql-tag enforces all fragment names across your application to be unique; read more about" + os.EOL + - "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); + console.warn("Warning: fragment with name " + fragmentName + " already exists.\n" + + "graphql-tag enforces all fragment names across your application to be unique; read more about\n" + + "this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names"); } fragmentSourceMap[fragmentName][sourceKey] = true;