mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
Merge pull request #24438 from mlamp/master
Changed types reflecting flow types, added validationRules
This commit is contained in:
@@ -1,31 +1,45 @@
|
||||
import express = require('express');
|
||||
import 'express-session';
|
||||
import graphqlHTTP = require('express-graphql');
|
||||
import { GraphQLSchema } from 'graphql/type/schema';
|
||||
|
||||
const app = express();
|
||||
const schema = {};
|
||||
const schema: GraphQLSchema = {
|
||||
getQueryType: null,
|
||||
getMutationType: null,
|
||||
getSubscriptionType: null,
|
||||
getTypeMap: null,
|
||||
getType: null,
|
||||
getPossibleTypes: null,
|
||||
isPossibleType: null,
|
||||
getDirective: null,
|
||||
getDirectives: null,
|
||||
};
|
||||
|
||||
const graphqlOption: graphqlHTTP.OptionsObj = {
|
||||
const graphqlOption: graphqlHTTP.OptionsData = {
|
||||
graphiql: true,
|
||||
schema: schema,
|
||||
schema,
|
||||
formatError: (error: Error) => ({
|
||||
message: error.message
|
||||
}),
|
||||
extensions: (args) => { }
|
||||
validationRules: [() => false, () => true],
|
||||
extensions: ({ document, variables, operationName, result }) => ({ key: "value", key2: "value"}),
|
||||
};
|
||||
|
||||
const graphqlOptionRequest = (request: express.Request, response: express.Response): graphqlHTTP.OptionsObj => ({
|
||||
const graphqlOptionRequest = (request: express.Request): graphqlHTTP.OptionsData => ({
|
||||
graphiql: true,
|
||||
schema: schema,
|
||||
context: request.session
|
||||
schema,
|
||||
context: request.session,
|
||||
validationRules: [() => false, () => true],
|
||||
});
|
||||
|
||||
const graphqlOptionRequestAsync = async (request: express.Request, response: express.Response): Promise<graphqlHTTP.OptionsObj> => {
|
||||
const graphqlOptionRequestAsync = async (request: express.Request): Promise<graphqlHTTP.OptionsData> => {
|
||||
return {
|
||||
graphiql: true,
|
||||
schema: await Promise.resolve(schema),
|
||||
context: request.session,
|
||||
extensions: async (args) => { }
|
||||
extensions: async (args) => { },
|
||||
validationRules: [() => false, () => true],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
86
types/express-graphql/index.d.ts
vendored
86
types/express-graphql/index.d.ts
vendored
@@ -1,14 +1,15 @@
|
||||
// Type definitions for express-graphql
|
||||
// Project: https://www.npmjs.org/package/express-graphql
|
||||
// Type definitions for express-graphql 0.6
|
||||
// Project: https://github.com/graphql/express-graphql
|
||||
// Definitions by: Isman Usoh <https://github.com/isman-usoh>
|
||||
// Nitin Tutlani <https://github.com/nitintutlani>
|
||||
// Daniel Fader <https://github.com/hubel>
|
||||
// Ehsan Ziya <https://github.com/zya>
|
||||
// Margus Lamp <https://github.com/mlamp>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import { DocumentNode, GraphQLSchema, GraphQLError } from 'graphql';
|
||||
export = graphqlHTTP;
|
||||
|
||||
declare namespace graphqlHTTP {
|
||||
@@ -16,60 +17,99 @@ declare namespace graphqlHTTP {
|
||||
* Used to configure the graphQLHTTP middleware by providing a schema
|
||||
* and other configuration options.
|
||||
*/
|
||||
export type Options = ((req: Request, res: Response) => OptionsObj) | ((req: Request, res: Response) => Promise<OptionsObj>) | OptionsObj
|
||||
export type OptionsObj = {
|
||||
export type Options = ((request: Request,
|
||||
response: Response,
|
||||
params?: GraphQLParams) => OptionsResult) | OptionsResult;
|
||||
export type OptionsResult = OptionsData | Promise<OptionsData>;
|
||||
export interface OptionsData {
|
||||
/**
|
||||
* A GraphQL schema from graphql-js.
|
||||
*/
|
||||
schema: Object,
|
||||
schema: GraphQLSchema;
|
||||
|
||||
/**
|
||||
* A value to pass as the context to the graphql() function.
|
||||
*/
|
||||
context?: Object,
|
||||
context?: any;
|
||||
|
||||
/**
|
||||
* An object to pass as the rootValue to the graphql() function.
|
||||
*/
|
||||
rootValue?: Object,
|
||||
rootValue?: any;
|
||||
|
||||
/**
|
||||
* A boolean to configure whether the output should be pretty-printed.
|
||||
*/
|
||||
pretty?: boolean,
|
||||
pretty?: boolean;
|
||||
|
||||
/**
|
||||
* An optional function which will be used to format any errors produced by
|
||||
* fulfilling a GraphQL operation. If no function is provided, GraphQL's
|
||||
* default spec-compliant `formatError` function will be used.
|
||||
*/
|
||||
formatError?: Function,
|
||||
formatError?: (error: GraphQLError) => any;
|
||||
|
||||
/**
|
||||
* An optional array of validation rules that will be applied on the document
|
||||
* in additional to those defined by the GraphQL spec.
|
||||
*/
|
||||
validationRules?: any[];
|
||||
|
||||
/**
|
||||
* An optional function for adding additional metadata to the GraphQL response
|
||||
* as a key-value object. The result will be added to "extensions" field in
|
||||
* the resulting JSON. This is often a useful place to add development time
|
||||
* info such as the runtime of a query or the amount of resources consumed.
|
||||
*
|
||||
* Information about the request is provided to be used.
|
||||
*
|
||||
* This function may be async.
|
||||
*/
|
||||
extensions?: (info: RequestInfo) => { [key: string]: any };
|
||||
|
||||
/**
|
||||
* A boolean to optionally enable GraphiQL mode.
|
||||
*/
|
||||
graphiql?: boolean,
|
||||
graphiql?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* All information about a GraphQL request.
|
||||
*/
|
||||
export interface RequestInfo {
|
||||
/**
|
||||
* The parsed GraphQL document.
|
||||
*/
|
||||
document?: DocumentNode;
|
||||
|
||||
/**
|
||||
* An optional function for adding additional metadata to the GraphQL response as a key-value object.
|
||||
* The result will be added to "extensions" field in the resulting JSON.
|
||||
* The variable values used at runtime.
|
||||
*/
|
||||
extensions?: ((args: ExtenstionsArgs) => any) | ((args: ExtenstionsArgs) => Promise<any>);
|
||||
variables?: { [name: string]: any };
|
||||
|
||||
};
|
||||
/**
|
||||
* The (optional) operation name requested.
|
||||
*/
|
||||
operationName?: string;
|
||||
|
||||
interface ExtenstionsArgs {
|
||||
document: object,
|
||||
variables: object,
|
||||
operationName: any,
|
||||
result: object
|
||||
/**
|
||||
* The result of executing the operation.
|
||||
*/
|
||||
result?: any;
|
||||
}
|
||||
|
||||
export interface GraphQLParams {
|
||||
query?: string;
|
||||
variables?: { [name: string]: any };
|
||||
operationName?: string;
|
||||
raw?: boolean;
|
||||
}
|
||||
|
||||
type Middleware = (request: Request, response: Response) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Middleware for express; takes an options object or function as input to
|
||||
* configure behavior, and returns an express middleware.
|
||||
*/
|
||||
* Middleware for express; takes an options object or function as input to
|
||||
* configure behavior, and returns an express middleware.
|
||||
*/
|
||||
declare function graphqlHTTP(options: graphqlHTTP.Options): graphqlHTTP.Middleware;
|
||||
|
||||
@@ -1,79 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
"strict-export-declare-modifiers": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user