graphql-http
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -7,38 +7,2 @@ /** | ||
/** | ||
* The incoming request headers the implementing server should provide. | ||
* | ||
* @category Common | ||
*/ | ||
export interface RequestHeaders { | ||
accept?: string | undefined; | ||
allow?: string | undefined; | ||
'content-type'?: string | undefined; | ||
/** | ||
* Always an array in Node. Duplicates are added to it. | ||
* Not necessarily true for other environments, make sure | ||
* to check the type during runtime. | ||
*/ | ||
'set-cookie'?: string | string[] | undefined; | ||
[key: string]: string | string[] | undefined; | ||
} | ||
/** | ||
* Server agnostic request interface containing the raw request | ||
* which is server dependant. | ||
* | ||
* @category Common | ||
*/ | ||
export interface Request<RawRequest> { | ||
readonly method: string; | ||
readonly url: string; | ||
readonly headers: RequestHeaders; | ||
readonly body: string | Record<string, unknown> | null; | ||
/** | ||
* The raw request itself from the implementing server. | ||
* | ||
* For example: `express.Request` when using Express, or maybe | ||
* `http.IncomingMessage` when just using Node with `http.createServer`. | ||
*/ | ||
readonly raw: RawRequest; | ||
} | ||
/** | ||
* Parameters for GraphQL's request for execution. | ||
@@ -57,43 +21,2 @@ * | ||
/** | ||
* The response headers that get returned from graphql-http. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type ResponseHeaders = { | ||
accept?: string; | ||
allow?: string; | ||
'content-type'?: string; | ||
} & Record<string, string>; | ||
/** | ||
* Server agnostic response body returned from `graphql-http` needing | ||
* to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type ResponseBody = string; | ||
/** | ||
* Server agnostic response options (ex. status and headers) returned from | ||
* `graphql-http` needing to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export interface ResponseInit { | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly headers?: ResponseHeaders; | ||
} | ||
/** | ||
* Server agnostic response returned from `graphql-http` containing the | ||
* body and init options needing to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type Response = readonly [body: ResponseBody | null, init: ResponseInit]; | ||
/** | ||
* Checks whether the passed value is the `graphql-http` server agnostic response. | ||
* | ||
* @category Common | ||
*/ | ||
export declare function isResponse(val: unknown): val is Response; | ||
/** | ||
* A representation of any set of values over any amount of time. | ||
@@ -100,0 +23,0 @@ * |
@@ -8,15 +8,1 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isResponse = void 0; | ||
const utils_1 = require("./utils"); | ||
/** | ||
* Checks whether the passed value is the `graphql-http` server agnostic response. | ||
* | ||
* @category Common | ||
*/ | ||
function isResponse(val) { | ||
// TODO: make sure the contents of init match ResponseInit | ||
return (Array.isArray(val) && | ||
(typeof val[0] === 'string' || val[0] === null) && | ||
(0, utils_1.isObject)(val[1])); | ||
} | ||
exports.isResponse = isResponse; |
@@ -7,4 +7,85 @@ /** | ||
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql'; | ||
import { Request, RequestParams, Response } from './common'; | ||
import { RequestParams } from './common'; | ||
/** | ||
* The incoming request headers the implementing server should provide. | ||
* | ||
* @category Common | ||
*/ | ||
export interface RequestHeaders { | ||
accept?: string | undefined; | ||
allow?: string | undefined; | ||
'content-type'?: string | undefined; | ||
/** | ||
* Always an array in Node. Duplicates are added to it. | ||
* Not necessarily true for other environments, make sure | ||
* to check the type during runtime. | ||
*/ | ||
'set-cookie'?: string | string[] | undefined; | ||
[key: string]: string | string[] | undefined; | ||
} | ||
/** | ||
* Server agnostic request interface containing the raw request | ||
* which is server dependant. | ||
* | ||
* @category Common | ||
*/ | ||
export interface Request<RawRequest, Context> { | ||
readonly method: string; | ||
readonly url: string; | ||
readonly headers: RequestHeaders; | ||
readonly body: string | Record<string, unknown> | null; | ||
/** | ||
* The raw request itself from the implementing server. | ||
* | ||
* For example: `express.Request` when using Express, or maybe | ||
* `http.IncomingMessage` when just using Node with `http.createServer`. | ||
*/ | ||
readonly raw: RawRequest; | ||
/** | ||
* Context value about the incoming request, you're free to pass any information here. | ||
*/ | ||
readonly context: Context; | ||
} | ||
/** | ||
* The response headers that get returned from graphql-http. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type ResponseHeaders = { | ||
accept?: string; | ||
allow?: string; | ||
'content-type'?: string; | ||
} & Record<string, string>; | ||
/** | ||
* Server agnostic response body returned from `graphql-http` needing | ||
* to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type ResponseBody = string; | ||
/** | ||
* Server agnostic response options (ex. status and headers) returned from | ||
* `graphql-http` needing to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export interface ResponseInit { | ||
readonly status: number; | ||
readonly statusText: string; | ||
readonly headers?: ResponseHeaders; | ||
} | ||
/** | ||
* Server agnostic response returned from `graphql-http` containing the | ||
* body and init options needing to be coerced to the server implementation in use. | ||
* | ||
* @category Common | ||
*/ | ||
export declare type Response = readonly [body: ResponseBody | null, init: ResponseInit]; | ||
/** | ||
* Checks whether the passed value is the `graphql-http` server agnostic response. | ||
* | ||
* @category Common | ||
*/ | ||
export declare function isResponse(val: unknown): val is Response; | ||
/** | ||
* A concrete GraphQL execution context value type. | ||
@@ -21,3 +102,3 @@ * | ||
/** @category Server */ | ||
export interface HandlerOptions<RawRequest = unknown> { | ||
export interface HandlerOptions<RawRequest = unknown, Context = unknown> { | ||
/** | ||
@@ -39,3 +120,3 @@ * The GraphQL schema on which the operations will | ||
*/ | ||
schema?: GraphQLSchema | ((req: Request<RawRequest>, args: Omit<ExecutionArgs, 'schema'>) => Promise<GraphQLSchema | Response> | GraphQLSchema | Response); | ||
schema?: GraphQLSchema | ((req: Request<RawRequest, Context>, args: Omit<ExecutionArgs, 'schema'>) => Promise<GraphQLSchema | Response> | GraphQLSchema | Response); | ||
/** | ||
@@ -46,6 +127,8 @@ * A value which is provided to every resolver and holds | ||
*/ | ||
context?: ExecutionContext | ((req: Request<RawRequest>, args: ExecutionArgs) => Promise<ExecutionContext | Response> | ExecutionContext | Response); | ||
context?: ExecutionContext | ((req: Request<RawRequest, Context>, args: ExecutionArgs) => Promise<ExecutionContext | Response> | ExecutionContext | Response); | ||
/** | ||
* A custom GraphQL validate function allowing you to apply your | ||
* own validation rules. | ||
* | ||
* Will not be used when implementing a custom `onSubscribe`. | ||
*/ | ||
@@ -70,2 +153,6 @@ validate?: typeof graphqlValidate; | ||
* | ||
* If you return `ExecutionResult` from the callback, it will be used | ||
* directly for responding to the request. Useful for implementing a response | ||
* cache. | ||
* | ||
* If you return `ExecutionArgs` from the callback, it will be used instead of | ||
@@ -75,2 +162,4 @@ * trying to build one internally. In this case, you are responsible for providing | ||
* | ||
* You *must* validate the `ExecutionArgs` yourself if returning them. | ||
* | ||
* If you return an array of `GraphQLError` from the callback, they will be reported | ||
@@ -90,3 +179,3 @@ * to the client while complying with the spec. | ||
*/ | ||
onSubscribe?: (req: Request<RawRequest>, params: RequestParams) => Promise<ExecutionArgs | GraphQLError[] | Response | void> | ExecutionArgs | GraphQLError[] | Response | void; | ||
onSubscribe?: (req: Request<RawRequest, Context>, params: RequestParams) => Promise<ExecutionResult | ExecutionArgs | readonly GraphQLError[] | Response | void> | ExecutionResult | ExecutionArgs | readonly GraphQLError[] | Response | void; | ||
/** | ||
@@ -105,3 +194,3 @@ * Executed after the operation call resolves. | ||
*/ | ||
onOperation?: (req: Request<RawRequest>, args: ExecutionArgs, result: ExecutionResult) => Promise<ExecutionResult | Response | void> | ExecutionResult | Response | void; | ||
onOperation?: (req: Request<RawRequest, Context>, args: ExecutionArgs, result: ExecutionResult) => Promise<ExecutionResult | Response | void> | ExecutionResult | Response | void; | ||
} | ||
@@ -118,3 +207,3 @@ /** | ||
*/ | ||
export declare type Handler<RawRequest = unknown> = (req: Request<RawRequest>) => Promise<Response>; | ||
export declare type Handler<RawRequest = unknown, Context = unknown> = (req: Request<RawRequest, Context>) => Promise<Response>; | ||
/** | ||
@@ -175,2 +264,26 @@ * Makes a GraphQL over HTTP Protocol compliant server handler. The handler can | ||
*/ | ||
export declare function createHandler<RawRequest = unknown>(options: HandlerOptions<RawRequest>): Handler<RawRequest>; | ||
export declare function createHandler<RawRequest = unknown, Context = unknown>(options: HandlerOptions<RawRequest, Context>): Handler<RawRequest, Context>; | ||
/** | ||
* Request's Media-Type that the server accepts. | ||
* | ||
* @category Server | ||
*/ | ||
export declare type AcceptableMediaType = 'application/graphql+json' | 'application/json'; | ||
/** | ||
* Inspects the request and detects the appropriate/acceptable Media-Type | ||
* looking at the `Accept` header while complying with the GraphQL over HTTP Protocol. | ||
* | ||
* @category Server | ||
*/ | ||
export declare function getAcceptableMediaType(acceptHeader: string | null | undefined): AcceptableMediaType | null; | ||
/** | ||
* Creates an appropriate GraphQL over HTTP response following the provided arguments. | ||
* | ||
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful". | ||
* | ||
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec) | ||
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP Protocol. | ||
* | ||
* @category Server | ||
*/ | ||
export declare function makeResponse(resultOrErrors: Readonly<ExecutionResult> | Readonly<GraphQLError[]> | Readonly<GraphQLError>, acceptedMediaType: AcceptableMediaType): Response; |
@@ -8,7 +8,18 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createHandler = void 0; | ||
exports.makeResponse = exports.getAcceptableMediaType = exports.createHandler = exports.isResponse = void 0; | ||
const graphql_1 = require("graphql"); | ||
const common_1 = require("./common"); | ||
const utils_1 = require("./utils"); | ||
/** | ||
* Checks whether the passed value is the `graphql-http` server agnostic response. | ||
* | ||
* @category Common | ||
*/ | ||
function isResponse(val) { | ||
// TODO: make sure the contents of init match ResponseInit | ||
return (Array.isArray(val) && | ||
(typeof val[0] === 'string' || val[0] === null) && | ||
(0, utils_1.isObject)(val[1])); | ||
} | ||
exports.isResponse = isResponse; | ||
/** | ||
* Makes a GraphQL over HTTP Protocol compliant server handler. The handler can | ||
@@ -85,24 +96,3 @@ * be used with your favourite server library. | ||
} | ||
let acceptedMediaType; | ||
const accepts = (req.headers.accept || '*/*') | ||
.replace(/\s/g, '') | ||
.toLowerCase() | ||
.split(','); | ||
for (const accept of accepts) { | ||
// accept-charset became obsolete, shouldnt be used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset) | ||
// TODO: handle the weight parameter "q" | ||
const [mediaType, ...params] = accept.split(';'); | ||
const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified; | ||
if (mediaType === 'application/json' && charset === 'charset=utf8') { | ||
acceptedMediaType = 'application/json'; | ||
break; | ||
} | ||
if ((mediaType === 'application/graphql+json' || | ||
mediaType === 'application/*' || | ||
mediaType === '*/*') && | ||
charset === 'charset=utf8') { | ||
acceptedMediaType = 'application/graphql+json'; | ||
break; | ||
} | ||
} | ||
const acceptedMediaType = getAcceptableMediaType(req.headers.accept); | ||
if (!acceptedMediaType) { | ||
@@ -178,4 +168,6 @@ return [ | ||
} | ||
if (!partParams.query) | ||
if (partParams.query == null) | ||
throw new Error('Missing query'); | ||
if (typeof partParams.query !== 'string') | ||
throw new Error('Invalid query'); | ||
if (partParams.variables != null && | ||
@@ -195,36 +187,11 @@ (typeof partParams.variables !== 'object' || | ||
catch (err) { | ||
return [ | ||
err.message, | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { statusText: 'Bad Request' }), | ||
]; | ||
return makeResponse(new graphql_1.GraphQLError(err.message), acceptedMediaType); | ||
} | ||
let args; | ||
const maybeResErrsOrArgs = await (onSubscribe === null || onSubscribe === void 0 ? void 0 : onSubscribe(req, params)); | ||
if ((0, common_1.isResponse)(maybeResErrsOrArgs)) | ||
if (isResponse(maybeResErrsOrArgs)) | ||
return maybeResErrsOrArgs; | ||
else if ((0, utils_1.areGraphQLErrors)(maybeResErrsOrArgs)) | ||
return [ | ||
JSON.stringify({ errors: maybeResErrsOrArgs }), | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { headers: { | ||
'content-type': acceptedMediaType === 'application/json' | ||
? 'application/json; charset=utf-8' | ||
: 'application/graphql+json; charset=utf-8', | ||
} }), | ||
]; | ||
else if ((0, utils_1.isExecutionResult)(maybeResErrsOrArgs) || | ||
(0, utils_1.areGraphQLErrors)(maybeResErrsOrArgs)) | ||
return makeResponse(maybeResErrsOrArgs, acceptedMediaType); | ||
else if (maybeResErrsOrArgs) | ||
@@ -241,18 +208,3 @@ args = maybeResErrsOrArgs; | ||
catch (err) { | ||
return [ | ||
JSON.stringify({ errors: [err] }), | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { statusText: 'Bad Request', headers: { | ||
'content-type': acceptedMediaType === 'application/json' | ||
? 'application/json; charset=utf-8' | ||
: 'application/graphql+json; charset=utf-8', | ||
} }), | ||
]; | ||
return makeResponse(err, acceptedMediaType); | ||
} | ||
@@ -266,3 +218,3 @@ const argsWithoutSchema = { | ||
const resOrSchema = await schema(req, argsWithoutSchema); | ||
if ((0, common_1.isResponse)(resOrSchema)) | ||
if (isResponse(resOrSchema)) | ||
return resOrSchema; | ||
@@ -274,2 +226,6 @@ args = Object.assign(Object.assign({}, argsWithoutSchema), { schema: resOrSchema }); | ||
} | ||
const validationErrs = validate(args.schema, args.document); | ||
if (validationErrs.length) { | ||
return makeResponse(validationErrs, acceptedMediaType); | ||
} | ||
} | ||
@@ -284,23 +240,6 @@ let operation; | ||
catch (_e) { | ||
return [ | ||
'Unable to detect operation AST', | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { statusText: 'Bad Request' }), | ||
]; | ||
return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType); | ||
} | ||
if (operation === 'subscription') { | ||
return [ | ||
'Subscriptions are not supported', | ||
{ | ||
status: 400, | ||
statusText: 'Bad Request', | ||
}, | ||
]; | ||
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType); | ||
} | ||
@@ -311,3 +250,5 @@ // mutations cannot happen over GETs | ||
return [ | ||
'Cannot perform mutations over GET', | ||
JSON.stringify({ | ||
errors: [new graphql_1.GraphQLError('Cannot perform mutations over GET')], | ||
}), | ||
{ | ||
@@ -324,33 +265,65 @@ status: 405, | ||
const maybeResOrContext = typeof context === 'function' ? await context(req, args) : context; | ||
if ((0, common_1.isResponse)(maybeResOrContext)) | ||
if (isResponse(maybeResOrContext)) | ||
return maybeResOrContext; | ||
args.contextValue = maybeResOrContext; | ||
} | ||
const validationErrs = validate(args.schema, args.document); | ||
if (validationErrs.length) { | ||
return [ | ||
JSON.stringify({ errors: validationErrs }), | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { headers: { | ||
'content-type': acceptedMediaType === 'application/json' | ||
? 'application/json; charset=utf-8' | ||
: 'application/graphql+json; charset=utf-8', | ||
} }), | ||
]; | ||
let result = await execute(args); | ||
const maybeResponseOrResult = await (onOperation === null || onOperation === void 0 ? void 0 : onOperation(req, args, result)); | ||
if (isResponse(maybeResponseOrResult)) | ||
return maybeResponseOrResult; | ||
else if (maybeResponseOrResult) | ||
result = maybeResponseOrResult; | ||
if ((0, utils_1.isAsyncIterable)(result)) { | ||
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType); | ||
} | ||
let result = await execute(args); | ||
const maybeResOrResult = await (onOperation === null || onOperation === void 0 ? void 0 : onOperation(req, args, result)); | ||
if ((0, common_1.isResponse)(maybeResOrResult)) | ||
return maybeResOrResult; | ||
else if (maybeResOrResult) | ||
result = maybeResOrResult; | ||
return makeResponse(result, acceptedMediaType); | ||
}; | ||
} | ||
exports.createHandler = createHandler; | ||
/** | ||
* Inspects the request and detects the appropriate/acceptable Media-Type | ||
* looking at the `Accept` header while complying with the GraphQL over HTTP Protocol. | ||
* | ||
* @category Server | ||
*/ | ||
function getAcceptableMediaType(acceptHeader) { | ||
let acceptedMediaType = null; | ||
const accepts = (acceptHeader || '*/*') | ||
.replace(/\s/g, '') | ||
.toLowerCase() | ||
.split(','); | ||
for (const accept of accepts) { | ||
// accept-charset became obsolete, shouldnt be used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset) | ||
// TODO: handle the weight parameter "q" | ||
const [mediaType, ...params] = accept.split(';'); | ||
const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified; | ||
if (mediaType === 'application/json' && charset === 'charset=utf8') { | ||
acceptedMediaType = 'application/json'; | ||
break; | ||
} | ||
if ((mediaType === 'application/graphql+json' || | ||
mediaType === 'application/*' || | ||
mediaType === '*/*') && | ||
charset === 'charset=utf8') { | ||
acceptedMediaType = 'application/graphql+json'; | ||
break; | ||
} | ||
} | ||
return acceptedMediaType; | ||
} | ||
exports.getAcceptableMediaType = getAcceptableMediaType; | ||
/** | ||
* Creates an appropriate GraphQL over HTTP response following the provided arguments. | ||
* | ||
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful". | ||
* | ||
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec) | ||
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP Protocol. | ||
* | ||
* @category Server | ||
*/ | ||
function makeResponse(resultOrErrors, acceptedMediaType) { | ||
if ((0, utils_1.isExecutionResult)(resultOrErrors)) { | ||
return [ | ||
JSON.stringify(result), | ||
JSON.stringify(resultOrErrors), | ||
{ | ||
@@ -366,4 +339,26 @@ status: 200, | ||
]; | ||
}; | ||
} | ||
return [ | ||
JSON.stringify({ | ||
errors: Array.isArray(resultOrErrors) | ||
? (0, utils_1.isObject)(resultOrErrors) | ||
? resultOrErrors | ||
: new graphql_1.GraphQLError(String(resultOrErrors)) | ||
: [resultOrErrors], | ||
}), | ||
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json' | ||
? { | ||
status: 200, | ||
statusText: 'OK', | ||
} | ||
: { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
})), { headers: { | ||
'content-type': acceptedMediaType === 'application/json' | ||
? 'application/json; charset=utf-8' | ||
: 'application/graphql+json; charset=utf-8', | ||
} }), | ||
]; | ||
} | ||
exports.createHandler = createHandler; | ||
exports.makeResponse = makeResponse; |
@@ -6,6 +6,10 @@ /** | ||
*/ | ||
import type { GraphQLError } from 'graphql'; | ||
import type { ExecutionResult, GraphQLError } from 'graphql'; | ||
/** @private */ | ||
export declare function isObject(val: unknown): val is Record<PropertyKey, unknown>; | ||
/** @private */ | ||
export declare function areGraphQLErrors(obj: unknown): obj is GraphQLError[]; | ||
export declare function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[]; | ||
/** @private */ | ||
export declare function isExecutionResult(val: unknown): val is ExecutionResult; | ||
/** @private */ | ||
export declare function isAsyncIterable<T = unknown>(val: unknown): val is AsyncIterable<T>; |
@@ -8,3 +8,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.areGraphQLErrors = exports.isObject = void 0; | ||
exports.isAsyncIterable = exports.isExecutionResult = exports.areGraphQLErrors = exports.isObject = void 0; | ||
/** @private */ | ||
@@ -24,1 +24,12 @@ function isObject(val) { | ||
exports.areGraphQLErrors = areGraphQLErrors; | ||
/** @private */ | ||
function isExecutionResult(val) { | ||
return (isObject(val) && | ||
('data' in val || ('data' in val && val.data == null && 'errors' in val))); | ||
} | ||
exports.isExecutionResult = isExecutionResult; | ||
/** @private */ | ||
function isAsyncIterable(val) { | ||
return typeof Object(val)[Symbol.asyncIterator] === 'function'; | ||
} | ||
exports.isAsyncIterable = isAsyncIterable; |
{ | ||
"name": "graphql-http", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client", | ||
@@ -79,4 +79,4 @@ "keywords": [ | ||
"@types/jest": "^28.1.6", | ||
"@typescript-eslint/eslint-plugin": "^5.32.0", | ||
"@typescript-eslint/parser": "^5.32.0", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"babel-jest": "^28.1.3", | ||
@@ -92,3 +92,3 @@ "eslint": "^8.21.0", | ||
"replacestream": "^4.0.3", | ||
"rollup": "^2.77.2", | ||
"rollup": "^2.77.3", | ||
"rollup-plugin-terser": "^7.0.2", | ||
@@ -95,0 +95,0 @@ "semantic-release": "^19.0.3", |
@@ -217,4 +217,6 @@ <div align="center"> | ||
// Create the GraphQL over HTTP handler | ||
const handler = createHandler<Request>({ schema }); | ||
// Start serving on `/graphql` using the handler | ||
await serve( | ||
@@ -221,0 +223,0 @@ async (req: Request) => { |
@@ -19,19 +19,2 @@ (function (global, factory) { | ||
* | ||
* common | ||
* | ||
*/ | ||
/** | ||
* Checks whether the passed value is the `graphql-http` server agnostic response. | ||
* | ||
* @category Common | ||
*/ | ||
function isResponse(val) { | ||
// TODO: make sure the contents of init match ResponseInit | ||
return (Array.isArray(val) && | ||
(typeof val[0] === 'string' || val[0] === null) && | ||
isObject(val[1])); | ||
} | ||
/** | ||
* | ||
* client | ||
@@ -205,3 +188,2 @@ * | ||
exports.createClient = createClient; | ||
exports.isResponse = isResponse; | ||
@@ -208,0 +190,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlHttp={})}(this,(function(e){"use strict";function t(e){return"object"==typeof e&&null!==e}class r extends Error{constructor(e){let r,o;var n;t(n=e)&&"boolean"==typeof n.ok&&"number"==typeof n.status&&"string"==typeof n.statusText?(o=e,r="Server responded with "+e.status+": "+e.statusText):r=e instanceof Error?e.message:String(e),super(r),this.name=this.constructor.name,this.response=o}}e.NetworkError=r,e.createClient=function(e){const{credentials:t="same-origin",referrer:o,referrerPolicy:n,shouldRetry:s=(()=>!1)}=e,i=e.fetchFn||fetch,a=e.abortControllerImpl||AbortController,c=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:r=>e?(setTimeout((()=>r()),0),()=>{}):(t.push(r),()=>{t.splice(t.indexOf(r),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();return{subscribe(l,p){if(c.disposed)throw new Error("Client has been disposed");const f=new a,u=c.onDispose((()=>{u(),f.abort()}));return(async()=>{var a;let c=null,u=0;for(;;){if(c){const e=await s(c,u);if(f.signal.aborted)return;if(!e)throw c;u++}try{const s="function"==typeof e.url?await e.url(l):e.url;if(f.signal.aborted)return;const c="function"==typeof e.headers?await e.headers():null!==(a=e.headers)&&void 0!==a?a:{};if(f.signal.aborted)return;let u;try{u=await i(s,{signal:f.signal,method:"POST",headers:Object.assign(Object.assign({},c),{"content-type":"application/json; charset=utf-8",accept:"application/graphql+json, application/json"}),credentials:t,referrer:o,referrerPolicy:n,body:JSON.stringify(l)})}catch(e){throw new r(e)}if(!u.ok)throw new r(u);if(!u.body)throw new Error("Missing response body");const d=u.headers.get("content-type");if(!d)throw new Error("Missing response content-type");if(!d.includes("application/graphql+json")&&!d.includes("application/json"))throw new Error(`Unsupported response content-type ${d}`);const h=await u.json();return p.next(h),f.abort()}catch(e){if(f.signal.aborted)return;if(!(e instanceof r))throw e;c=e}}})().then((()=>p.complete())).catch((e=>p.error(e))),()=>f.abort()},dispose(){c.dispose()}}},e.isResponse=function(e){return Array.isArray(e)&&("string"==typeof e[0]||null===e[0])&&t(e[1])},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlHttp={})}(this,(function(e){"use strict";class t extends Error{constructor(e){let t,r;var o;(function(e){return"object"==typeof e&&null!==e})(o=e)&&"boolean"==typeof o.ok&&"number"==typeof o.status&&"string"==typeof o.statusText?(r=e,t="Server responded with "+e.status+": "+e.statusText):t=e instanceof Error?e.message:String(e),super(t),this.name=this.constructor.name,this.response=r}}e.NetworkError=t,e.createClient=function(e){const{credentials:r="same-origin",referrer:o,referrerPolicy:n,shouldRetry:s=(()=>!1)}=e,i=e.fetchFn||fetch,a=e.abortControllerImpl||AbortController,c=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:r=>e?(setTimeout((()=>r()),0),()=>{}):(t.push(r),()=>{t.splice(t.indexOf(r),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();return{subscribe(l,p){if(c.disposed)throw new Error("Client has been disposed");const f=new a,u=c.onDispose((()=>{u(),f.abort()}));return(async()=>{var a;let c=null,u=0;for(;;){if(c){const e=await s(c,u);if(f.signal.aborted)return;if(!e)throw c;u++}try{const s="function"==typeof e.url?await e.url(l):e.url;if(f.signal.aborted)return;const c="function"==typeof e.headers?await e.headers():null!==(a=e.headers)&&void 0!==a?a:{};if(f.signal.aborted)return;let u;try{u=await i(s,{signal:f.signal,method:"POST",headers:Object.assign(Object.assign({},c),{"content-type":"application/json; charset=utf-8",accept:"application/graphql+json, application/json"}),credentials:r,referrer:o,referrerPolicy:n,body:JSON.stringify(l)})}catch(e){throw new t(e)}if(!u.ok)throw new t(u);if(!u.body)throw new Error("Missing response body");const d=u.headers.get("content-type");if(!d)throw new Error("Missing response content-type");if(!d.includes("application/graphql+json")&&!d.includes("application/json"))throw new Error(`Unsupported response content-type ${d}`);const h=await u.json();return p.next(h),f.abort()}catch(e){if(f.signal.aborted)return;if(!(e instanceof t))throw e;c=e}}})().then((()=>p.complete())).catch((e=>p.error(e))),()=>f.abort()},dispose(){c.dispose()}}},Object.defineProperty(e,"__esModule",{value:!0})})); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98843
1829
719