Initial Save

This commit is contained in:
jackbeeby
2025-03-28 12:30:19 +11:00
parent e381994f19
commit d8773925e8
9910 changed files with 982718 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import { GraphQLSchema, DocumentNode, GraphQLError } from "graphql";
import { GraphQLResolverMap } from "./schema/resolverMap";
export interface GraphQLSchemaModule {
typeDefs: DocumentNode;
resolvers?: GraphQLResolverMap<any>;
}
interface GraphQLServiceDefinition {
schema?: GraphQLSchema;
errors?: GraphQLError[];
}
export declare function buildServiceDefinition(modules: (GraphQLSchemaModule | DocumentNode)[]): GraphQLServiceDefinition;
export {};
//# sourceMappingURL=buildServiceDefinition.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"buildServiceDefinition.d.ts","sourceRoot":"","sources":["../src/buildServiceDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EAMZ,YAAY,EAQb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,CAAC;IACvB,SAAS,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;CACrC;AAED,UAAU,wBAAwB;IAChC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB;AAMD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,CAAC,mBAAmB,GAAG,YAAY,CAAC,EAAE,GAC9C,wBAAwB,CA+K1B"}

View File

@@ -0,0 +1,168 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildServiceDefinition = void 0;
const graphql_1 = require("graphql");
const graphql_2 = require("./utilities/graphql");
const predicates_1 = require("./utilities/predicates");
function flattened(arr) {
return new Array().concat(...arr);
}
function buildServiceDefinition(modules) {
const errors = [];
const typeDefinitionsMap = Object.create(null);
const typeExtensionsMap = Object.create(null);
const directivesMap = Object.create(null);
const schemaDefinitions = [];
const schemaExtensions = [];
for (let module of modules) {
if ((0, graphql_2.isNode)(module) && (0, graphql_2.isDocumentNode)(module)) {
module = { typeDefs: module };
}
for (const definition of module.typeDefs.definitions) {
if ((0, graphql_1.isTypeDefinitionNode)(definition)) {
const typeName = definition.name.value;
if (typeDefinitionsMap[typeName]) {
typeDefinitionsMap[typeName].push(definition);
}
else {
typeDefinitionsMap[typeName] = [definition];
}
}
else if ((0, graphql_1.isTypeExtensionNode)(definition)) {
const typeName = definition.name.value;
if (typeExtensionsMap[typeName]) {
typeExtensionsMap[typeName].push(definition);
}
else {
typeExtensionsMap[typeName] = [definition];
}
}
else if (definition.kind === graphql_1.Kind.DIRECTIVE_DEFINITION) {
const directiveName = definition.name.value;
if (directivesMap[directiveName]) {
directivesMap[directiveName].push(definition);
}
else {
directivesMap[directiveName] = [definition];
}
}
else if (definition.kind === graphql_1.Kind.SCHEMA_DEFINITION) {
schemaDefinitions.push(definition);
}
else if (definition.kind === graphql_1.Kind.SCHEMA_EXTENSION) {
schemaExtensions.push(definition);
}
}
}
for (const [typeName, typeDefinitions] of Object.entries(typeDefinitionsMap)) {
if (typeDefinitions.length > 1) {
errors.push(new graphql_1.GraphQLError(`Type "${typeName}" was defined more than once.`, typeDefinitions));
}
}
for (const [directiveName, directives] of Object.entries(directivesMap)) {
if (directives.length > 1) {
errors.push(new graphql_1.GraphQLError(`Directive "${directiveName}" was defined more than once.`, directives));
}
}
let operationTypeMap;
if (schemaDefinitions.length > 0 || schemaExtensions.length > 0) {
operationTypeMap = {};
const schemaDefinition = schemaDefinitions[schemaDefinitions.length - 1];
const operationTypes = flattened([schemaDefinition, ...schemaExtensions]
.map((node) => node.operationTypes)
.filter(predicates_1.isNotNullOrUndefined));
for (const operationType of operationTypes) {
const typeName = operationType.type.name.value;
const operation = operationType.operation;
if (operationTypeMap[operation]) {
throw new graphql_1.GraphQLError(`Must provide only one ${operation} type in schema.`, [schemaDefinition]);
}
if (!(typeDefinitionsMap[typeName] || typeExtensionsMap[typeName])) {
throw new graphql_1.GraphQLError(`Specified ${operation} type "${typeName}" not found in document.`, [schemaDefinition]);
}
operationTypeMap[operation] = typeName;
}
}
else {
operationTypeMap = {
query: "Query",
mutation: "Mutation",
subscription: "Subscription",
};
}
for (const [typeName, typeExtensions] of Object.entries(typeExtensionsMap)) {
if (!typeDefinitionsMap[typeName]) {
if (Object.values(operationTypeMap).includes(typeName)) {
typeDefinitionsMap[typeName] = [
{
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
name: {
kind: graphql_1.Kind.NAME,
value: typeName,
},
},
];
}
else {
errors.push(new graphql_1.GraphQLError(`Cannot extend type "${typeName}" because it does not exist in the existing schema.`, typeExtensions));
}
}
}
if (errors.length > 0) {
return { errors };
}
try {
const typeDefinitions = flattened(Object.values(typeDefinitionsMap));
const directives = flattened(Object.values(directivesMap));
let schema = (0, graphql_1.buildASTSchema)({
kind: graphql_1.Kind.DOCUMENT,
definitions: [...typeDefinitions, ...directives],
});
const typeExtensions = flattened(Object.values(typeExtensionsMap));
if (typeExtensions.length > 0) {
schema = (0, graphql_1.extendSchema)(schema, {
kind: graphql_1.Kind.DOCUMENT,
definitions: typeExtensions,
});
}
for (const module of modules) {
if ("kind" in module || !module.resolvers)
continue;
addResolversToSchema(schema, module.resolvers);
}
return { schema };
}
catch (error) {
return { errors: [error] };
}
}
exports.buildServiceDefinition = buildServiceDefinition;
function addResolversToSchema(schema, resolvers) {
for (const [typeName, fieldConfigs] of Object.entries(resolvers)) {
const type = schema.getType(typeName);
if (!(0, graphql_1.isObjectType)(type))
continue;
const fieldMap = type.getFields();
for (const [fieldName, fieldConfig] of Object.entries(fieldConfigs)) {
if (fieldName.startsWith("__")) {
type[fieldName.substring(2)] = fieldConfig;
continue;
}
const field = fieldMap[fieldName];
if (!field)
continue;
if (typeof fieldConfig === "function") {
field.resolve = fieldConfig;
}
else {
if (fieldConfig.resolve) {
field.resolve = fieldConfig.resolve;
}
if (fieldConfig.subscribe) {
field.subscribe = fieldConfig.subscribe;
}
}
}
}
}
//# sourceMappingURL=buildServiceDefinition.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
export * from "./utilities";
export * from "./schema";
export * from "./buildServiceDefinition";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC"}

20
node_modules/@apollographql/apollo-tools/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./utilities"), exports);
__exportStar(require("./schema"), exports);
__exportStar(require("./buildServiceDefinition"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAE5B,2CAAyB;AACzB,2DAAyC"}

View File

@@ -0,0 +1,3 @@
export * from "./resolverMap";
export * from "./resolveObject";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}

View File

@@ -0,0 +1,19 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./resolverMap"), exports);
__exportStar(require("./resolveObject"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC"}

View File

@@ -0,0 +1,11 @@
import { GraphQLResolveInfo, FieldNode } from "graphql";
export declare type GraphQLObjectResolver<TSource, TContext> = (source: TSource, fields: Record<string, ReadonlyArray<FieldNode>>, context: TContext, info: GraphQLResolveInfo) => any;
declare module "graphql/type/definition" {
interface GraphQLObjectType {
resolveObject?: GraphQLObjectResolver<any, any>;
}
interface GraphQLObjectTypeConfig<TSource, TContext> {
resolveObject?: GraphQLObjectResolver<TSource, TContext>;
}
}
//# sourceMappingURL=resolveObject.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolveObject.d.ts","sourceRoot":"","sources":["../../src/schema/resolveObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAExD,oBAAY,qBAAqB,CAAC,OAAO,EAAE,QAAQ,IAAI,CACrD,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,EAChD,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,kBAAkB,KACrB,GAAG,CAAC;AAET,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,iBAAiB;QACzB,aAAa,CAAC,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACjD;IAED,UAAU,uBAAuB,CAAC,OAAO,EAAE,QAAQ;QACjD,aAAa,CAAC,EAAE,qBAAqB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;KAC1D;CACF"}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=resolveObject.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolveObject.js","sourceRoot":"","sources":["../../src/schema/resolveObject.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,19 @@
import { GraphQLFieldResolver } from "graphql";
export interface GraphQLResolverMap<TContext> {
[typeName: string]: {
[fieldName: string]: GraphQLFieldResolver<any, TContext> | {
requires?: string;
resolve: GraphQLFieldResolver<any, TContext>;
subscribe?: undefined;
} | {
requires?: string;
resolve?: undefined;
subscribe: GraphQLFieldResolver<any, TContext>;
} | {
requires?: string;
resolve: GraphQLFieldResolver<any, TContext>;
subscribe: GraphQLFieldResolver<any, TContext>;
};
};
}
//# sourceMappingURL=resolverMap.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolverMap.d.ts","sourceRoot":"","sources":["../../src/schema/resolverMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,kBAAkB,CAAC,QAAQ;IAC1C,CAAC,QAAQ,EAAE,MAAM,GAAG;QAClB,CAAC,SAAS,EAAE,MAAM,GACd,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,GACnC;YACE,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7C,SAAS,CAAC,EAAE,SAAS,CAAC;SACvB,GACD;YACE,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,OAAO,CAAC,EAAE,SAAS,CAAC;YACpB,SAAS,EAAE,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SAChD,GACD;YACE,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7C,SAAS,EAAE,oBAAoB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SAChD,CAAC;KACP,CAAC;CACH"}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=resolverMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolverMap.js","sourceRoot":"","sources":["../../src/schema/resolverMap.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,8 @@
import { ASTNode, TypeDefinitionNode, TypeExtensionNode, DocumentNode } from "graphql";
declare module "graphql/language/predicates" {
function isTypeDefinitionNode(node: ASTNode): node is TypeDefinitionNode;
function isTypeExtensionNode(node: ASTNode): node is TypeExtensionNode;
}
export declare function isNode(maybeNode: any): maybeNode is ASTNode;
export declare function isDocumentNode(node: ASTNode): node is DocumentNode;
//# sourceMappingURL=graphql.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/utilities/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EAEb,MAAM,SAAS,CAAC;AAIjB,OAAO,QAAQ,6BAA6B,CAAC;IAC3C,SAAS,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,kBAAkB,CAAC;IACzE,SAAS,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,iBAAiB,CAAC;CACxE;AAED,wBAAgB,MAAM,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,IAAI,OAAO,CAE3D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAElE"}

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDocumentNode = exports.isNode = void 0;
const graphql_1 = require("graphql");
function isNode(maybeNode) {
return maybeNode && typeof maybeNode.kind === "string";
}
exports.isNode = isNode;
function isDocumentNode(node) {
return isNode(node) && node.kind === graphql_1.Kind.DOCUMENT;
}
exports.isDocumentNode = isDocumentNode;
//# sourceMappingURL=graphql.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/utilities/graphql.ts"],"names":[],"mappings":";;;AAAA,qCAMiB;AASjB,SAAgB,MAAM,CAAC,SAAc;IACnC,OAAO,SAAS,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,CAAC;AACzD,CAAC;AAFD,wBAEC;AAED,SAAgB,cAAc,CAAC,IAAa;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAI,CAAC,QAAQ,CAAC;AACrD,CAAC;AAFD,wCAEC"}

View File

@@ -0,0 +1,4 @@
export * from "./invariant";
export * from "./predicates";
export * from "./graphql";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}

View File

@@ -0,0 +1,20 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./invariant"), exports);
__exportStar(require("./predicates"), exports);
__exportStar(require("./graphql"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,+CAA6B;AAC7B,4CAA0B"}

View File

@@ -0,0 +1,2 @@
export declare function invariant(condition: any, message: string): void;
//# sourceMappingURL=invariant.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/utilities/invariant.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,QAIxD"}

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invariant = void 0;
function invariant(condition, message) {
if (!condition) {
throw new Error(message);
}
}
exports.invariant = invariant;
//# sourceMappingURL=invariant.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../../src/utilities/invariant.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAC,SAAc,EAAE,OAAe;IACvD,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAJD,8BAIC"}

View File

@@ -0,0 +1,2 @@
export declare function isNotNullOrUndefined<T>(value: T | null | undefined): value is T;
//# sourceMappingURL=predicates.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../src/utilities/predicates.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAC1B,KAAK,IAAI,CAAC,CAEZ"}

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotNullOrUndefined = void 0;
function isNotNullOrUndefined(value) {
return value !== null && typeof value !== "undefined";
}
exports.isNotNullOrUndefined = isNotNullOrUndefined;
//# sourceMappingURL=predicates.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/utilities/predicates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,oBAAoB,CAClC,KAA2B;IAE3B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,CAAC;AACxD,CAAC;AAJD,oDAIC"}