mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 11:02:11 +08:00
Improved testing and add property "context" in OptionsObj
This commit is contained in:
@@ -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);
|
||||
|
||||
5
express-graphql/express-graphql.d.ts
vendored
5
express-graphql/express-graphql.d.ts
vendored
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user