Repository: apollographql/apollo-client

Problem statement:
Decide on a more elegant solution to make `gql` work with npm link
To fix the current `npm-link` issue, where the module `apollo-client/gql` cannot be found, we will place `gql.js` in the root of the repo and redirect it to `lib/src/`gql.js`.

After a deep discussion about separate modules or not, we decided to go ahead with the current strategy while we think of something better to do. 

This is that issue.



Hints:
I also ran into the same issue when importing from `writeToStore` and `readFromStore` in relation to #180. Hopefully not nearly as important long-term as `gql`, but I thought it worth mentioning anyway.

@stubailo when do you think we can get the hacky version in. Again if you just wanna write down what you want, im sure we can do it

PR [#243](https://github.com/apollostack/apollo-client/pull/243) will place gql in root. Circle back later for elegant fix


Patch:
diff --git a/gql.js b/gql.js
--- a/gql.js
+++ b/gql.js
@@ -1,4 +1,2 @@
-/* We are placing this file in the root to enable npm-link development
- * Currently, gql resides in a submodule and is not able to be imported when linked
- */
-module.exports = require('./lib/src/gql');
+// This is here for backcompat, even though the right way is to use the other package
+module.exports = require('graphql-tag');
diff --git a/src/gql.ts b/src/gql.ts
deleted file mode 100644
--- a/src/gql.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { parse } from 'graphql/language/parser';
-
-import {
-  Document,
-} from 'graphql';
-
-const cache: {[queryString: string]: Document} = {};
-
-function parseDocument(doc: string): Document {
-  if (cache[doc]) {
-    return cache[doc];
-  }
-
-  const parsed = parse(doc);
-
-  if (!parsed || parsed.kind !== 'Document') {
-    throw new Error('Not a valid GraphQL document.');
-  }
-
-  cache[doc] = parsed;
-
-  return parsed as Document;
-}
-
-// XXX This should eventually disallow arbitrary string interpolation, like Relay does
-export default function gql(literals, ...substitutions): Document {
-  let result = '';
-
-  // run the loop only for the substitution count
-  for (let i = 0; i < substitutions.length; i++) {
-      result += literals[i];
-      result += substitutions[i];
-  }
-
-  // add the last literal
-  result += literals[literals.length - 1];
-
-  return parseDocument(result);
-}
-
-export function registerGqlTag() {
-  if (typeof window !== 'undefined') {
-    window['gql'] = gql;
-  } else if (typeof global !== 'undefined') {
-    global['gql'] = gql;
-  }
-}


Test patch:
diff --git a/test/QueryManager.ts b/test/QueryManager.ts
--- a/test/QueryManager.ts
+++ b/test/QueryManager.ts
@@ -15,7 +15,7 @@ import {
   addTypenameToSelectionSet,
 } from '../src/queries/queryTransform';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 import {
   assert,
diff --git a/test/batching.ts b/test/batching.ts
--- a/test/batching.ts
+++ b/test/batching.ts
@@ -5,7 +5,7 @@ import { assert } from 'chai';
 import mockNetworkInterface, {
   mockBatchedNetworkInterface,
 } from './mocks/mockNetworkInterface';
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 import { GraphQLResult } from 'graphql';
 
 const networkInterface = mockNetworkInterface();
diff --git a/test/client.ts b/test/client.ts
--- a/test/client.ts
+++ b/test/client.ts
@@ -18,7 +18,7 @@ import {
   Store,
 } from '../src/store';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 import {
   createStore,
diff --git a/test/diffAgainstStore.ts b/test/diffAgainstStore.ts
--- a/test/diffAgainstStore.ts
+++ b/test/diffAgainstStore.ts
@@ -12,7 +12,7 @@ import {
   NormalizedCache,
 } from '../src/data/store';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 describe('diffing queries against the store', () => {
   it('returns nothing when the store is enough', () => {
diff --git a/test/directives.ts b/test/directives.ts
--- a/test/directives.ts
+++ b/test/directives.ts
@@ -9,7 +9,7 @@ import {
   getQueryDefinition,
 } from '../src/queries/getFromAST';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 import cloneDeep = require('lodash.clonedeep');
 
diff --git a/test/getFromAST.ts b/test/getFromAST.ts
--- a/test/getFromAST.ts
+++ b/test/getFromAST.ts
@@ -14,7 +14,7 @@ import {
   OperationDefinition,
 } from 'graphql';
 import { print } from 'graphql/language/printer';
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 import { assert } from 'chai';
 
 describe('AST utility functions', () => {
diff --git a/test/gql.ts b/test/gql.ts
deleted file mode 100644
--- a/test/gql.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { assert } from 'chai';
-
-import gql from '../src/gql';
-
-describe('gql', () => {
-  it('parses queries', () => {
-    assert.equal(gql`{ testQuery }`.kind, 'Document');
-  });
-
-  it('returns the same object for the same query', () => {
-    assert.isTrue(gql`{ sameQuery }` === gql`{ sameQuery }`);
-  });
-});
diff --git a/test/networkInterface.ts b/test/networkInterface.ts
--- a/test/networkInterface.ts
+++ b/test/networkInterface.ts
@@ -19,7 +19,7 @@ import {
   MiddlewareRequest,
 } from '../src/middleware';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 import { print } from 'graphql/language/printer';
 
diff --git a/test/queryMerging.ts b/test/queryMerging.ts
--- a/test/queryMerging.ts
+++ b/test/queryMerging.ts
@@ -25,7 +25,7 @@ import {
   OperationDefinition,
 } from 'graphql';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 import { assert } from 'chai';
 import cloneDeep = require('lodash.clonedeep');
 
diff --git a/test/queryTransform.ts b/test/queryTransform.ts
--- a/test/queryTransform.ts
+++ b/test/queryTransform.ts
@@ -8,7 +8,7 @@ import {
   getMutationDefinition,
 } from '../src/queries/getFromAST';
 import { print } from 'graphql/language/printer';
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 import { assert } from 'chai';
 
 describe('query transforms', () => {
diff --git a/test/readFromStore.ts b/test/readFromStore.ts
--- a/test/readFromStore.ts
+++ b/test/readFromStore.ts
@@ -10,7 +10,7 @@ import {
   StoreObject,
 } from '../src/data/store';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 describe('reading from the store', () => {
   it('rejects malformed queries', () => {
diff --git a/test/roundtrip.ts b/test/roundtrip.ts
--- a/test/roundtrip.ts
+++ b/test/roundtrip.ts
@@ -7,7 +7,7 @@ import {
   Document,
 } from 'graphql';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 describe('roundtrip', () => {
   it('real graphql result', () => {
diff --git a/test/scheduler.ts b/test/scheduler.ts
--- a/test/scheduler.ts
+++ b/test/scheduler.ts
@@ -8,7 +8,7 @@ import {
   createApolloStore,
 } from '../src/store';
 import mockNetworkInterface from './mocks/mockNetworkInterface';
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 describe('QueryScheduler', () => {
   it('should throw an error if we try to register a non-polling query', () => {
diff --git a/test/tests.ts b/test/tests.ts
--- a/test/tests.ts
+++ b/test/tests.ts
@@ -16,7 +16,6 @@ import './networkInterface';
 import './QueryManager';
 import './client';
 import './store';
-import './gql';
 import './queryTransform';
 import './getFromAST';
 import './directives';
diff --git a/test/writeToStore.ts b/test/writeToStore.ts
--- a/test/writeToStore.ts
+++ b/test/writeToStore.ts
@@ -23,7 +23,7 @@ import {
   Node,
 } from 'graphql';
 
-import gql from '../src/gql';
+import gql from 'graphql-tag';
 
 describe('writing to the store', () => {
   it('properly normalizes a trivial item', () => {