mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
add koa-graphql types (#36619)
* add koa-graphql types * fix ts version * fix tests and lint
This commit is contained in:
parent
f667351f06
commit
a72e5b0e7c
83
types/koa-graphql/index.d.ts
vendored
Normal file
83
types/koa-graphql/index.d.ts
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
// Type definitions for koa-graphql 0.8
|
||||
// Project: https://github.com/chentsulin/koa-graphql
|
||||
// Definitions by: Matheus Gonçalves da Silva <https://github.com/PlayMa256>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Context, Request, Response, Middleware } from "koa";
|
||||
import {
|
||||
GraphQLError,
|
||||
GraphQLSchema,
|
||||
GraphQLFieldResolver,
|
||||
ValidationContext,
|
||||
ASTVisitor
|
||||
} from "graphql";
|
||||
import { GraphQLParams, RequestInfo } from "express-graphql";
|
||||
|
||||
export type Options =
|
||||
| ((request: Request, repsonse: Response, ctx: Context) => OptionsResult)
|
||||
| OptionsResult;
|
||||
|
||||
export type OptionsResult = OptionsData | Promise<OptionsData>;
|
||||
|
||||
export interface OptionsData {
|
||||
/**
|
||||
* A GraphQL schema from graphql-js.
|
||||
*/
|
||||
schema: GraphQLSchema;
|
||||
|
||||
/**
|
||||
* A value to pass as the context to this middleware.
|
||||
*/
|
||||
context?: any;
|
||||
|
||||
/**
|
||||
* An object to pass as the rootvalue to the graphql() function.
|
||||
*/
|
||||
rootValue?: any;
|
||||
|
||||
/**
|
||||
* A boolean to configure whether the output should be pretty-printed.
|
||||
*/
|
||||
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?: (error: GraphQLError, context?: any) => any;
|
||||
|
||||
/**
|
||||
* An optional array of validation rules that will be applied on the document
|
||||
* in addition to those defined by the GraphQL spec.
|
||||
*/
|
||||
validationRules?: Array<(arg0: ValidationContext) => ASTVisitor>;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A resolver function to use when one is not provided by the schema.
|
||||
* If not provided, the default field resolver is used (which looks for a
|
||||
* value or method on the source value with the field's name).
|
||||
*/
|
||||
fieldResolver?: GraphQLFieldResolver<any, any>;
|
||||
}
|
||||
|
||||
export default function graphqlHTTP(options: Options): Middleware;
|
||||
19
types/koa-graphql/koa-graphql-tests.ts
Normal file
19
types/koa-graphql/koa-graphql-tests.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import * as Koa from 'koa';
|
||||
import * as mount from 'koa-mount';
|
||||
import graphqlHTTP from 'koa-graphql';
|
||||
import { buildSchema } from 'graphql';
|
||||
|
||||
const schema = buildSchema(`type Query { hello: String }`);
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
app.use(
|
||||
mount(
|
||||
'/graphql',
|
||||
graphqlHTTP(req => {
|
||||
return {
|
||||
schema,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
24
types/koa-graphql/tsconfig.json
Normal file
24
types/koa-graphql/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"esnext.asynciterable"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"strictFunctionTypes": true,
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"koa-graphql-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/koa-graphql/tslint.json
Normal file
1
types/koa-graphql/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user