Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support use case of gql() vs gql #66

Merged
merged 3 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down