graphql-server-express
Advanced tools
Comparing version
"use strict"; | ||
const expressApollo_1 = require("./expressApollo"); | ||
var expressApollo_1 = require("./expressApollo"); | ||
exports.graphqlConnect = expressApollo_1.graphqlExpress; | ||
exports.graphiqlConnect = expressApollo_1.graphiqlExpress; | ||
//# sourceMappingURL=connectApollo.js.map |
@@ -0,1 +1,2 @@ | ||
/// <reference types="@types/es6-shim" /> | ||
import * as express from 'express'; | ||
@@ -2,0 +3,0 @@ import { GraphQLOptions } from 'graphql-server-core'; |
"use strict"; | ||
const url = require("url"); | ||
const graphql_server_core_1 = require("graphql-server-core"); | ||
const GraphiQL = require("graphql-server-module-graphiql"); | ||
var url = require("url"); | ||
var graphql_server_core_1 = require("graphql-server-core"); | ||
var GraphiQL = require("graphql-server-module-graphiql"); | ||
function graphqlExpress(options) { | ||
@@ -10,5 +10,5 @@ if (!options) { | ||
if (arguments.length > 1) { | ||
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length}`); | ||
throw new Error("Apollo Server expects exactly one argument, got " + arguments.length); | ||
} | ||
return (req, res) => { | ||
return function (req, res) { | ||
graphql_server_core_1.runHttpQuery([req, res], { | ||
@@ -18,7 +18,7 @@ method: req.method, | ||
query: req.method === 'POST' ? req.body : req.query, | ||
}).then((gqlResponse) => { | ||
}).then(function (gqlResponse) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.write(gqlResponse); | ||
res.end(); | ||
}, (error) => { | ||
}, function (error) { | ||
if ('HttpQueryError' !== error.name) { | ||
@@ -28,3 +28,3 @@ throw error; | ||
if (error.headers) { | ||
Object.keys(error.headers).forEach((header) => { | ||
Object.keys(error.headers).forEach(function (header) { | ||
res.setHeader(header, error.headers[header]); | ||
@@ -41,11 +41,10 @@ }); | ||
function graphiqlExpress(options) { | ||
return (req, res) => { | ||
const q = req.url && url.parse(req.url, true).query || {}; | ||
const query = q.query || ''; | ||
const variables = q.variables || '{}'; | ||
const operationName = q.operationName || ''; | ||
const graphiQLString = GraphiQL.renderGraphiQL({ | ||
return function (req, res) { | ||
var q = req.url && url.parse(req.url, true).query || {}; | ||
var query = q.query || ''; | ||
var operationName = q.operationName || ''; | ||
var graphiQLString = GraphiQL.renderGraphiQL({ | ||
endpointURL: options.endpointURL, | ||
query: query || options.query, | ||
variables: JSON.parse(variables) || options.variables, | ||
variables: q.variables && JSON.parse(q.variables) || options.variables, | ||
operationName: operationName || options.operationName, | ||
@@ -52,0 +51,0 @@ passHeader: options.passHeader, |
{ | ||
"name": "graphql-server-express", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Production-ready Node.js GraphQL server for Express and Connect", | ||
@@ -29,4 +29,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"graphql-server-core": "^0.5.1", | ||
"graphql-server-module-graphiql": "^0.4.4" | ||
"graphql-server-core": "^0.5.2", | ||
"graphql-server-module-graphiql": "^0.5.2" | ||
}, | ||
@@ -36,10 +36,10 @@ "devDependencies": { | ||
"@types/connect": "^3.4.30", | ||
"@types/express": "^4.0.33", | ||
"@types/express": "^4.0.35", | ||
"@types/multer": "0.0.32", | ||
"graphql-server-integration-testsuite": "^0.5.1", | ||
"body-parser": "^1.15.2", | ||
"connect": "^3.4.1", | ||
"body-parser": "^1.16.0", | ||
"connect": "^3.5.0", | ||
"connect-query": "^0.2.0", | ||
"express": "^4.14.0", | ||
"multer": "^1.2.0" | ||
"graphql-server-integration-testsuite": "^0.5.2", | ||
"multer": "^1.2.1" | ||
}, | ||
@@ -50,4 +50,4 @@ "peerDependencies": { | ||
"optionalDependencies": { | ||
"@types/express": "^4.0.33", | ||
"@types/graphql": "^0.8.5" | ||
"@types/express": "^4.0.35", | ||
"@types/graphql": "^0.8.6" | ||
}, | ||
@@ -54,0 +54,0 @@ "typings": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
+ Added
- Removed
Updated