@ttoss/graphql-api 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/graphql-api",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "A library for building GraphQL APIs using ttoss ecosystem.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -42,7 +42,7 @@
42
42
  "ts-node": "^10.9.2",
43
43
  "tsconfig-paths": "^4.2.0",
44
44
  "yargs": "^17.7.2",
45
- "@ttoss/ids": "^0.2.10"
45
+ "@ttoss/ids": "^0.2.11"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "graphql": "^16.6.0"
@@ -52,7 +52,7 @@
52
52
  "graphql": "^16.8.1",
53
53
  "jest": "^29.7.0",
54
54
  "tsup": "^8.3.0",
55
- "@ttoss/config": "^1.32.10"
55
+ "@ttoss/config": "^1.33.0"
56
56
  },
57
57
  "keywords": [
58
58
  "api",
package/dist/cli.d.mts DELETED
@@ -1,2 +0,0 @@
1
- import 'graphql-shield';
2
- import 'graphql-middleware';
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import 'graphql-shield';
2
- import 'graphql-middleware';
package/dist/cli.js DELETED
@@ -1,120 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: () => from[key],
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
- value: mod,
26
- enumerable: true
27
- }) : target, mod));
28
-
29
- // src/cli.ts
30
- var fs = __toESM(require("fs"));
31
- var path = __toESM(require("path"));
32
- var typescriptPlugin = __toESM(require("@graphql-codegen/typescript"));
33
- var import_core = require("@graphql-codegen/core");
34
- var import_helpers = require("yargs/helpers");
35
- var import_graphql = require("graphql");
36
- var import_ts_node = require("ts-node");
37
- var import_tsconfig_paths = require("tsconfig-paths");
38
- var import_npmlog = __toESM(require("npmlog"));
39
- var import_yargs = __toESM(require("yargs"));
40
- var logPrefix = "graphql-api";
41
- var tsConfig = require(path.resolve(process.cwd(), "tsconfig.json"));
42
- var cleanup = () => {};
43
- try {
44
- const baseUrl = tsConfig?.compilerOptions?.baseUrl;
45
- const paths = tsConfig?.compilerOptions?.paths;
46
- if (baseUrl && !paths || !baseUrl && paths) {
47
- throw new Error("tsconfig.json must have 'baseUrl' and 'paths' properties.");
48
- }
49
- if (baseUrl && paths) {
50
- cleanup = (0, import_tsconfig_paths.register)({
51
- baseUrl: tsConfig.compilerOptions.baseUrl,
52
- paths: tsConfig.compilerOptions.paths
53
- });
54
- }
55
- } catch (error) {
56
- error instanceof Error && import_npmlog.default.error(logPrefix, error.message);
57
- process.exit(1);
58
- }
59
- (0, import_ts_node.register)({
60
- transpileOnly: true,
61
- compilerOptions: {
62
- module: "NodeNext",
63
- moduleResolution: "NodeNext"
64
- }
65
- });
66
- var buildSchema = async ({
67
- directory
68
- }) => {
69
- import_npmlog.default.info(logPrefix, "Building schema...");
70
- await fs.promises.mkdir("schema", {
71
- recursive: true
72
- });
73
- try {
74
- await fs.promises.access("schema/types.ts");
75
- } catch {
76
- await fs.promises.writeFile("schema/types.ts", "");
77
- }
78
- const {
79
- schemaComposer
80
- } = require(path.resolve(process.cwd(), directory, "schemaComposer.ts"));
81
- const sdl = schemaComposer.toSDL();
82
- const codegenConfig = {
83
- documents: [],
84
- config: {
85
- declarationKind: {
86
- type: "interface",
87
- interface: "interface"
88
- },
89
- namingConvention: "keep"
90
- },
91
- filename: "schema/types.ts",
92
- schema: (0, import_graphql.parse)(sdl),
93
- plugins: [{
94
- typescript: {}
95
- }],
96
- pluginMap: {
97
- typescript: typescriptPlugin
98
- }
99
- };
100
- await fs.promises.writeFile("schema/schema.graphql", sdl);
101
- import_npmlog.default.info(logPrefix, "Generating types...");
102
- const typesOutput = await (0, import_core.codegen)(codegenConfig);
103
- const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
104
- await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
105
- ${typesOutput}`);
106
- cleanup();
107
- import_npmlog.default.info(logPrefix, "Schema and types generated!");
108
- };
109
- (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).command("build-schema", "fetch the contents of the URL", yargs2 => {
110
- return yargs2.options({
111
- directory: {
112
- alias: ["d"],
113
- type: "string",
114
- describe: "Schema composer directory relative to the project root",
115
- default: "src"
116
- }
117
- });
118
- }, argv => {
119
- return buildSchema(argv);
120
- }).demandCommand(1).strictOptions().parse();
@@ -1,8 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function (x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
- export { __require };
package/dist/esm/cli.js DELETED
@@ -1,95 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { __require } from "./chunk-NT3ZWSM6.js";
3
-
4
- // src/cli.ts
5
- import * as fs from "node:fs";
6
- import * as path from "node:path";
7
- import * as typescriptPlugin from "@graphql-codegen/typescript";
8
- import { codegen } from "@graphql-codegen/core";
9
- import { hideBin } from "yargs/helpers";
10
- import { parse } from "graphql";
11
- import { register } from "ts-node";
12
- import { register as registerTsPaths } from "tsconfig-paths";
13
- import log from "npmlog";
14
- import yargs from "yargs";
15
- var logPrefix = "graphql-api";
16
- var tsConfig = __require(path.resolve(process.cwd(), "tsconfig.json"));
17
- var cleanup = () => {};
18
- try {
19
- const baseUrl = tsConfig?.compilerOptions?.baseUrl;
20
- const paths = tsConfig?.compilerOptions?.paths;
21
- if (baseUrl && !paths || !baseUrl && paths) {
22
- throw new Error("tsconfig.json must have 'baseUrl' and 'paths' properties.");
23
- }
24
- if (baseUrl && paths) {
25
- cleanup = registerTsPaths({
26
- baseUrl: tsConfig.compilerOptions.baseUrl,
27
- paths: tsConfig.compilerOptions.paths
28
- });
29
- }
30
- } catch (error) {
31
- error instanceof Error && log.error(logPrefix, error.message);
32
- process.exit(1);
33
- }
34
- register({
35
- transpileOnly: true,
36
- compilerOptions: {
37
- module: "NodeNext",
38
- moduleResolution: "NodeNext"
39
- }
40
- });
41
- var buildSchema = async ({
42
- directory
43
- }) => {
44
- log.info(logPrefix, "Building schema...");
45
- await fs.promises.mkdir("schema", {
46
- recursive: true
47
- });
48
- try {
49
- await fs.promises.access("schema/types.ts");
50
- } catch {
51
- await fs.promises.writeFile("schema/types.ts", "");
52
- }
53
- const {
54
- schemaComposer
55
- } = __require(path.resolve(process.cwd(), directory, "schemaComposer.ts"));
56
- const sdl = schemaComposer.toSDL();
57
- const codegenConfig = {
58
- documents: [],
59
- config: {
60
- declarationKind: {
61
- type: "interface",
62
- interface: "interface"
63
- },
64
- namingConvention: "keep"
65
- },
66
- filename: "schema/types.ts",
67
- schema: parse(sdl),
68
- plugins: [{
69
- typescript: {}
70
- }],
71
- pluginMap: {
72
- typescript: typescriptPlugin
73
- }
74
- };
75
- await fs.promises.writeFile("schema/schema.graphql", sdl);
76
- log.info(logPrefix, "Generating types...");
77
- const typesOutput = await codegen(codegenConfig);
78
- const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
79
- await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
80
- ${typesOutput}`);
81
- cleanup();
82
- log.info(logPrefix, "Schema and types generated!");
83
- };
84
- yargs(hideBin(process.argv)).command("build-schema", "fetch the contents of the URL", yargs2 => {
85
- return yargs2.options({
86
- directory: {
87
- alias: ["d"],
88
- type: "string",
89
- describe: "Schema composer directory relative to the project root",
90
- default: "src"
91
- }
92
- });
93
- }, argv => {
94
- return buildSchema(argv);
95
- }).demandCommand(1).strictOptions().parse();
package/dist/esm/index.js DELETED
@@ -1,161 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import "./chunk-NT3ZWSM6.js";
3
-
4
- // src/composeWithRelay/composeWithRelay.ts
5
- import { ObjectTypeComposer } from "graphql-compose";
6
-
7
- // src/composeWithRelay/nodeFieldConfig.ts
8
- import { getProjectionFromAST } from "graphql-compose";
9
- import { fromGlobalId } from "@ttoss/ids";
10
- var getNodeFieldConfig = (typeMapForRelayNode, nodeInterface) => {
11
- return {
12
- description: "Fetches an object that has globally unique ID among all types",
13
- type: nodeInterface,
14
- args: {
15
- id: {
16
- type: "ID!",
17
- description: "The globally unique ID among all types"
18
- }
19
- },
20
- // eslint-disable-next-line max-params
21
- resolve: (source, args, context, info) => {
22
- if (!args.id || !(typeof args.id === "string")) {
23
- return null;
24
- }
25
- const {
26
- type
27
- } = fromGlobalId(args.id);
28
- if (!typeMapForRelayNode[type]) {
29
- return null;
30
- }
31
- const {
32
- tc,
33
- resolver: findById
34
- } = typeMapForRelayNode[type];
35
- if (findById && findById.resolve && tc) {
36
- const graphqlType = tc.getType();
37
- let projection;
38
- if (info) {
39
- projection = getProjectionFromAST({
40
- ...info,
41
- returnType: graphqlType
42
- });
43
- } else {
44
- projection = {};
45
- }
46
- const idArgName = Object.keys(findById.args)[0];
47
- return findById.resolve({
48
- source,
49
- args: {
50
- [idArgName]: args.id
51
- },
52
- // eg. mongoose has _id fieldname, so should map
53
- context,
54
- info,
55
- projection
56
- }).then(res => {
57
- if (!res) {
58
- return res;
59
- }
60
- res.__nodeType = graphqlType;
61
- return res;
62
- });
63
- }
64
- return null;
65
- }
66
- };
67
- };
68
-
69
- // src/composeWithRelay/nodeInterface.ts
70
- import { InterfaceTypeComposer } from "graphql-compose";
71
- var NodeTC = InterfaceTypeComposer.createTemp({
72
- name: "Node",
73
- description: "An object, that can be fetched by the globally unique ID among all types.",
74
- fields: {
75
- id: {
76
- type: "ID!",
77
- description: "The globally unique ID among all types."
78
- }
79
- },
80
- resolveType: payload => {
81
- return payload.__nodeType.name ? payload.__nodeType.name : null;
82
- }
83
- });
84
- var NodeInterface = NodeTC.getType();
85
- var getNodeInterface = sc => {
86
- if (sc.hasInstance("Node", InterfaceTypeComposer)) {
87
- return sc.get("Node");
88
- }
89
- sc.set("Node", NodeTC);
90
- return NodeTC;
91
- };
92
-
93
- // src/composeWithRelay/composeWithRelay.ts
94
- import { toGlobalId } from "@ttoss/ids";
95
- var TypeMapForRelayNode = {};
96
- var composeWithRelay = tc => {
97
- if (!(tc instanceof ObjectTypeComposer)) {
98
- throw new Error("You should provide ObjectTypeComposer instance to composeWithRelay method");
99
- }
100
- const nodeInterface = getNodeInterface(tc.schemaComposer);
101
- const nodeFieldConfig = getNodeFieldConfig(TypeMapForRelayNode, nodeInterface);
102
- if (tc.getTypeName() === "Query" || tc.getTypeName() === "RootQuery") {
103
- tc.setField("node", nodeFieldConfig);
104
- return tc;
105
- }
106
- if (tc.getTypeName() === "Mutation" || tc.getTypeName() === "RootMutation") {
107
- return tc;
108
- }
109
- if (!tc.hasRecordIdFn()) {
110
- throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) should have recordIdFn. This function returns ID from provided object.`);
111
- }
112
- const findById = tc.getResolver("findById");
113
- if (!findById) {
114
- throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) provided to composeWithRelay should have findById resolver.`);
115
- }
116
- TypeMapForRelayNode[tc.getTypeName()] = {
117
- resolver: findById,
118
- tc
119
- };
120
- tc.addFields({
121
- id: {
122
- type: "ID!",
123
- description: "The globally unique ID among all types",
124
- resolve: source => {
125
- return toGlobalId(tc.getTypeName(), tc.getRecordId(source).toString());
126
- }
127
- }
128
- });
129
- tc.addInterface(nodeInterface);
130
- return tc;
131
- };
132
-
133
- // src/composeWithRelay/index.ts
134
- import { schemaComposer } from "graphql-compose";
135
- composeWithRelay(schemaComposer.Query);
136
-
137
- // src/index.ts
138
- import { default as default2 } from "graphql-compose-connection";
139
- export * from "graphql-compose";
140
-
141
- // src/buildSchema.ts
142
- import { applyMiddleware } from "graphql-middleware";
143
- var buildSchema = ({
144
- schemaComposer: schemaComposer2,
145
- middlewares
146
- }) => {
147
- if (!schemaComposer2) {
148
- throw new Error("No schemaComposer provided");
149
- }
150
- const schema = schemaComposer2.buildSchema();
151
- if (middlewares) {
152
- return applyMiddleware(schema, ...middlewares.map(middleware => {
153
- if (middleware.generate) {
154
- return middleware.generate(schema);
155
- }
156
- return middleware;
157
- }));
158
- }
159
- return schema;
160
- };
161
- export { buildSchema, default2 as composeWithConnection, composeWithRelay };
@@ -1,4 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
-
3
- // src/shield.ts
4
- export * from "graphql-shield";
package/dist/index.d.mts DELETED
@@ -1,16 +0,0 @@
1
- import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
2
- export * from 'graphql-compose';
3
- export { default as composeWithConnection } from 'graphql-compose-connection';
4
- import { GraphQLSchema } from 'graphql';
5
- import { IMiddleware, IMiddlewareGenerator } from 'graphql-middleware';
6
- export { IMiddleware as Middleware } from 'graphql-middleware';
7
-
8
- declare const composeWithRelay: <TContext>(tc: ObjectTypeComposer<any, TContext>) => ObjectTypeComposer<any, TContext>;
9
-
10
- type BuildSchemaInput<TContext = unknown> = {
11
- schemaComposer: SchemaComposer<TContext>;
12
- middlewares?: (IMiddleware | IMiddlewareGenerator<unknown, TContext, unknown>)[];
13
- };
14
- declare const buildSchema: ({ schemaComposer, middlewares, }: BuildSchemaInput) => GraphQLSchema;
15
-
16
- export { type BuildSchemaInput, buildSchema, composeWithRelay };
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
2
- export * from 'graphql-compose';
3
- export { default as composeWithConnection } from 'graphql-compose-connection';
4
- import { GraphQLSchema } from 'graphql';
5
- import { IMiddleware, IMiddlewareGenerator } from 'graphql-middleware';
6
- export { IMiddleware as Middleware } from 'graphql-middleware';
7
-
8
- declare const composeWithRelay: <TContext>(tc: ObjectTypeComposer<any, TContext>) => ObjectTypeComposer<any, TContext>;
9
-
10
- type BuildSchemaInput<TContext = unknown> = {
11
- schemaComposer: SchemaComposer<TContext>;
12
- middlewares?: (IMiddleware | IMiddlewareGenerator<unknown, TContext, unknown>)[];
13
- };
14
- declare const buildSchema: ({ schemaComposer, middlewares, }: BuildSchemaInput) => GraphQLSchema;
15
-
16
- export { type BuildSchemaInput, buildSchema, composeWithRelay };
package/dist/index.js DELETED
@@ -1,211 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __export = (target, all) => {
11
- for (var name in all) __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
- get: () => from[key],
20
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
- });
22
- }
23
- return to;
24
- };
25
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
- value: mod,
33
- enumerable: true
34
- }) : target, mod));
35
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
36
- value: true
37
- }), mod);
38
-
39
- // src/index.ts
40
- var src_exports = {};
41
- __export(src_exports, {
42
- buildSchema: () => buildSchema,
43
- composeWithConnection: () => import_graphql_compose_connection.default,
44
- composeWithRelay: () => composeWithRelay
45
- });
46
- module.exports = __toCommonJS(src_exports);
47
-
48
- // src/composeWithRelay/composeWithRelay.ts
49
- var import_graphql_compose3 = require("graphql-compose");
50
-
51
- // src/composeWithRelay/nodeFieldConfig.ts
52
- var import_graphql_compose = require("graphql-compose");
53
- var import_ids = require("@ttoss/ids");
54
- var getNodeFieldConfig = (typeMapForRelayNode, nodeInterface) => {
55
- return {
56
- description: "Fetches an object that has globally unique ID among all types",
57
- type: nodeInterface,
58
- args: {
59
- id: {
60
- type: "ID!",
61
- description: "The globally unique ID among all types"
62
- }
63
- },
64
- // eslint-disable-next-line max-params
65
- resolve: (source, args, context, info) => {
66
- if (!args.id || !(typeof args.id === "string")) {
67
- return null;
68
- }
69
- const {
70
- type
71
- } = (0, import_ids.fromGlobalId)(args.id);
72
- if (!typeMapForRelayNode[type]) {
73
- return null;
74
- }
75
- const {
76
- tc,
77
- resolver: findById
78
- } = typeMapForRelayNode[type];
79
- if (findById && findById.resolve && tc) {
80
- const graphqlType = tc.getType();
81
- let projection;
82
- if (info) {
83
- projection = (0, import_graphql_compose.getProjectionFromAST)({
84
- ...info,
85
- returnType: graphqlType
86
- });
87
- } else {
88
- projection = {};
89
- }
90
- const idArgName = Object.keys(findById.args)[0];
91
- return findById.resolve({
92
- source,
93
- args: {
94
- [idArgName]: args.id
95
- },
96
- // eg. mongoose has _id fieldname, so should map
97
- context,
98
- info,
99
- projection
100
- }).then(res => {
101
- if (!res) {
102
- return res;
103
- }
104
- res.__nodeType = graphqlType;
105
- return res;
106
- });
107
- }
108
- return null;
109
- }
110
- };
111
- };
112
-
113
- // src/composeWithRelay/nodeInterface.ts
114
- var import_graphql_compose2 = require("graphql-compose");
115
- var NodeTC = import_graphql_compose2.InterfaceTypeComposer.createTemp({
116
- name: "Node",
117
- description: "An object, that can be fetched by the globally unique ID among all types.",
118
- fields: {
119
- id: {
120
- type: "ID!",
121
- description: "The globally unique ID among all types."
122
- }
123
- },
124
- resolveType: payload => {
125
- return payload.__nodeType.name ? payload.__nodeType.name : null;
126
- }
127
- });
128
- var NodeInterface = NodeTC.getType();
129
- var getNodeInterface = sc => {
130
- if (sc.hasInstance("Node", import_graphql_compose2.InterfaceTypeComposer)) {
131
- return sc.get("Node");
132
- }
133
- sc.set("Node", NodeTC);
134
- return NodeTC;
135
- };
136
-
137
- // src/composeWithRelay/composeWithRelay.ts
138
- var import_ids2 = require("@ttoss/ids");
139
- var TypeMapForRelayNode = {};
140
- var composeWithRelay = tc => {
141
- if (!(tc instanceof import_graphql_compose3.ObjectTypeComposer)) {
142
- throw new Error("You should provide ObjectTypeComposer instance to composeWithRelay method");
143
- }
144
- const nodeInterface = getNodeInterface(tc.schemaComposer);
145
- const nodeFieldConfig = getNodeFieldConfig(TypeMapForRelayNode, nodeInterface);
146
- if (tc.getTypeName() === "Query" || tc.getTypeName() === "RootQuery") {
147
- tc.setField("node", nodeFieldConfig);
148
- return tc;
149
- }
150
- if (tc.getTypeName() === "Mutation" || tc.getTypeName() === "RootMutation") {
151
- return tc;
152
- }
153
- if (!tc.hasRecordIdFn()) {
154
- throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) should have recordIdFn. This function returns ID from provided object.`);
155
- }
156
- const findById = tc.getResolver("findById");
157
- if (!findById) {
158
- throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) provided to composeWithRelay should have findById resolver.`);
159
- }
160
- TypeMapForRelayNode[tc.getTypeName()] = {
161
- resolver: findById,
162
- tc
163
- };
164
- tc.addFields({
165
- id: {
166
- type: "ID!",
167
- description: "The globally unique ID among all types",
168
- resolve: source => {
169
- return (0, import_ids2.toGlobalId)(tc.getTypeName(), tc.getRecordId(source).toString());
170
- }
171
- }
172
- });
173
- tc.addInterface(nodeInterface);
174
- return tc;
175
- };
176
-
177
- // src/composeWithRelay/index.ts
178
- var import_graphql_compose4 = require("graphql-compose");
179
- composeWithRelay(import_graphql_compose4.schemaComposer.Query);
180
-
181
- // src/index.ts
182
- var import_graphql_compose_connection = __toESM(require("graphql-compose-connection"));
183
- __reExport(src_exports, require("graphql-compose"), module.exports);
184
-
185
- // src/buildSchema.ts
186
- var import_graphql_middleware = require("graphql-middleware");
187
- var buildSchema = ({
188
- schemaComposer: schemaComposer2,
189
- middlewares
190
- }) => {
191
- if (!schemaComposer2) {
192
- throw new Error("No schemaComposer provided");
193
- }
194
- const schema = schemaComposer2.buildSchema();
195
- if (middlewares) {
196
- return (0, import_graphql_middleware.applyMiddleware)(schema, ...middlewares.map(middleware => {
197
- if (middleware.generate) {
198
- return middleware.generate(schema);
199
- }
200
- return middleware;
201
- }));
202
- }
203
- return schema;
204
- };
205
- // Annotate the CommonJS export names for ESM import in node:
206
- 0 && (module.exports = {
207
- buildSchema,
208
- composeWithConnection,
209
- composeWithRelay,
210
- ...require("graphql-compose")
211
- });
package/dist/shield.d.mts DELETED
@@ -1,2 +0,0 @@
1
- export * from 'graphql-shield';
2
- export { IMiddleware, IMiddlewareFieldMap, IMiddlewareFunction, IMiddlewareGenerator, IMiddlewareGeneratorConstructor, IMiddlewareTypeMap } from 'graphql-middleware';
package/dist/shield.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from 'graphql-shield';
2
- export { IMiddleware, IMiddlewareFieldMap, IMiddlewareFunction, IMiddlewareGenerator, IMiddlewareGeneratorConstructor, IMiddlewareTypeMap } from 'graphql-middleware';
package/dist/shield.js DELETED
@@ -1,29 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
- get: () => from[key],
12
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
- });
14
- }
15
- return to;
16
- };
17
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: true
20
- }), mod);
21
-
22
- // src/shield.ts
23
- var shield_exports = {};
24
- module.exports = __toCommonJS(shield_exports);
25
- __reExport(shield_exports, require("graphql-shield"), module.exports);
26
- // Annotate the CommonJS export names for ESM import in node:
27
- 0 && (module.exports = {
28
- ...require("graphql-shield")
29
- });