Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import type { GraphQLRequest, Operation } from "../core/index.js";
export declare function createOperation(starting: any, operation: GraphQLRequest): Operation;
//# sourceMappingURL=createOperation.d.ts.map

View File

@@ -0,0 +1,23 @@
import { __assign } from "tslib";
export function createOperation(starting, operation) {
var context = __assign({}, starting);
var setContext = function (next) {
if (typeof next === "function") {
context = __assign(__assign({}, context), next(context));
}
else {
context = __assign(__assign({}, context), next);
}
};
var getContext = function () { return (__assign({}, context)); };
Object.defineProperty(operation, "setContext", {
enumerable: false,
value: setContext,
});
Object.defineProperty(operation, "getContext", {
enumerable: false,
value: getContext,
});
return operation;
}
//# sourceMappingURL=createOperation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createOperation.js","sourceRoot":"","sources":["../../../src/link/utils/createOperation.ts"],"names":[],"mappings":";AAEA,MAAM,UAAU,eAAe,CAC7B,QAAa,EACb,SAAyB;IAEzB,IAAI,OAAO,gBAAQ,QAAQ,CAAE,CAAC;IAC9B,IAAM,UAAU,GAAG,UAAC,IAAS;QAC3B,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/B,OAAO,yBAAQ,OAAO,GAAK,IAAI,CAAC,OAAO,CAAC,CAAE,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,OAAO,yBAAQ,OAAO,GAAK,IAAI,CAAE,CAAC;QACpC,CAAC;IACH,CAAC,CAAC;IACF,IAAM,UAAU,GAAG,cAAM,OAAA,cAAM,OAAO,EAAG,EAAhB,CAAgB,CAAC;IAE1C,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE;QAC7C,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,UAAU;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE;QAC7C,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,UAAU;KAClB,CAAC,CAAC;IAEH,OAAO,SAAsB,CAAC;AAChC,CAAC","sourcesContent":["import type { GraphQLRequest, Operation } from \"../core/index.js\";\n\nexport function createOperation(\n starting: any,\n operation: GraphQLRequest\n): Operation {\n let context = { ...starting };\n const setContext = (next: any) => {\n if (typeof next === \"function\") {\n context = { ...context, ...next(context) };\n } else {\n context = { ...context, ...next };\n }\n };\n const getContext = () => ({ ...context });\n\n Object.defineProperty(operation, \"setContext\", {\n enumerable: false,\n value: setContext,\n });\n\n Object.defineProperty(operation, \"getContext\", {\n enumerable: false,\n value: getContext,\n });\n\n return operation as Operation;\n}\n"]}

View File

@@ -0,0 +1,5 @@
import type { DocumentNode } from "graphql";
export declare function filterOperationVariables(variables: Record<string, any>, query: DocumentNode): {
[x: string]: any;
};
//# sourceMappingURL=filterOperationVariables.d.ts.map

View File

@@ -0,0 +1,23 @@
import { __assign } from "tslib";
import { visit } from "graphql";
export function filterOperationVariables(variables, query) {
var result = __assign({}, variables);
var unusedNames = new Set(Object.keys(variables));
visit(query, {
Variable: function (node, _key, parent) {
// A variable type definition at the top level of a query is not
// enough to silence server-side errors about the variable being
// unused, so variable definitions do not count as usage.
// https://spec.graphql.org/draft/#sec-All-Variables-Used
if (parent &&
parent.kind !== "VariableDefinition") {
unusedNames.delete(node.name.value);
}
},
});
unusedNames.forEach(function (name) {
delete result[name];
});
return result;
}
//# sourceMappingURL=filterOperationVariables.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"filterOperationVariables.js","sourceRoot":"","sources":["../../../src/link/utils/filterOperationVariables.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,UAAU,wBAAwB,CACtC,SAA8B,EAC9B,KAAmB;IAEnB,IAAM,MAAM,gBAAQ,SAAS,CAAE,CAAC;IAChC,IAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IACpD,KAAK,CAAC,KAAK,EAAE;QACX,QAAQ,YAAC,IAAI,EAAE,IAAI,EAAE,MAAM;YACzB,gEAAgE;YAChE,gEAAgE;YAChE,yDAAyD;YACzD,yDAAyD;YACzD,IACE,MAAM;gBACL,MAAiC,CAAC,IAAI,KAAK,oBAAoB,EAChE,CAAC;gBACD,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IACH,WAAW,CAAC,OAAO,CAAC,UAAC,IAAI;QACvB,OAAO,MAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { VariableDefinitionNode, DocumentNode } from \"graphql\";\nimport { visit } from \"graphql\";\n\nexport function filterOperationVariables(\n variables: Record<string, any>,\n query: DocumentNode\n) {\n const result = { ...variables };\n const unusedNames = new Set(Object.keys(variables));\n visit(query, {\n Variable(node, _key, parent) {\n // A variable type definition at the top level of a query is not\n // enough to silence server-side errors about the variable being\n // unused, so variable definitions do not count as usage.\n // https://spec.graphql.org/draft/#sec-All-Variables-Used\n if (\n parent &&\n (parent as VariableDefinitionNode).kind !== \"VariableDefinition\"\n ) {\n unusedNames.delete(node.name.value);\n }\n },\n });\n unusedNames.forEach((name) => {\n delete result![name];\n });\n return result;\n}\n"]}

View File

@@ -0,0 +1,3 @@
import { Observable } from "../../utilities/index.js";
export declare function fromError<T>(errorValue: any): Observable<T>;
//# sourceMappingURL=fromError.d.ts.map

View File

@@ -0,0 +1,7 @@
import { Observable } from "../../utilities/index.js";
export function fromError(errorValue) {
return new Observable(function (observer) {
observer.error(errorValue);
});
}
//# sourceMappingURL=fromError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fromError.js","sourceRoot":"","sources":["../../../src/link/utils/fromError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,UAAU,SAAS,CAAI,UAAe;IAC1C,OAAO,IAAI,UAAU,CAAI,UAAC,QAAQ;QAChC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Observable } from \"../../utilities/index.js\";\n\nexport function fromError<T>(errorValue: any): Observable<T> {\n return new Observable<T>((observer) => {\n observer.error(errorValue);\n });\n}\n"]}

View File

@@ -0,0 +1,3 @@
import { Observable } from "../../utilities/index.js";
export declare function fromPromise<T>(promise: Promise<T>): Observable<T>;
//# sourceMappingURL=fromPromise.d.ts.map

View File

@@ -0,0 +1,12 @@
import { Observable } from "../../utilities/index.js";
export function fromPromise(promise) {
return new Observable(function (observer) {
promise
.then(function (value) {
observer.next(value);
observer.complete();
})
.catch(observer.error.bind(observer));
});
}
//# sourceMappingURL=fromPromise.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fromPromise.js","sourceRoot":"","sources":["../../../src/link/utils/fromPromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,UAAU,WAAW,CAAI,OAAmB;IAChD,OAAO,IAAI,UAAU,CAAI,UAAC,QAAQ;QAChC,OAAO;aACJ,IAAI,CAAC,UAAC,KAAQ;YACb,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC,CAAC;aACD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Observable } from \"../../utilities/index.js\";\n\nexport function fromPromise<T>(promise: Promise<T>): Observable<T> {\n return new Observable<T>((observer) => {\n promise\n .then((value: T) => {\n observer.next(value);\n observer.complete();\n })\n .catch(observer.error.bind(observer));\n });\n}\n"]}

View File

@@ -0,0 +1,11 @@
import "../../utilities/globals/index.js";
export { fromError } from "./fromError.js";
export { toPromise } from "./toPromise.js";
export { fromPromise } from "./fromPromise.js";
export type { ServerError } from "./throwServerError.js";
export { throwServerError } from "./throwServerError.js";
export { validateOperation } from "./validateOperation.js";
export { createOperation } from "./createOperation.js";
export { transformOperation } from "./transformOperation.js";
export { filterOperationVariables } from "./filterOperationVariables.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,10 @@
import "../../utilities/globals/index.js";
export { fromError } from "./fromError.js";
export { toPromise } from "./toPromise.js";
export { fromPromise } from "./fromPromise.js";
export { throwServerError } from "./throwServerError.js";
export { validateOperation } from "./validateOperation.js";
export { createOperation } from "./createOperation.js";
export { transformOperation } from "./transformOperation.js";
export { filterOperationVariables } from "./filterOperationVariables.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport { fromError } from \"./fromError.js\";\nexport { toPromise } from \"./toPromise.js\";\nexport { fromPromise } from \"./fromPromise.js\";\nexport type { ServerError } from \"./throwServerError.js\";\nexport { throwServerError } from \"./throwServerError.js\";\nexport { validateOperation } from \"./validateOperation.js\";\nexport { createOperation } from \"./createOperation.js\";\nexport { transformOperation } from \"./transformOperation.js\";\nexport { filterOperationVariables } from \"./filterOperationVariables.js\";\n"]}

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/link/utils",
"type": "module",
"main": "utils.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": false
}

View File

@@ -0,0 +1,7 @@
export type ServerError = Error & {
response: Response;
result: Record<string, any> | string;
statusCode: number;
};
export declare const throwServerError: (response: Response, result: any, message: string) => never;
//# sourceMappingURL=throwServerError.d.ts.map

View File

@@ -0,0 +1,9 @@
export var throwServerError = function (response, result, message) {
var error = new Error(message);
error.name = "ServerError";
error.response = response;
error.statusCode = response.status;
error.result = result;
throw error;
};
//# sourceMappingURL=throwServerError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throwServerError.js","sourceRoot":"","sources":["../../../src/link/utils/throwServerError.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,QAAkB,EAClB,MAAW,EACX,OAAe;IAEf,IAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAgB,CAAC;IAChD,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC;IAC3B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IACnC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,MAAM,KAAK,CAAC;AACd,CAAC,CAAC","sourcesContent":["export type ServerError = Error & {\n response: Response;\n result: Record<string, any> | string;\n statusCode: number;\n};\n\nexport const throwServerError = (\n response: Response,\n result: any,\n message: string\n) => {\n const error = new Error(message) as ServerError;\n error.name = \"ServerError\";\n error.response = response;\n error.statusCode = response.status;\n error.result = result;\n throw error;\n};\n"]}

View File

@@ -0,0 +1,3 @@
import type { Observable } from "../../utilities/index.js";
export declare function toPromise<R>(observable: Observable<R>): Promise<R>;
//# sourceMappingURL=toPromise.d.ts.map

View File

@@ -0,0 +1,19 @@
import { invariant } from "../../utilities/globals/index.js";
export function toPromise(observable) {
var completed = false;
return new Promise(function (resolve, reject) {
observable.subscribe({
next: function (data) {
if (completed) {
globalThis.__DEV__ !== false && invariant.warn(42);
}
else {
completed = true;
resolve(data);
}
},
error: reject,
});
});
}
//# sourceMappingURL=toPromise.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toPromise.js","sourceRoot":"","sources":["../../../src/link/utils/toPromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAG7D,MAAM,UAAU,SAAS,CAAI,UAAyB;IACpD,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,OAAO,IAAI,OAAO,CAAI,UAAC,OAAO,EAAE,MAAM;QACpC,UAAU,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,UAAC,IAAI;gBACT,IAAI,SAAS,EAAE,CAAC;oBACd,SAAS,CAAC,IAAI,CACZ,mEAAmE,CACpE,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,SAAS,GAAG,IAAI,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC;YACD,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\nimport type { Observable } from \"../../utilities/index.js\";\n\nexport function toPromise<R>(observable: Observable<R>): Promise<R> {\n let completed = false;\n return new Promise<R>((resolve, reject) => {\n observable.subscribe({\n next: (data) => {\n if (completed) {\n invariant.warn(\n `Promise Wrapper does not support multiple results from Observable`\n );\n } else {\n completed = true;\n resolve(data);\n }\n },\n error: reject,\n });\n });\n}\n"]}

View File

@@ -0,0 +1,3 @@
import type { GraphQLRequest } from "../core/index.js";
export declare function transformOperation(operation: GraphQLRequest): GraphQLRequest;
//# sourceMappingURL=transformOperation.d.ts.map

View File

@@ -0,0 +1,18 @@
import { getOperationName } from "../../utilities/index.js";
export function transformOperation(operation) {
var transformedOperation = {
variables: operation.variables || {},
extensions: operation.extensions || {},
operationName: operation.operationName,
query: operation.query,
};
// Best guess at an operation name
if (!transformedOperation.operationName) {
transformedOperation.operationName =
typeof transformedOperation.query !== "string" ?
getOperationName(transformedOperation.query) || undefined
: "";
}
return transformedOperation;
}
//# sourceMappingURL=transformOperation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"transformOperation.js","sourceRoot":"","sources":["../../../src/link/utils/transformOperation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,UAAU,kBAAkB,CAAC,SAAyB;IAC1D,IAAM,oBAAoB,GAAmB;QAC3C,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,EAAE;QACpC,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,EAAE;QACtC,aAAa,EAAE,SAAS,CAAC,aAAa;QACtC,KAAK,EAAE,SAAS,CAAC,KAAK;KACvB,CAAC;IAEF,kCAAkC;IAClC,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,CAAC;QACxC,oBAAoB,CAAC,aAAa;YAChC,OAAO,oBAAoB,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;gBAC9C,gBAAgB,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAI,SAAS;gBAC3D,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;IAED,OAAO,oBAAiC,CAAC;AAC3C,CAAC","sourcesContent":["import type { GraphQLRequest, Operation } from \"../core/index.js\";\nimport { getOperationName } from \"../../utilities/index.js\";\n\nexport function transformOperation(operation: GraphQLRequest): GraphQLRequest {\n const transformedOperation: GraphQLRequest = {\n variables: operation.variables || {},\n extensions: operation.extensions || {},\n operationName: operation.operationName,\n query: operation.query,\n };\n\n // Best guess at an operation name\n if (!transformedOperation.operationName) {\n transformedOperation.operationName =\n typeof transformedOperation.query !== \"string\" ?\n getOperationName(transformedOperation.query) || undefined\n : \"\";\n }\n\n return transformedOperation as Operation;\n}\n"]}

View File

@@ -0,0 +1,134 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var utilities = require('../../utilities');
var tslib = require('tslib');
var graphql = require('graphql');
function fromError(errorValue) {
return new utilities.Observable(function (observer) {
observer.error(errorValue);
});
}
function toPromise(observable) {
var completed = false;
return new Promise(function (resolve, reject) {
observable.subscribe({
next: function (data) {
if (completed) {
globalThis.__DEV__ !== false && globals.invariant.warn(42);
}
else {
completed = true;
resolve(data);
}
},
error: reject,
});
});
}
function fromPromise(promise) {
return new utilities.Observable(function (observer) {
promise
.then(function (value) {
observer.next(value);
observer.complete();
})
.catch(observer.error.bind(observer));
});
}
var throwServerError = function (response, result, message) {
var error = new Error(message);
error.name = "ServerError";
error.response = response;
error.statusCode = response.status;
error.result = result;
throw error;
};
function validateOperation(operation) {
var OPERATION_FIELDS = [
"query",
"operationName",
"variables",
"extensions",
"context",
];
for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
var key = _a[_i];
if (OPERATION_FIELDS.indexOf(key) < 0) {
throw globals.newInvariantError(43, key);
}
}
return operation;
}
function createOperation(starting, operation) {
var context = tslib.__assign({}, starting);
var setContext = function (next) {
if (typeof next === "function") {
context = tslib.__assign(tslib.__assign({}, context), next(context));
}
else {
context = tslib.__assign(tslib.__assign({}, context), next);
}
};
var getContext = function () { return (tslib.__assign({}, context)); };
Object.defineProperty(operation, "setContext", {
enumerable: false,
value: setContext,
});
Object.defineProperty(operation, "getContext", {
enumerable: false,
value: getContext,
});
return operation;
}
function transformOperation(operation) {
var transformedOperation = {
variables: operation.variables || {},
extensions: operation.extensions || {},
operationName: operation.operationName,
query: operation.query,
};
if (!transformedOperation.operationName) {
transformedOperation.operationName =
typeof transformedOperation.query !== "string" ?
utilities.getOperationName(transformedOperation.query) || undefined
: "";
}
return transformedOperation;
}
function filterOperationVariables(variables, query) {
var result = tslib.__assign({}, variables);
var unusedNames = new Set(Object.keys(variables));
graphql.visit(query, {
Variable: function (node, _key, parent) {
if (parent &&
parent.kind !== "VariableDefinition") {
unusedNames.delete(node.name.value);
}
},
});
unusedNames.forEach(function (name) {
delete result[name];
});
return result;
}
exports.createOperation = createOperation;
exports.filterOperationVariables = filterOperationVariables;
exports.fromError = fromError;
exports.fromPromise = fromPromise;
exports.throwServerError = throwServerError;
exports.toPromise = toPromise;
exports.transformOperation = transformOperation;
exports.validateOperation = validateOperation;
//# sourceMappingURL=utils.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,134 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var utilities = require('../../utilities');
var tslib = require('tslib');
var graphql = require('graphql');
function fromError(errorValue) {
return new utilities.Observable(function (observer) {
observer.error(errorValue);
});
}
function toPromise(observable) {
var completed = false;
return new Promise(function (resolve, reject) {
observable.subscribe({
next: function (data) {
if (completed) {
globalThis.__DEV__ !== false && globals.invariant.warn(42);
}
else {
completed = true;
resolve(data);
}
},
error: reject,
});
});
}
function fromPromise(promise) {
return new utilities.Observable(function (observer) {
promise
.then(function (value) {
observer.next(value);
observer.complete();
})
.catch(observer.error.bind(observer));
});
}
var throwServerError = function (response, result, message) {
var error = new Error(message);
error.name = "ServerError";
error.response = response;
error.statusCode = response.status;
error.result = result;
throw error;
};
function validateOperation(operation) {
var OPERATION_FIELDS = [
"query",
"operationName",
"variables",
"extensions",
"context",
];
for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
var key = _a[_i];
if (OPERATION_FIELDS.indexOf(key) < 0) {
throw globals.newInvariantError(43, key);
}
}
return operation;
}
function createOperation(starting, operation) {
var context = tslib.__assign({}, starting);
var setContext = function (next) {
if (typeof next === "function") {
context = tslib.__assign(tslib.__assign({}, context), next(context));
}
else {
context = tslib.__assign(tslib.__assign({}, context), next);
}
};
var getContext = function () { return (tslib.__assign({}, context)); };
Object.defineProperty(operation, "setContext", {
enumerable: false,
value: setContext,
});
Object.defineProperty(operation, "getContext", {
enumerable: false,
value: getContext,
});
return operation;
}
function transformOperation(operation) {
var transformedOperation = {
variables: operation.variables || {},
extensions: operation.extensions || {},
operationName: operation.operationName,
query: operation.query,
};
if (!transformedOperation.operationName) {
transformedOperation.operationName =
typeof transformedOperation.query !== "string" ?
utilities.getOperationName(transformedOperation.query) || undefined
: "";
}
return transformedOperation;
}
function filterOperationVariables(variables, query) {
var result = tslib.__assign({}, variables);
var unusedNames = new Set(Object.keys(variables));
graphql.visit(query, {
Variable: function (node, _key, parent) {
if (parent &&
parent.kind !== "VariableDefinition") {
unusedNames.delete(node.name.value);
}
},
});
unusedNames.forEach(function (name) {
delete result[name];
});
return result;
}
exports.createOperation = createOperation;
exports.filterOperationVariables = filterOperationVariables;
exports.fromError = fromError;
exports.fromPromise = fromPromise;
exports.throwServerError = throwServerError;
exports.toPromise = toPromise;
exports.transformOperation = transformOperation;
exports.validateOperation = validateOperation;
//# sourceMappingURL=utils.cjs.map

View File

@@ -0,0 +1,3 @@
import type { GraphQLRequest } from "../core/index.js";
export declare function validateOperation(operation: GraphQLRequest): GraphQLRequest;
//# sourceMappingURL=validateOperation.d.ts.map

View File

@@ -0,0 +1,18 @@
import { newInvariantError } from "../../utilities/globals/index.js";
export function validateOperation(operation) {
var OPERATION_FIELDS = [
"query",
"operationName",
"variables",
"extensions",
"context",
];
for (var _i = 0, _a = Object.keys(operation); _i < _a.length; _i++) {
var key = _a[_i];
if (OPERATION_FIELDS.indexOf(key) < 0) {
throw newInvariantError(43, key);
}
}
return operation;
}
//# sourceMappingURL=validateOperation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validateOperation.js","sourceRoot":"","sources":["../../../src/link/utils/validateOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGrE,MAAM,UAAU,iBAAiB,CAAC,SAAyB;IACzD,IAAM,gBAAgB,GAAG;QACvB,OAAO;QACP,eAAe;QACf,WAAW;QACX,YAAY;QACZ,SAAS;KACV,CAAC;IACF,KAAgB,UAAsB,EAAtB,KAAA,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;QAApC,IAAI,GAAG,SAAA;QACV,IAAI,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,iBAAiB,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { newInvariantError } from \"../../utilities/globals/index.js\";\nimport type { GraphQLRequest } from \"../core/index.js\";\n\nexport function validateOperation(operation: GraphQLRequest): GraphQLRequest {\n const OPERATION_FIELDS = [\n \"query\",\n \"operationName\",\n \"variables\",\n \"extensions\",\n \"context\",\n ];\n for (let key of Object.keys(operation)) {\n if (OPERATION_FIELDS.indexOf(key) < 0) {\n throw newInvariantError(`illegal argument: %s`, key);\n }\n }\n\n return operation;\n}\n"]}