UNPKG

@txstate-mws/graphql-server

Version:

A simple graphql server designed to work with typegraphql.

58 lines (57 loc) 2.22 kB
import { HttpError } from 'fastify-txstate'; import { type GraphQLError } from 'graphql'; export declare enum MutationMessageType { error = "error", warning = "warning", success = "success" } export declare class MutationMessage { arg?: string; message: string; type: MutationMessageType; constructor(message: string, arg?: string, type?: MutationMessageType); } export interface ValidatedResponseArgs { success?: boolean; messages?: MutationMessage[]; } export declare class ValidatedResponse { success: boolean; messages: MutationMessage[]; constructor(config?: ValidatedResponseArgs); addMessage(message: string, arg?: string, type?: MutationMessageType): void; assert(condition: boolean, message: string, arg?: string): void; assertBetween(input: any, arg: string, min: number, max: number): void; assertPositive(input: any, arg: string): void; assertLength(input: any, arg: string, min: number, max: number): void; hasErrors(): boolean; /** * SomeSpecificTypeOfResponse.error('OMG fail', 'argName') * * Creates a new error response object for service layer to return upon fatal errors. * (e.g. permission denied, object ID does not exist, other "you shall not pass" types of errors) * * @param message Will be first item in the messages array * @param arg Name of the input argument this message relates to * @returns ValidatedResponse (whatever class this is being called from) */ static error<R extends ValidatedResponse>(this: new (config: any) => R, message: string, arg?: string): R; } export declare class UnimplementedError extends Error { constructor(); } export declare class GQLError extends Error { query: string; errors: readonly GraphQLError[]; constructor(message: string, query: string, errors: readonly GraphQLError[]); toString(): string; } export declare class ParseError extends GQLError { constructor(query: string, errors: readonly GraphQLError[]); } export declare class ExecutionError extends GQLError { constructor(query: string, errors: readonly GraphQLError[]); } export declare class AuthError extends HttpError { constructor(); }