From 754b0e01ac5483ccc8ae34793847f7024624b35b Mon Sep 17 00:00:00 2001 From: Donat Perler Date: Sun, 26 Jun 2016 16:34:57 +0800 Subject: [PATCH] Improved testing and add property "context" in OptionsObj --- express-graphql/express-graphql-tests.ts | 29 ++++++++++++++++++++---- express-graphql/express-graphql.d.ts | 5 ++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/express-graphql/express-graphql-tests.ts b/express-graphql/express-graphql-tests.ts index ec9e48ea43..7469a0801d 100644 --- a/express-graphql/express-graphql-tests.ts +++ b/express-graphql/express-graphql-tests.ts @@ -1,10 +1,29 @@ /// /// +/// -var express = require("express"); -var graphqlHTTP = require("express-graphql"); -var app = express(); +import * as express from "express"; +import * as graphqlHTTP from "express-graphql"; -var schema = {}; +const app = express(); +const schema = {}; -app.use("/graphql", graphqlHTTP({ schema: schema, graphiql: true })); +const graphqlOption: graphqlHTTP.OptionsObj = { + graphiql: true, + schema: schema, + formatError: (error:Error) => ({ + message: error.message, + }) +}; + +const graphqlOptionRequest = (request: express.Request): graphqlHTTP.OptionsObj => ({ + graphiql: true, + schema: schema, + context: request.session, +}); + +app.use("/graphql1", graphqlHTTP(graphqlOption)); + +app.use("/graphql2", graphqlHTTP(graphqlOptionRequest)); + +app.listen(8080); diff --git a/express-graphql/express-graphql.d.ts b/express-graphql/express-graphql.d.ts index ecaa2dc43a..e5f42f5839 100644 --- a/express-graphql/express-graphql.d.ts +++ b/express-graphql/express-graphql.d.ts @@ -20,6 +20,11 @@ declare module "express-graphql" { */ schema:Object, + /** + * A value to pass as the context to the graphql() function. + */ + context?:Object, + /** * An object to pass as the rootValue to the graphql() function. */