mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-05-19 18:54:37 +00:00
Add type definitions for graphql-errors
This commit is contained in:
47
types/graphql-errors/graphql-errors-tests.ts
Normal file
47
types/graphql-errors/graphql-errors-tests.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { GraphQLSchema, buildSchema } from 'graphql';
|
||||
import {
|
||||
UserError,
|
||||
maskErrors,
|
||||
handlerFunction,
|
||||
setDefaultHandler
|
||||
} from 'graphql-errors';
|
||||
|
||||
// $ExpectType GraphQLSchema
|
||||
const schema: GraphQLSchema = buildSchema(`
|
||||
# graphql schema definition
|
||||
`);
|
||||
|
||||
const customHandler: handlerFunction = err => {
|
||||
return { ...err, message: 'Internal error' };
|
||||
};
|
||||
|
||||
/**
|
||||
* Mask GraphQL error messages
|
||||
*/
|
||||
|
||||
// $ExpectType void
|
||||
maskErrors(schema);
|
||||
|
||||
// $ExpectType void
|
||||
maskErrors(schema, customHandler);
|
||||
|
||||
// $ExpectError
|
||||
maskErrors('schema');
|
||||
|
||||
/**
|
||||
* Set callback function that modifies the errors
|
||||
*/
|
||||
|
||||
// $ExpectType void
|
||||
setDefaultHandler(customHandler);
|
||||
|
||||
// $ExpectError
|
||||
setDefaultHandler();
|
||||
|
||||
// $ExpectError
|
||||
setDefaultHandler(err => {});
|
||||
|
||||
/**
|
||||
* Thrown an user error
|
||||
*/
|
||||
new UserError("Uh, Houston, we've had a problem");
|
||||
17
types/graphql-errors/index.d.ts
vendored
Normal file
17
types/graphql-errors/index.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Type definitions for graphql-errors 2.1
|
||||
// Project: https://github.com/kadirahq/graphql-errors
|
||||
// Definitions by: Matías Olivera <https://github.com/MatiasOlivera>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import { GraphQLSchema } from 'graphql';
|
||||
|
||||
export type handlerFunction = (err: Error) => Error;
|
||||
|
||||
export function setDefaultHandler(fn: handlerFunction): void;
|
||||
|
||||
export function maskErrors(schema: GraphQLSchema, fn?: handlerFunction): void;
|
||||
|
||||
export class UserError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
16
types/graphql-errors/tsconfig.json
Normal file
16
types/graphql-errors/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "esnext.asynciterable"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": ["index.d.ts", "graphql-errors-tests.ts"]
|
||||
}
|
||||
1
types/graphql-errors/tslint.json
Normal file
1
types/graphql-errors/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user