Improved testing and add property "context" in OptionsObj

This commit is contained in:
Donat Perler
2016-06-26 16:34:57 +08:00
parent 97080f10db
commit 754b0e01ac
2 changed files with 29 additions and 5 deletions

View File

@@ -1,10 +1,29 @@
/// <reference path="./express-graphql.d.ts" />
/// <reference path="../express/express.d.ts" />
/// <reference path="../express-session/express-session.d.ts" />
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);

View File

@@ -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.
*/