@dashdot/graphql-server
Advanced tools
@@ -1,1 +0,7 @@ | ||
| export default function createGraphqlRequestHandler(store: any, context: any, processFileUploads: any): (req: any, res: any) => Promise<void>; | ||
| import { IncomingMessage } from 'http'; | ||
| export default function createGraphqlRequestHandler(store: any, context: any, processFileUploads?: any): (req: IncomingMessage, res: { | ||
| writeHead: (arg0: number, arg1?: { | ||
| 'Content-Type': string; | ||
| } | undefined) => void; | ||
| end: (arg0: string) => void; | ||
| }) => Promise<void>; |
@@ -6,7 +6,7 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const processGraphqlRequest_1 = __importDefault(require("./processGraphqlRequest")); | ||
| const utils_1 = require("./utils"); | ||
| const processGraphqlRequest_1 = __importDefault(require("./processGraphqlRequest")); | ||
| function createGraphqlRequestHandler(store, context, processFileUploads) { | ||
| return async (req, res) => { | ||
| const { status, text, body, } = await (0, processGraphqlRequest_1.default)(req, { | ||
| const { status, text, body } = await (0, processGraphqlRequest_1.default)(req, { | ||
| store, | ||
@@ -23,3 +23,3 @@ context, | ||
| res.writeHead(status, { | ||
| 'Content-Type': 'application/json' | ||
| 'Content-Type': 'application/json', | ||
| }); | ||
@@ -26,0 +26,0 @@ res.end(JSON.stringify(body)); |
+25
-31
@@ -1,39 +0,33 @@ | ||
| export class GraphqlError extends Error { | ||
| constructor(message: string | undefined, code: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlError extends Error { | ||
| originalError: any; | ||
| code: string; | ||
| code: string | null; | ||
| extensions: any; | ||
| static CODE: string; | ||
| errors?: any; | ||
| constructor(message?: string, code?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlError { | ||
| export { INTERNAL_SERVER_ERROR as CODE }; | ||
| export declare class GraphqlValidationError extends GraphqlError { | ||
| constructor(message?: string, originalError?: Error | null, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export class GraphqlValidationError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlContextError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlValidationError { | ||
| export { VALIDATION_ERROR as CODE }; | ||
| export declare class GraphqlUnauthorizedError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export class GraphqlContextError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlUserInputError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlContextError { | ||
| export { CONTEXT_ERROR as CODE }; | ||
| export declare class GraphqlErrorWithMessageAndOriginalError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any); | ||
| } | ||
| export class GraphqlUnauthorizedError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| } | ||
| export namespace GraphqlUnauthorizedError { | ||
| export { UNAUTHORIZED_ERROR as CODE }; | ||
| } | ||
| export class GraphqlUserInputError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| } | ||
| export namespace GraphqlUserInputError { | ||
| export { USER_INPUT_ERROR as CODE }; | ||
| } | ||
| declare const INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR"; | ||
| declare const VALIDATION_ERROR: "VALIDATION_ERROR"; | ||
| declare const CONTEXT_ERROR: "CONTEXT_ERROR"; | ||
| declare const UNAUTHORIZED_ERROR: "UNAUTHORIZED_ERROR"; | ||
| declare const USER_INPUT_ERROR: "USER_INPUT_ERROR"; | ||
| export {}; |
+20
-10
| "use strict"; | ||
| /* eslint-disable default-param-last */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.GraphqlUserInputError = exports.GraphqlUnauthorizedError = exports.GraphqlContextError = exports.GraphqlValidationError = exports.GraphqlError = void 0; | ||
| /* eslint-disable default-param-last */ | ||
| exports.GraphqlErrorWithMessageAndOriginalError = exports.GraphqlUserInputError = exports.GraphqlUnauthorizedError = exports.GraphqlContextError = exports.GraphqlValidationError = exports.GraphqlError = void 0; | ||
| /* eslint-disable max-classes-per-file */ | ||
@@ -12,5 +12,10 @@ const INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR'; | ||
| class GraphqlError extends Error { | ||
| originalError; | ||
| code; | ||
| extensions; | ||
| static CODE; | ||
| errors; | ||
| constructor(message = 'Something went wrong', code = INTERNAL_SERVER_ERROR, originalError, extensions) { | ||
| super(message); | ||
| this.originalError = originalError; | ||
| this.originalError = originalError || null; | ||
| this.code = code; | ||
@@ -21,12 +26,10 @@ if (!this.name) { | ||
| if (extensions) { | ||
| Object | ||
| .keys(extensions) | ||
| .filter((key) => key !== 'message' && key !== 'extensions') | ||
| .forEach((key) => { | ||
| this[key] = extensions[key]; | ||
| }); | ||
| const { errors } = extensions; | ||
| if (errors) { | ||
| this.errors = errors; | ||
| } | ||
| } | ||
| this.extensions = { | ||
| ...extensions, | ||
| code | ||
| code, | ||
| }; | ||
@@ -69,1 +72,8 @@ } | ||
| GraphqlUserInputError.CODE = USER_INPUT_ERROR; | ||
| class GraphqlErrorWithMessageAndOriginalError extends GraphqlError { | ||
| constructor(message = 'Something went wrong', originalError) { | ||
| super(message, undefined, originalError); | ||
| this.name = 'GraphqlErrorWithMessageAndOriginalError'; | ||
| } | ||
| } | ||
| exports.GraphqlErrorWithMessageAndOriginalError = GraphqlErrorWithMessageAndOriginalError; |
@@ -0,4 +1,10 @@ | ||
| import { GraphQLSchema } from 'graphql'; | ||
| export default class GraphqlQueryStore { | ||
| constructor(schema: any, { validationRules, queryComplexity: { maximumComplexity, defaultComplexity, } }?: { | ||
| validationRules?: any[] | undefined; | ||
| schema: GraphQLSchema; | ||
| validationRules: any; | ||
| maximumComplexity: number; | ||
| defaultComplexity: number; | ||
| store: Map<string, any>; | ||
| constructor(schema: GraphQLSchema, { validationRules, queryComplexity: { maximumComplexity, defaultComplexity }, }?: { | ||
| validationRules?: never[] | undefined; | ||
| queryComplexity?: { | ||
@@ -9,12 +15,7 @@ maximumComplexity?: number | undefined; | ||
| }); | ||
| schema: any; | ||
| validationRules: any[]; | ||
| maximumComplexity: number; | ||
| defaultComplexity: number; | ||
| store: Map<any, any>; | ||
| createId(query: any): string; | ||
| get(id: any): any; | ||
| has(id: any): boolean; | ||
| createId(query: string): string; | ||
| get(id: string): any; | ||
| has(id: string): boolean; | ||
| generateValidationRules(variables: any): any[]; | ||
| create(query: any, variables: any): import("graphql-jit").CompiledQuery<{ | ||
| create(query: string, variables: any): import("graphql-jit").CompiledQuery<{ | ||
| [key: string]: any; | ||
@@ -21,0 +22,0 @@ }, { |
@@ -5,9 +5,14 @@ "use strict"; | ||
| /* eslint-disable class-methods-use-this */ | ||
| const crypto_1 = require("crypto"); | ||
| const graphql_1 = require("graphql"); | ||
| const graphql_jit_1 = require("graphql-jit"); | ||
| const graphql_query_complexity_1 = require("graphql-query-complexity"); | ||
| const crypto_1 = require("crypto"); | ||
| const errors_1 = require("./errors"); | ||
| class GraphqlQueryStore { | ||
| constructor(schema, { validationRules = [], queryComplexity: { maximumComplexity = 1000, defaultComplexity = 1, } = {} } = {}) { | ||
| schema; | ||
| validationRules; | ||
| maximumComplexity; | ||
| defaultComplexity; | ||
| store; | ||
| constructor(schema, { validationRules = [], queryComplexity: { maximumComplexity = 1000, defaultComplexity = 1 } = {}, } = {}) { | ||
| this.schema = schema; | ||
@@ -33,12 +38,6 @@ this.validationRules = validationRules; | ||
| maximumComplexity: this.maximumComplexity, | ||
| estimators: [ | ||
| (0, graphql_query_complexity_1.simpleEstimator)({ defaultComplexity: this.defaultComplexity }) | ||
| ], | ||
| estimators: [(0, graphql_query_complexity_1.simpleEstimator)({ defaultComplexity: this.defaultComplexity })], | ||
| variables, | ||
| }); | ||
| return [ | ||
| ...graphql_1.specifiedRules, | ||
| complexityRule, | ||
| ...this.validationRules, | ||
| ]; | ||
| return [...graphql_1.specifiedRules, complexityRule, ...this.validationRules]; | ||
| } | ||
@@ -49,3 +48,3 @@ create(query, variables) { | ||
| throw new errors_1.GraphqlValidationError('Invalid query.', null, { | ||
| errors: validationErrors | ||
| errors: validationErrors, | ||
| }); | ||
@@ -56,3 +55,3 @@ } | ||
| throw new errors_1.GraphqlValidationError('Invalid query.', null, { | ||
| errors: compiledQuery.errors | ||
| errors: compiledQuery.errors, | ||
| }); | ||
@@ -59,0 +58,0 @@ } |
@@ -1,4 +0,4 @@ | ||
| export { default as createGraphqlRequestHandler } from "./createGraphqlRequestHandler"; | ||
| export { default as GraphqlQueryStore } from "./GraphqlQueryStore"; | ||
| export { default as processGraphqlRequest } from "./processGraphqlRequest"; | ||
| export * from "./errors"; | ||
| export { default as createGraphqlRequestHandler } from './createGraphqlRequestHandler'; | ||
| export { default as GraphqlQueryStore } from './GraphqlQueryStore'; | ||
| export { default as processGraphqlRequest } from './processGraphqlRequest'; | ||
| export * from './errors'; |
@@ -1,12 +0,14 @@ | ||
| export default function processGraphqlRequest(req: any, { store, context, processFileUploads, readRequestBody, }: { | ||
| /// <reference types="node" /> | ||
| import { IncomingMessage } from 'http'; | ||
| type GraphqlResponse = { | ||
| status: number; | ||
| text?: string; | ||
| body?: any; | ||
| }; | ||
| export default function processGraphqlRequest(req: IncomingMessage, { store, context, processFileUploads, readRequestBody, }: { | ||
| store: any; | ||
| context?: {} | undefined; | ||
| processFileUploads: any; | ||
| readRequestBody: any; | ||
| }): Promise<{ | ||
| status: number; | ||
| text: string; | ||
| } | { | ||
| status: number; | ||
| body: any; | ||
| }>; | ||
| context: any; | ||
| processFileUploads: (req: IncomingMessage) => Promise<any>; | ||
| readRequestBody: (req: IncomingMessage) => Promise<any>; | ||
| }): Promise<GraphqlResponse>; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| // eslint-disable-next-line import/extensions | ||
| const errors_1 = require("./errors"); | ||
| const responses_1 = require("./responses"); | ||
| const errors_1 = require("./errors"); | ||
| async function processGraphqlRequest(req, { store, context = {}, processFileUploads, readRequestBody, }) { | ||
@@ -7,0 +6,0 @@ if (!store) { |
@@ -1,16 +0,28 @@ | ||
| export function methodNotAllowed(text?: string): { | ||
| export declare const methodNotAllowed: (text?: string) => { | ||
| status: number; | ||
| text: string; | ||
| }; | ||
| export function badRequest(text?: string): { | ||
| export declare const badRequest: (text?: string) => { | ||
| status: number; | ||
| text: string; | ||
| }; | ||
| export function json(body: any, status?: number): { | ||
| export declare const json: (body: { | ||
| message: string; | ||
| errors: any; | ||
| }, status?: number) => { | ||
| status: number; | ||
| body: any; | ||
| body: { | ||
| message: string; | ||
| errors: any; | ||
| }; | ||
| }; | ||
| export function badRequestJson(result: any): { | ||
| export declare const badRequestJson: (result: { | ||
| message: string; | ||
| errors: any; | ||
| }) => { | ||
| status: number; | ||
| body: any; | ||
| body: { | ||
| message: string; | ||
| errors: any; | ||
| }; | ||
| }; |
@@ -6,11 +6,11 @@ "use strict"; | ||
| const METHOD_NOT_ALLOWED = 405; | ||
| const BED_REQUEST = 400; | ||
| const BAD_REQUEST = 400; | ||
| const methodNotAllowed = (text = 'Method Not Allowed') => ({ | ||
| status: METHOD_NOT_ALLOWED, | ||
| text | ||
| text, | ||
| }); | ||
| exports.methodNotAllowed = methodNotAllowed; | ||
| const badRequest = (text = 'Bad Request') => ({ | ||
| status: BED_REQUEST, | ||
| text | ||
| status: BAD_REQUEST, | ||
| text, | ||
| }); | ||
@@ -23,3 +23,3 @@ exports.badRequest = badRequest; | ||
| exports.json = json; | ||
| const badRequestJson = (result) => ((0, exports.json)(result, BED_REQUEST)); | ||
| const badRequestJson = (result) => (0, exports.json)(result, BAD_REQUEST); | ||
| exports.badRequestJson = badRequestJson; |
+17
-13
| /// <reference types="node" /> | ||
| export function createTestClient(server: any, headers: any): GraphQLClient; | ||
| export function createTestServer(handler: any): Promise<http.Server>; | ||
| export class RequestMock extends EventEmitter { | ||
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import { EventEmitter } from 'events'; | ||
| import { GraphQLClient } from 'graphql-request'; | ||
| import http from 'http'; | ||
| export declare function createTestClient(server: { | ||
| uri: string; | ||
| }, headers?: {}): GraphQLClient; | ||
| export declare function createTestServer(handler: http.RequestListener | undefined): Promise<http.Server>; | ||
| export declare class RequestMock extends EventEmitter { | ||
| method: string; | ||
| headers?: any; | ||
| constructor({ method }?: { | ||
| method?: string | undefined; | ||
| }); | ||
| method: string; | ||
| headers: {}; | ||
| send(data: any): void; | ||
| send(data: WithImplicitCoercion<string | Uint8Array | readonly number[]>): void; | ||
| } | ||
| export class ResponseMock extends EventEmitter { | ||
| constructor(); | ||
| export declare class ResponseMock extends EventEmitter { | ||
| data: any; | ||
| statusCode: any; | ||
| headers: any; | ||
| writeHead: import("jest-mock").Mock<(statusCode: any, headers: any) => void>; | ||
| end: import("jest-mock").Mock<(data: any) => void>; | ||
| writeHead: any; | ||
| end: any; | ||
| constructor(); | ||
| } | ||
| import { GraphQLClient } from "graphql-request"; | ||
| import http from "http"; | ||
| import { EventEmitter } from "events"; |
+10
-2
@@ -10,6 +10,6 @@ "use strict"; | ||
| const events_1 = require("events"); | ||
| const graphql_request_1 = require("graphql-request"); | ||
| const http_1 = __importDefault(require("http")); | ||
| const test_listen_1 = __importDefault(require("test-listen")); | ||
| const graphql_request_1 = require("graphql-request"); | ||
| function createTestClient(server, headers) { | ||
| function createTestClient(server, headers = {}) { | ||
| return new graphql_request_1.GraphQLClient(server.uri, { headers }); | ||
@@ -21,2 +21,3 @@ } | ||
| const uri = await (0, test_listen_1.default)(server); | ||
| // @ts-ignore | ||
| server.uri = uri; | ||
@@ -27,2 +28,4 @@ return server; | ||
| class RequestMock extends events_1.EventEmitter { | ||
| method; | ||
| headers; | ||
| constructor({ method = 'POST' } = {}) { | ||
@@ -48,2 +51,7 @@ super(); | ||
| class ResponseMock extends events_1.EventEmitter { | ||
| data; | ||
| statusCode; | ||
| headers; | ||
| writeHead; | ||
| end; | ||
| constructor() { | ||
@@ -50,0 +58,0 @@ super(); |
@@ -1,5 +0,6 @@ | ||
| export function readRequestBody(req: any): Promise<any>; | ||
| export function methodNotAllowed(res: any, message?: string): void; | ||
| export function badRequest(res: any, message?: string): void; | ||
| export function json(res: any, result: any, statusCode?: number): void; | ||
| export function badRequestJson(res: any, result: any): void; | ||
| import { IncomingMessage, ServerResponse } from 'http'; | ||
| export declare const readRequestBody: (req: IncomingMessage) => Promise<unknown>; | ||
| export declare const methodNotAllowed: (res: ServerResponse, message?: string) => void; | ||
| export declare const badRequest: (res: ServerResponse, message?: string) => void; | ||
| export declare const json: (res: ServerResponse, result: any, statusCode?: number) => void; | ||
| export declare const badRequestJson: (res: any, result: any) => void; |
@@ -6,10 +6,9 @@ "use strict"; | ||
| const METHOD_NOT_ALLOWED = 405; | ||
| const BED_REQUEST = 400; | ||
| const readRequestBody = (req) => (new Promise((resolve, reject) => { | ||
| const BAD_REQUEST = 400; | ||
| const readRequestBody = (req) => new Promise((resolve, reject) => { | ||
| const body = []; | ||
| req | ||
| .on('data', (chunk) => body.push(chunk)) | ||
| req.on('data', (chunk) => body.push(chunk)) | ||
| .on('error', (error) => reject(error)) | ||
| .on('end', () => resolve(JSON.parse(Buffer.concat(body).toString()))); | ||
| })); | ||
| }); | ||
| exports.readRequestBody = readRequestBody; | ||
@@ -22,3 +21,3 @@ const methodNotAllowed = (res, message = 'Method Not Allowed') => { | ||
| const badRequest = (res, message = 'Bad Request') => { | ||
| res.writeHead(BED_REQUEST); | ||
| res.writeHead(BAD_REQUEST); | ||
| res.end(message); | ||
@@ -29,3 +28,3 @@ }; | ||
| res.writeHead(statusCode, { | ||
| 'Content-Type': 'application/json' | ||
| 'Content-Type': 'application/json', | ||
| }); | ||
@@ -35,3 +34,3 @@ res.end(JSON.stringify(result)); | ||
| exports.json = json; | ||
| const badRequestJson = (res, result) => ((0, exports.json)(res, result, BED_REQUEST)); | ||
| const badRequestJson = (res, result) => (0, exports.json)(res, result, BAD_REQUEST); | ||
| exports.badRequestJson = badRequestJson; |
@@ -1,1 +0,7 @@ | ||
| export default function createGraphqlRequestHandler(store: any, context: any, processFileUploads: any): (req: any, res: any) => Promise<void>; | ||
| import { IncomingMessage } from 'http'; | ||
| export default function createGraphqlRequestHandler(store: any, context: any, processFileUploads?: any): (req: IncomingMessage, res: { | ||
| writeHead: (arg0: number, arg1?: { | ||
| 'Content-Type': string; | ||
| } | undefined) => void; | ||
| end: (arg0: string) => void; | ||
| }) => Promise<void>; |
@@ -0,6 +1,6 @@ | ||
| import processGraphqlRequest from './processGraphqlRequest'; | ||
| import { readRequestBody } from './utils'; | ||
| import processGraphqlRequest from './processGraphqlRequest'; | ||
| export default function createGraphqlRequestHandler(store, context, processFileUploads) { | ||
| return async (req, res) => { | ||
| const { status, text, body, } = await processGraphqlRequest(req, { | ||
| const { status, text, body } = await processGraphqlRequest(req, { | ||
| store, | ||
@@ -17,3 +17,3 @@ context, | ||
| res.writeHead(status, { | ||
| 'Content-Type': 'application/json' | ||
| 'Content-Type': 'application/json', | ||
| }); | ||
@@ -20,0 +20,0 @@ res.end(JSON.stringify(body)); |
+25
-31
@@ -1,39 +0,33 @@ | ||
| export class GraphqlError extends Error { | ||
| constructor(message: string | undefined, code: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlError extends Error { | ||
| originalError: any; | ||
| code: string; | ||
| code: string | null; | ||
| extensions: any; | ||
| static CODE: string; | ||
| errors?: any; | ||
| constructor(message?: string, code?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlError { | ||
| export { INTERNAL_SERVER_ERROR as CODE }; | ||
| export declare class GraphqlValidationError extends GraphqlError { | ||
| constructor(message?: string, originalError?: Error | null, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export class GraphqlValidationError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlContextError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlValidationError { | ||
| export { VALIDATION_ERROR as CODE }; | ||
| export declare class GraphqlUnauthorizedError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export class GraphqlContextError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| export declare class GraphqlUserInputError extends GraphqlError { | ||
| constructor(message?: string, originalError?: any, extensions?: { | ||
| errors: any; | ||
| }); | ||
| } | ||
| export namespace GraphqlContextError { | ||
| export { CONTEXT_ERROR as CODE }; | ||
| export declare class GraphqlErrorWithMessageAndOriginalError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any); | ||
| } | ||
| export class GraphqlUnauthorizedError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| } | ||
| export namespace GraphqlUnauthorizedError { | ||
| export { UNAUTHORIZED_ERROR as CODE }; | ||
| } | ||
| export class GraphqlUserInputError extends GraphqlError { | ||
| constructor(message: string | undefined, originalError: any, extensions: any); | ||
| } | ||
| export namespace GraphqlUserInputError { | ||
| export { USER_INPUT_ERROR as CODE }; | ||
| } | ||
| declare const INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR"; | ||
| declare const VALIDATION_ERROR: "VALIDATION_ERROR"; | ||
| declare const CONTEXT_ERROR: "CONTEXT_ERROR"; | ||
| declare const UNAUTHORIZED_ERROR: "UNAUTHORIZED_ERROR"; | ||
| declare const USER_INPUT_ERROR: "USER_INPUT_ERROR"; | ||
| export {}; |
+17
-8
@@ -9,5 +9,10 @@ /* eslint-disable default-param-last */ | ||
| export class GraphqlError extends Error { | ||
| originalError; | ||
| code; | ||
| extensions; | ||
| static CODE; | ||
| errors; | ||
| constructor(message = 'Something went wrong', code = INTERNAL_SERVER_ERROR, originalError, extensions) { | ||
| super(message); | ||
| this.originalError = originalError; | ||
| this.originalError = originalError || null; | ||
| this.code = code; | ||
@@ -18,12 +23,10 @@ if (!this.name) { | ||
| if (extensions) { | ||
| Object | ||
| .keys(extensions) | ||
| .filter((key) => key !== 'message' && key !== 'extensions') | ||
| .forEach((key) => { | ||
| this[key] = extensions[key]; | ||
| }); | ||
| const { errors } = extensions; | ||
| if (errors) { | ||
| this.errors = errors; | ||
| } | ||
| } | ||
| this.extensions = { | ||
| ...extensions, | ||
| code | ||
| code, | ||
| }; | ||
@@ -61,1 +64,7 @@ } | ||
| GraphqlUserInputError.CODE = USER_INPUT_ERROR; | ||
| export class GraphqlErrorWithMessageAndOriginalError extends GraphqlError { | ||
| constructor(message = 'Something went wrong', originalError) { | ||
| super(message, undefined, originalError); | ||
| this.name = 'GraphqlErrorWithMessageAndOriginalError'; | ||
| } | ||
| } |
@@ -0,4 +1,10 @@ | ||
| import { GraphQLSchema } from 'graphql'; | ||
| export default class GraphqlQueryStore { | ||
| constructor(schema: any, { validationRules, queryComplexity: { maximumComplexity, defaultComplexity, } }?: { | ||
| validationRules?: any[] | undefined; | ||
| schema: GraphQLSchema; | ||
| validationRules: any; | ||
| maximumComplexity: number; | ||
| defaultComplexity: number; | ||
| store: Map<string, any>; | ||
| constructor(schema: GraphQLSchema, { validationRules, queryComplexity: { maximumComplexity, defaultComplexity }, }?: { | ||
| validationRules?: never[] | undefined; | ||
| queryComplexity?: { | ||
@@ -9,12 +15,7 @@ maximumComplexity?: number | undefined; | ||
| }); | ||
| schema: any; | ||
| validationRules: any[]; | ||
| maximumComplexity: number; | ||
| defaultComplexity: number; | ||
| store: Map<any, any>; | ||
| createId(query: any): string; | ||
| get(id: any): any; | ||
| has(id: any): boolean; | ||
| createId(query: string): string; | ||
| get(id: string): any; | ||
| has(id: string): boolean; | ||
| generateValidationRules(variables: any): any[]; | ||
| create(query: any, variables: any): import("graphql-jit").CompiledQuery<{ | ||
| create(query: string, variables: any): import("graphql-jit").CompiledQuery<{ | ||
| [key: string]: any; | ||
@@ -21,0 +22,0 @@ }, { |
| /* eslint-disable max-classes-per-file */ | ||
| /* eslint-disable class-methods-use-this */ | ||
| import { validate, parse, specifiedRules } from 'graphql'; | ||
| import { createHash } from 'crypto'; | ||
| import { parse, specifiedRules, validate } from 'graphql'; | ||
| import { compileQuery, isCompiledQuery } from 'graphql-jit'; | ||
| import { createComplexityRule, simpleEstimator } from 'graphql-query-complexity'; | ||
| import { createHash } from 'crypto'; | ||
| import { GraphqlValidationError } from './errors'; | ||
| export default class GraphqlQueryStore { | ||
| constructor(schema, { validationRules = [], queryComplexity: { maximumComplexity = 1000, defaultComplexity = 1, } = {} } = {}) { | ||
| schema; | ||
| validationRules; | ||
| maximumComplexity; | ||
| defaultComplexity; | ||
| store; | ||
| constructor(schema, { validationRules = [], queryComplexity: { maximumComplexity = 1000, defaultComplexity = 1 } = {}, } = {}) { | ||
| this.schema = schema; | ||
@@ -30,12 +35,6 @@ this.validationRules = validationRules; | ||
| maximumComplexity: this.maximumComplexity, | ||
| estimators: [ | ||
| simpleEstimator({ defaultComplexity: this.defaultComplexity }) | ||
| ], | ||
| estimators: [simpleEstimator({ defaultComplexity: this.defaultComplexity })], | ||
| variables, | ||
| }); | ||
| return [ | ||
| ...specifiedRules, | ||
| complexityRule, | ||
| ...this.validationRules, | ||
| ]; | ||
| return [...specifiedRules, complexityRule, ...this.validationRules]; | ||
| } | ||
@@ -46,3 +45,3 @@ create(query, variables) { | ||
| throw new GraphqlValidationError('Invalid query.', null, { | ||
| errors: validationErrors | ||
| errors: validationErrors, | ||
| }); | ||
@@ -53,3 +52,3 @@ } | ||
| throw new GraphqlValidationError('Invalid query.', null, { | ||
| errors: compiledQuery.errors | ||
| errors: compiledQuery.errors, | ||
| }); | ||
@@ -56,0 +55,0 @@ } |
@@ -1,4 +0,4 @@ | ||
| export { default as createGraphqlRequestHandler } from "./createGraphqlRequestHandler"; | ||
| export { default as GraphqlQueryStore } from "./GraphqlQueryStore"; | ||
| export { default as processGraphqlRequest } from "./processGraphqlRequest"; | ||
| export * from "./errors"; | ||
| export { default as createGraphqlRequestHandler } from './createGraphqlRequestHandler'; | ||
| export { default as GraphqlQueryStore } from './GraphqlQueryStore'; | ||
| export { default as processGraphqlRequest } from './processGraphqlRequest'; | ||
| export * from './errors'; |
@@ -1,12 +0,14 @@ | ||
| export default function processGraphqlRequest(req: any, { store, context, processFileUploads, readRequestBody, }: { | ||
| /// <reference types="node" /> | ||
| import { IncomingMessage } from 'http'; | ||
| type GraphqlResponse = { | ||
| status: number; | ||
| text?: string; | ||
| body?: any; | ||
| }; | ||
| export default function processGraphqlRequest(req: IncomingMessage, { store, context, processFileUploads, readRequestBody, }: { | ||
| store: any; | ||
| context?: {} | undefined; | ||
| processFileUploads: any; | ||
| readRequestBody: any; | ||
| }): Promise<{ | ||
| status: number; | ||
| text: string; | ||
| } | { | ||
| status: number; | ||
| body: any; | ||
| }>; | ||
| context: any; | ||
| processFileUploads: (req: IncomingMessage) => Promise<any>; | ||
| readRequestBody: (req: IncomingMessage) => Promise<any>; | ||
| }): Promise<GraphqlResponse>; | ||
| export {}; |
@@ -1,4 +0,3 @@ | ||
| // eslint-disable-next-line import/extensions | ||
| import { badRequestJson, badRequest, methodNotAllowed, json } from './responses'; | ||
| import { GraphqlValidationError, GraphqlContextError } from './errors'; | ||
| import { GraphqlContextError, GraphqlValidationError } from './errors'; | ||
| import { badRequest, badRequestJson, json, methodNotAllowed } from './responses'; | ||
| export default async function processGraphqlRequest(req, { store, context = {}, processFileUploads, readRequestBody, }) { | ||
@@ -5,0 +4,0 @@ if (!store) { |
@@ -1,16 +0,28 @@ | ||
| export function methodNotAllowed(text?: string): { | ||
| export declare const methodNotAllowed: (text?: string) => { | ||
| status: number; | ||
| text: string; | ||
| }; | ||
| export function badRequest(text?: string): { | ||
| export declare const badRequest: (text?: string) => { | ||
| status: number; | ||
| text: string; | ||
| }; | ||
| export function json(body: any, status?: number): { | ||
| export declare const json: (body: { | ||
| message: string; | ||
| errors: any; | ||
| }, status?: number) => { | ||
| status: number; | ||
| body: any; | ||
| body: { | ||
| message: string; | ||
| errors: any; | ||
| }; | ||
| }; | ||
| export function badRequestJson(result: any): { | ||
| export declare const badRequestJson: (result: { | ||
| message: string; | ||
| errors: any; | ||
| }) => { | ||
| status: number; | ||
| body: any; | ||
| body: { | ||
| message: string; | ||
| errors: any; | ||
| }; | ||
| }; |
| const OK = 200; | ||
| const METHOD_NOT_ALLOWED = 405; | ||
| const BED_REQUEST = 400; | ||
| const BAD_REQUEST = 400; | ||
| export const methodNotAllowed = (text = 'Method Not Allowed') => ({ | ||
| status: METHOD_NOT_ALLOWED, | ||
| text | ||
| text, | ||
| }); | ||
| export const badRequest = (text = 'Bad Request') => ({ | ||
| status: BED_REQUEST, | ||
| text | ||
| status: BAD_REQUEST, | ||
| text, | ||
| }); | ||
@@ -16,2 +16,2 @@ export const json = (body, status = OK) => ({ | ||
| }); | ||
| export const badRequestJson = (result) => (json(result, BED_REQUEST)); | ||
| export const badRequestJson = (result) => json(result, BAD_REQUEST); |
+17
-13
| /// <reference types="node" /> | ||
| export function createTestClient(server: any, headers: any): GraphQLClient; | ||
| export function createTestServer(handler: any): Promise<http.Server>; | ||
| export class RequestMock extends EventEmitter { | ||
| /// <reference types="node" /> | ||
| /// <reference types="node" /> | ||
| import { EventEmitter } from 'events'; | ||
| import { GraphQLClient } from 'graphql-request'; | ||
| import http from 'http'; | ||
| export declare function createTestClient(server: { | ||
| uri: string; | ||
| }, headers?: {}): GraphQLClient; | ||
| export declare function createTestServer(handler: http.RequestListener | undefined): Promise<http.Server>; | ||
| export declare class RequestMock extends EventEmitter { | ||
| method: string; | ||
| headers?: any; | ||
| constructor({ method }?: { | ||
| method?: string | undefined; | ||
| }); | ||
| method: string; | ||
| headers: {}; | ||
| send(data: any): void; | ||
| send(data: WithImplicitCoercion<string | Uint8Array | readonly number[]>): void; | ||
| } | ||
| export class ResponseMock extends EventEmitter { | ||
| constructor(); | ||
| export declare class ResponseMock extends EventEmitter { | ||
| data: any; | ||
| statusCode: any; | ||
| headers: any; | ||
| writeHead: import("jest-mock").Mock<(statusCode: any, headers: any) => void>; | ||
| end: import("jest-mock").Mock<(data: any) => void>; | ||
| writeHead: any; | ||
| end: any; | ||
| constructor(); | ||
| } | ||
| import { GraphQLClient } from "graphql-request"; | ||
| import http from "http"; | ||
| import { EventEmitter } from "events"; |
+10
-2
| /* eslint-disable max-classes-per-file */ | ||
| import { jest } from '@jest/globals'; | ||
| import { EventEmitter } from 'events'; | ||
| import { GraphQLClient } from 'graphql-request'; | ||
| import http from 'http'; | ||
| import testListen from 'test-listen'; | ||
| import { GraphQLClient } from 'graphql-request'; | ||
| export function createTestClient(server, headers) { | ||
| export function createTestClient(server, headers = {}) { | ||
| return new GraphQLClient(server.uri, { headers }); | ||
@@ -13,2 +13,3 @@ } | ||
| const uri = await testListen(server); | ||
| // @ts-ignore | ||
| server.uri = uri; | ||
@@ -18,2 +19,4 @@ return server; | ||
| export class RequestMock extends EventEmitter { | ||
| method; | ||
| headers; | ||
| constructor({ method = 'POST' } = {}) { | ||
@@ -38,2 +41,7 @@ super(); | ||
| export class ResponseMock extends EventEmitter { | ||
| data; | ||
| statusCode; | ||
| headers; | ||
| writeHead; | ||
| end; | ||
| constructor() { | ||
@@ -40,0 +48,0 @@ super(); |
@@ -1,5 +0,6 @@ | ||
| export function readRequestBody(req: any): Promise<any>; | ||
| export function methodNotAllowed(res: any, message?: string): void; | ||
| export function badRequest(res: any, message?: string): void; | ||
| export function json(res: any, result: any, statusCode?: number): void; | ||
| export function badRequestJson(res: any, result: any): void; | ||
| import { IncomingMessage, ServerResponse } from 'http'; | ||
| export declare const readRequestBody: (req: IncomingMessage) => Promise<unknown>; | ||
| export declare const methodNotAllowed: (res: ServerResponse, message?: string) => void; | ||
| export declare const badRequest: (res: ServerResponse, message?: string) => void; | ||
| export declare const json: (res: ServerResponse, result: any, statusCode?: number) => void; | ||
| export declare const badRequestJson: (res: any, result: any) => void; |
| const OK = 200; | ||
| const METHOD_NOT_ALLOWED = 405; | ||
| const BED_REQUEST = 400; | ||
| export const readRequestBody = (req) => (new Promise((resolve, reject) => { | ||
| const BAD_REQUEST = 400; | ||
| export const readRequestBody = (req) => new Promise((resolve, reject) => { | ||
| const body = []; | ||
| req | ||
| .on('data', (chunk) => body.push(chunk)) | ||
| req.on('data', (chunk) => body.push(chunk)) | ||
| .on('error', (error) => reject(error)) | ||
| .on('end', () => resolve(JSON.parse(Buffer.concat(body).toString()))); | ||
| })); | ||
| }); | ||
| export const methodNotAllowed = (res, message = 'Method Not Allowed') => { | ||
@@ -16,3 +15,3 @@ res.writeHead(METHOD_NOT_ALLOWED); | ||
| export const badRequest = (res, message = 'Bad Request') => { | ||
| res.writeHead(BED_REQUEST); | ||
| res.writeHead(BAD_REQUEST); | ||
| res.end(message); | ||
@@ -22,6 +21,6 @@ }; | ||
| res.writeHead(statusCode, { | ||
| 'Content-Type': 'application/json' | ||
| 'Content-Type': 'application/json', | ||
| }); | ||
| res.end(JSON.stringify(result)); | ||
| }; | ||
| export const badRequestJson = (res, result) => (json(res, result, BED_REQUEST)); | ||
| export const badRequestJson = (res, result) => json(res, result, BAD_REQUEST); |
+9
-5
| { | ||
| "name": "@dashdot/graphql-server", | ||
| "version": "0.6.0", | ||
| "version": "0.7.0", | ||
| "description": "A high performance graphql handler using the power of JIT.", | ||
@@ -35,2 +35,7 @@ "type": "module", | ||
| "@graphql-tools/schema": "^8.5.0", | ||
| "@types/jest": "^29.5.11", | ||
| "@swc/jest": "^0.2.24", | ||
| "jest": "^29.4.3", | ||
| "ts-jest": "^29.0.5", | ||
| "@types/test-listen": "^1.1.2", | ||
| "codecov": "^3.8.3", | ||
@@ -41,8 +46,7 @@ "eslint": "^8.19.0", | ||
| "eslint-plugin-jest": "^26.5.3", | ||
| "graphql": "^15.8.0", | ||
| "graphql": "^16.6.0", | ||
| "graphql-request": "^4.3.0", | ||
| "graphql-upload": "^13.0.0", | ||
| "jest": "^28.1.2", | ||
| "test-listen": "^1.1.0", | ||
| "typescript": "^4.7.4" | ||
| "typescript": "^4.9.5", | ||
| "test-listen": "^1.1.0" | ||
| }, | ||
@@ -49,0 +53,0 @@ "eslintConfig": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
38394
5.24%989
7.5%17
30.77%10
150%