From 2c73b0fe50fe8c7018f59224215fd78923d3ae8a Mon Sep 17 00:00:00 2001 From: Matthew Erwin Date: Wed, 22 Mar 2017 16:35:41 -0400 Subject: [PATCH 1/3] Support use case of gql(``) vs gql`` Current implementation throws an exception that the query isn't valid without providing information that the document was reduced to a single character by the implementation. Either the software should elegantly handle the case when parenthesis are added to the function call or else return a useful error on usage. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 36cdbc7a..325fd44c 100644 --- a/src/index.js +++ b/src/index.js @@ -146,7 +146,7 @@ function gql(/* arguments */) { var literals = args[0]; // We always get literals[0] and then matching post literals for each arg given - var result = literals[0]; + var result = (typeof(literals) === "string") ? literals : literals[0]; for (var i = 1; i < args.length; i++) { if (args[i] && args[i].kind && args[i].kind === 'Document') { From 950a8c9cb7004a4c838737dd7cf44a3b66e45968 Mon Sep 17 00:00:00 2001 From: Jon Wong Date: Wed, 10 May 2017 18:56:23 -0700 Subject: [PATCH 2/3] Adding test --- test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.js b/test.js index 4c938dfc..a05f2512 100644 --- a/test.js +++ b/test.js @@ -9,6 +9,10 @@ const assert = require('chai').assert; assert.equal(gql`{ testQuery }`.kind, 'Document'); }); + it('parses queries when called as a function', () => { + assert.equal(gql('{ testQuery }').kind, 'Document'); + }); + it('parses queries with weird substitutions', () => { const obj = {}; assert.equal(gql`{ field(input: "${obj.missing}") }`.kind, 'Document'); From e26c4370d99af49db29603215dd928af03e37d84 Mon Sep 17 00:00:00 2001 From: Jon Wong Date: Wed, 10 May 2017 18:58:53 -0700 Subject: [PATCH 3/3] Adding to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f60c5efa..05226ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Change log ### vNEXT +- Add support for calling `gql` as a function [matthewerwin](https://github.com/matthewerwin) in [PR #66](https://github.com/apollographql/graphql-tag/pull/66) ### v2.0.0 Restore dependence on `graphql` module [abhiaiyer91](https://github.com/abhiaiyer91) in [PR #46](https://github.com/apollographql/graphql-tag/pull/46) addressing [#6](https://github.com/apollographql/graphql-tag/issues/6)