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,36 @@
import type { GraphQLSchema } from "graphql";
import type { Operation, FetchResult } from "../core/index.js";
import { ApolloLink } from "../core/index.js";
import { Observable } from "../../utilities/index.js";
export declare namespace SchemaLink {
type ResolverContext = Record<string, any>;
type ResolverContextFunction = (operation: Operation) => ResolverContext | PromiseLike<ResolverContext>;
interface Options {
/**
* The schema to generate responses from.
*/
schema: GraphQLSchema;
/**
* The root value to use when generating responses.
*/
rootValue?: any;
/**
* A context to provide to resolvers declared within the schema.
*/
context?: ResolverContext | ResolverContextFunction;
/**
* Validate incoming queries against the given schema, returning
* validation errors as a GraphQL server would.
*/
validate?: boolean;
}
}
export declare class SchemaLink extends ApolloLink {
schema: SchemaLink.Options["schema"];
rootValue: SchemaLink.Options["rootValue"];
context: SchemaLink.Options["context"];
validate: boolean;
constructor(options: SchemaLink.Options);
request(operation: Operation): Observable<FetchResult>;
}
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,55 @@
import { __extends } from "tslib";
import { validate, execute } from "graphql";
import { ApolloLink } from "../core/index.js";
import { Observable } from "../../utilities/index.js";
var SchemaLink = /** @class */ (function (_super) {
__extends(SchemaLink, _super);
function SchemaLink(options) {
var _this = _super.call(this) || this;
_this.schema = options.schema;
_this.rootValue = options.rootValue;
_this.context = options.context;
_this.validate = !!options.validate;
return _this;
}
SchemaLink.prototype.request = function (operation) {
var _this = this;
return new Observable(function (observer) {
new Promise(function (resolve) {
return resolve(typeof _this.context === "function" ?
_this.context(operation)
: _this.context);
})
.then(function (context) {
if (_this.validate) {
var validationErrors = validate(_this.schema, operation.query);
if (validationErrors.length > 0) {
return { errors: validationErrors };
}
}
return execute({
schema: _this.schema,
document: operation.query,
rootValue: _this.rootValue,
contextValue: context,
variableValues: operation.variables,
operationName: operation.operationName,
});
})
.then(function (data) {
if (!observer.closed) {
observer.next(data);
observer.complete();
}
})
.catch(function (error) {
if (!observer.closed) {
observer.error(error);
}
});
});
};
return SchemaLink;
}(ApolloLink));
export { SchemaLink };
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/schema/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAgCtD;IAAgC,8BAAU;IAMxC,oBAAY,OAA2B;QACrC,YAAA,MAAK,WAAE,SAAC;QACR,KAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,KAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,KAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;;IACrC,CAAC;IAEM,4BAAO,GAAd,UAAe,SAAoB;QAAnC,iBAsCC;QArCC,OAAO,IAAI,UAAU,CAAc,UAAC,QAAQ;YAC1C,IAAI,OAAO,CAA6B,UAAC,OAAO;gBAC9C,OAAA,OAAO,CACL,OAAO,KAAI,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;oBAClC,KAAI,CAAC,OAAO,CAAC,SAAS,CAAC;oBACzB,CAAC,CAAC,KAAI,CAAC,OAAO,CACf;YAJD,CAIC,CACF;iBACE,IAAI,CAAC,UAAC,OAAO;gBACZ,IAAI,KAAI,CAAC,QAAQ,EAAE,CAAC;oBAClB,IAAM,gBAAgB,GAAG,QAAQ,CAAC,KAAI,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;oBAChE,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAChC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;oBACtC,CAAC;gBACH,CAAC;gBAED,OAAO,OAAO,CAAC;oBACb,MAAM,EAAE,KAAI,CAAC,MAAM;oBACnB,QAAQ,EAAE,SAAS,CAAC,KAAK;oBACzB,SAAS,EAAE,KAAI,CAAC,SAAS;oBACzB,YAAY,EAAE,OAAO;oBACrB,cAAc,EAAE,SAAS,CAAC,SAAS;oBACnC,aAAa,EAAE,SAAS,CAAC,aAAa;iBACvC,CAAC,CAAC;YACL,CAAC,CAAC;iBACD,IAAI,CAAC,UAAC,IAAI;gBACT,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;oBACrB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,CAAC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,UAAC,KAAK;gBACX,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;oBACrB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;IACH,iBAAC;AAAD,CAAC,AArDD,CAAgC,UAAU,GAqDzC","sourcesContent":["import type { GraphQLSchema } from \"graphql\";\nimport { validate, execute } from \"graphql\";\n\nimport type { Operation, FetchResult } from \"../core/index.js\";\nimport { ApolloLink } from \"../core/index.js\";\nimport { Observable } from \"../../utilities/index.js\";\n\nexport namespace SchemaLink {\n export type ResolverContext = Record<string, any>;\n export type ResolverContextFunction = (\n operation: Operation\n ) => ResolverContext | PromiseLike<ResolverContext>;\n\n export interface Options {\n /**\n * The schema to generate responses from.\n */\n schema: GraphQLSchema;\n\n /**\n * The root value to use when generating responses.\n */\n rootValue?: any;\n\n /**\n * A context to provide to resolvers declared within the schema.\n */\n context?: ResolverContext | ResolverContextFunction;\n\n /**\n * Validate incoming queries against the given schema, returning\n * validation errors as a GraphQL server would.\n */\n validate?: boolean;\n }\n}\n\nexport class SchemaLink extends ApolloLink {\n public schema: SchemaLink.Options[\"schema\"];\n public rootValue: SchemaLink.Options[\"rootValue\"];\n public context: SchemaLink.Options[\"context\"];\n public validate: boolean;\n\n constructor(options: SchemaLink.Options) {\n super();\n this.schema = options.schema;\n this.rootValue = options.rootValue;\n this.context = options.context;\n this.validate = !!options.validate;\n }\n\n public request(operation: Operation): Observable<FetchResult> {\n return new Observable<FetchResult>((observer) => {\n new Promise<SchemaLink.ResolverContext>((resolve) =>\n resolve(\n typeof this.context === \"function\" ?\n this.context(operation)\n : this.context\n )\n )\n .then((context) => {\n if (this.validate) {\n const validationErrors = validate(this.schema, operation.query);\n if (validationErrors.length > 0) {\n return { errors: validationErrors };\n }\n }\n\n return execute({\n schema: this.schema,\n document: operation.query,\n rootValue: this.rootValue,\n contextValue: context,\n variableValues: operation.variables,\n operationName: operation.operationName,\n });\n })\n .then((data) => {\n if (!observer.closed) {\n observer.next(data);\n observer.complete();\n }\n })\n .catch((error) => {\n if (!observer.closed) {\n observer.error(error);\n }\n });\n });\n }\n}\n"]}

View File

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

View File

@@ -0,0 +1,61 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var graphql = require('graphql');
var core = require('../core');
var utilities = require('../../utilities');
var SchemaLink = (function (_super) {
tslib.__extends(SchemaLink, _super);
function SchemaLink(options) {
var _this = _super.call(this) || this;
_this.schema = options.schema;
_this.rootValue = options.rootValue;
_this.context = options.context;
_this.validate = !!options.validate;
return _this;
}
SchemaLink.prototype.request = function (operation) {
var _this = this;
return new utilities.Observable(function (observer) {
new Promise(function (resolve) {
return resolve(typeof _this.context === "function" ?
_this.context(operation)
: _this.context);
})
.then(function (context) {
if (_this.validate) {
var validationErrors = graphql.validate(_this.schema, operation.query);
if (validationErrors.length > 0) {
return { errors: validationErrors };
}
}
return graphql.execute({
schema: _this.schema,
document: operation.query,
rootValue: _this.rootValue,
contextValue: context,
variableValues: operation.variables,
operationName: operation.operationName,
});
})
.then(function (data) {
if (!observer.closed) {
observer.next(data);
observer.complete();
}
})
.catch(function (error) {
if (!observer.closed) {
observer.error(error);
}
});
});
};
return SchemaLink;
}(core.ApolloLink));
exports.SchemaLink = SchemaLink;
//# sourceMappingURL=schema.cjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.cjs","sources":["index.js"],"sourcesContent":["import { __extends } from \"tslib\";\nimport { validate, execute } from \"graphql\";\nimport { ApolloLink } from \"../core/index.js\";\nimport { Observable } from \"../../utilities/index.js\";\nvar SchemaLink = /** @class */ (function (_super) {\n __extends(SchemaLink, _super);\n function SchemaLink(options) {\n var _this = _super.call(this) || this;\n _this.schema = options.schema;\n _this.rootValue = options.rootValue;\n _this.context = options.context;\n _this.validate = !!options.validate;\n return _this;\n }\n SchemaLink.prototype.request = function (operation) {\n var _this = this;\n return new Observable(function (observer) {\n new Promise(function (resolve) {\n return resolve(typeof _this.context === \"function\" ?\n _this.context(operation)\n : _this.context);\n })\n .then(function (context) {\n if (_this.validate) {\n var validationErrors = validate(_this.schema, operation.query);\n if (validationErrors.length > 0) {\n return { errors: validationErrors };\n }\n }\n return execute({\n schema: _this.schema,\n document: operation.query,\n rootValue: _this.rootValue,\n contextValue: context,\n variableValues: operation.variables,\n operationName: operation.operationName,\n });\n })\n .then(function (data) {\n if (!observer.closed) {\n observer.next(data);\n observer.complete();\n }\n })\n .catch(function (error) {\n if (!observer.closed) {\n observer.error(error);\n }\n });\n });\n };\n return SchemaLink;\n}(ApolloLink));\nexport { SchemaLink };\n//# sourceMappingURL=index.js.map"],"names":["__extends","Observable","validate","execute","ApolloLink"],"mappings":";;;;;;;;;AAIG,IAAC,UAAU,KAAkB,UAAU,MAAM,EAAE;AAClD,IAAIA,eAAS,CAAC,UAAU,EAAE,MAAM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AAoB,MAAM,EAAE,KAAK,CAAC,MAAM;AACxC,oBAAoB,QAAQ,EAAE,SAAS,CAAC,KAAK;AAC7C,oBAAoB,SAAS,EAAE,KAAK,CAAC,SAAS;AAC9C,oBAAoB,YAAY,EAAE,OAAO;AACzC,oBAAoB,cAAc,EAAE,SAAS,CAAC,SAAS;AACvD,oBAAoB,aAAa,EAAE,SAAS,CAAC,aAAa;AAC1D,iBAAiB,CAAC,CAAC;AACnB,aAAa,CAAC;AACd,iBAAiB,IAAI,CAAC,UAAU,IAAI,EAAE;AACtC,gBAAgB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;AACtC,oBAAoB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxC,oBAAoB,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACxC,iBAAiB;AACjB,aAAa,CAAC;AACd,iBAAiB,KAAK,CAAC,UAAU,KAAK,EAAE;AACxC,gBAAgB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;AACtC,oBAAoB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,IAAI,OAAO,UAAU,CAAC;AACtB,CAAC,CAACC,eAAU,CAAC;;;;"}

View File

@@ -0,0 +1,61 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var graphql = require('graphql');
var core = require('../core');
var utilities = require('../../utilities');
var SchemaLink = (function (_super) {
tslib.__extends(SchemaLink, _super);
function SchemaLink(options) {
var _this = _super.call(this) || this;
_this.schema = options.schema;
_this.rootValue = options.rootValue;
_this.context = options.context;
_this.validate = !!options.validate;
return _this;
}
SchemaLink.prototype.request = function (operation) {
var _this = this;
return new utilities.Observable(function (observer) {
new Promise(function (resolve) {
return resolve(typeof _this.context === "function" ?
_this.context(operation)
: _this.context);
})
.then(function (context) {
if (_this.validate) {
var validationErrors = graphql.validate(_this.schema, operation.query);
if (validationErrors.length > 0) {
return { errors: validationErrors };
}
}
return graphql.execute({
schema: _this.schema,
document: operation.query,
rootValue: _this.rootValue,
contextValue: context,
variableValues: operation.variables,
operationName: operation.operationName,
});
})
.then(function (data) {
if (!observer.closed) {
observer.next(data);
observer.complete();
}
})
.catch(function (error) {
if (!observer.closed) {
observer.error(error);
}
});
});
};
return SchemaLink;
}(core.ApolloLink));
exports.SchemaLink = SchemaLink;
//# sourceMappingURL=schema.cjs.map