graphql-tag
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -26,3 +26,4 @@ var parse = require('graphql/language/parser').parse; | ||
var literals = args[0]; | ||
var substitutions = args.shift(); | ||
args.shift(); | ||
var substitutions = args; | ||
@@ -29,0 +30,0 @@ var result = ''; |
{ | ||
"name": "graphql-tag", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A JavaScript template literal tag that parses GraphQL queries", | ||
@@ -26,4 +26,5 @@ "main": "index.js", | ||
"chai": "^3.5.0", | ||
"lodash": "^4.13.1", | ||
"mocha": "^2.5.3" | ||
} | ||
} |
95
test.js
var gqlRequire = require('./index'); | ||
var gqlDefault = require('./index').default; | ||
import { assert } from 'chai'; | ||
import _ from 'lodash'; | ||
function stripLoc(obj) { | ||
if (_.isArray(obj)) { | ||
return obj.map(stripLoc); | ||
} | ||
if (! _.isObject(obj)) { | ||
return obj; | ||
} | ||
const omitted = _.omit(obj, ['loc']); | ||
return _.mapValues(omitted, (value) => { | ||
return stripLoc(value); | ||
}); | ||
} | ||
[gqlRequire, gqlDefault].forEach((gql, i) => { | ||
@@ -14,3 +31,81 @@ describe(`gql ${i}`, () => { | ||
}); | ||
it('is correct for a simple query', () => { | ||
const ast = stripLoc(gql` | ||
{ | ||
user(id: 5) { | ||
firstName | ||
lastName | ||
} | ||
} | ||
`); | ||
assert.deepEqual(ast, { | ||
"kind": "Document", | ||
"definitions": [ | ||
{ | ||
"kind": "OperationDefinition", | ||
"operation": "query", | ||
"name": null, | ||
"variableDefinitions": null, | ||
"directives": [], | ||
"selectionSet": { | ||
"kind": "SelectionSet", | ||
"selections": [ | ||
{ | ||
"kind": "Field", | ||
"alias": null, | ||
"name": { | ||
"kind": "Name", | ||
"value": "user" | ||
}, | ||
"arguments": [ | ||
{ | ||
"kind": "Argument", | ||
"name": { | ||
"kind": "Name", | ||
"value": "id" | ||
}, | ||
"value": { | ||
"kind": "IntValue", | ||
"value": "5" | ||
} | ||
} | ||
], | ||
"directives": [], | ||
"selectionSet": { | ||
"kind": "SelectionSet", | ||
"selections": [ | ||
{ | ||
"kind": "Field", | ||
"alias": null, | ||
"name": { | ||
"kind": "Name", | ||
"value": "firstName" | ||
}, | ||
"arguments": [], | ||
"directives": [], | ||
"selectionSet": null | ||
}, | ||
{ | ||
"kind": "Field", | ||
"alias": null, | ||
"name": { | ||
"kind": "Name", | ||
"value": "lastName" | ||
}, | ||
"arguments": [], | ||
"directives": [], | ||
"selectionSet": null | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}) | ||
}) | ||
}); | ||
}); |
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
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
7151
134
5