From 14c2c9bc68a58bc650411c4498570b068af057ea Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 18:39:29 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 205 ++++++- packages/server/codegen.yml | 11 +- packages/server/package.json | 1 + packages/server/schema.gql | 522 ------------------ .../server/src/schema/base/schema.graphql | 51 ++ .../server/src/schema/client/schema.graphql | 35 ++ .../server/src/schema/history/schema.graphql | 29 + .../server/src/schema/profile/schema.graphql | 31 ++ packages/server/src/schema/res/schema.graphql | 212 +++++++ .../server/src/schema/storage/schema.graphql | 31 ++ .../server/src/schema/token/schema.graphql | 42 ++ .../server/src/schema/topic/schema.graphql | 96 ++++ .../server/src/schema/user/schema.graphql | 36 ++ 13 files changed, 767 insertions(+), 535 deletions(-) delete mode 100644 packages/server/schema.gql create mode 100644 packages/server/src/schema/base/schema.graphql create mode 100644 packages/server/src/schema/client/schema.graphql create mode 100644 packages/server/src/schema/history/schema.graphql create mode 100644 packages/server/src/schema/profile/schema.graphql create mode 100644 packages/server/src/schema/res/schema.graphql create mode 100644 packages/server/src/schema/storage/schema.graphql create mode 100644 packages/server/src/schema/token/schema.graphql create mode 100644 packages/server/src/schema/topic/schema.graphql create mode 100644 packages/server/src/schema/user/schema.graphql diff --git a/package-lock.json b/package-lock.json index 96e6277..c4cea51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1732,6 +1732,34 @@ "kuler": "^2.0.0" } }, + "node_modules/@eddeee888/gcg-server-config": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eddeee888/gcg-server-config/-/gcg-server-config-0.1.0.tgz", + "integrity": "sha512-ZM4Cfem3FWelpz5sdCfJ+fZTCyY1WDdcT6K5GZ/UZpr7JjMApSMKnf+o9VMT2T+BB91Hffr0AH8W4oLEWUEWuw==", + "dev": true, + "dependencies": { + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/typescript-resolvers": "^4.0.0" + } + }, + "node_modules/@eddeee888/gcg-typescript-resolver-files": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@eddeee888/gcg-typescript-resolver-files/-/gcg-typescript-resolver-files-0.7.2.tgz", + "integrity": "sha512-9LBkn6pGtXSQmH9rLoF/CkUUlsNwX4A539pRolr/yS++arGN871IptmZ89ezM4iGbbW/OPwp+Zp7AmNTgBExmA==", + "dev": true, + "dependencies": { + "@eddeee888/gcg-server-config": "0.1.0", + "@graphql-codegen/add": "^5.0.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/typescript-resolvers": "^4.0.0", + "ts-morph": "^19.0.0", + "tslib": "^2.3.0" + }, + "peerDependencies": { + "graphql": "^15.0.0 || ^16.0.0" + } + }, "node_modules/@eslint/eslintrc": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.1.tgz", @@ -1783,6 +1811,19 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "node_modules/@graphql-codegen/add": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@graphql-codegen/add/-/add-5.0.0.tgz", + "integrity": "sha512-ynWDOsK2yxtFHwcJTB9shoSkUd7YXd6ZE57f0nk7W5cu/nAgxZZpEsnTPEpZB/Mjf14YRGe2uJHQ7AfElHjqUQ==", + "dev": true, + "dependencies": { + "@graphql-codegen/plugin-helpers": "^5.0.0", + "tslib": "~2.5.0" + }, + "peerDependencies": { + "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" + } + }, "node_modules/@graphql-codegen/cli": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@graphql-codegen/cli/-/cli-5.0.0.tgz", @@ -5360,6 +5401,48 @@ "node": ">= 10" } }, + "node_modules/@ts-morph/common": { + "version": "0.20.0", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.20.0.tgz", + "integrity": "sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==", + "dev": true, + "dependencies": { + "fast-glob": "^3.2.12", + "minimatch": "^7.4.3", + "mkdirp": "^2.1.6", + "path-browserify": "^1.0.1" + } + }, + "node_modules/@ts-morph/common/node_modules/minimatch": { + "version": "7.4.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.6.tgz", + "integrity": "sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@ts-morph/common/node_modules/mkdirp": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", + "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", + "dev": true, + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -7200,6 +7283,12 @@ "type-is": "^1.6.16" } }, + "node_modules/code-block-writer": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz", + "integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==", + "dev": true + }, "node_modules/collect-v8-coverage": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", @@ -8745,9 +8834,9 @@ "dev": true }, "node_modules/fast-glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", - "integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, "dependencies": { "@nodelib/fs.stat": "^2.0.2", @@ -14219,6 +14308,12 @@ "util": "^0.10.3" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true + }, "node_modules/path-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/path-case/-/path-case-3.0.4.tgz", @@ -16226,6 +16321,16 @@ "integrity": "sha512-DEQrfv6l7IvN2jlzc/VTdZJYsWUnQNCsueYjMkC/iXoEoi5fNan6MjeDqkvhfzbmHgdz9UxDUluX3V5HdjTydQ==", "dev": true }, + "node_modules/ts-morph": { + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-19.0.0.tgz", + "integrity": "sha512-D6qcpiJdn46tUqV45vr5UGM2dnIEuTGNxVhg0sk5NX11orcouwj6i1bMqZIz2mZTZB1Hcgy7C3oEVhAT+f6mbQ==", + "dev": true, + "dependencies": { + "@ts-morph/common": "~0.20.0", + "code-block-writer": "^12.0.0" + } + }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -17319,6 +17424,7 @@ "zod": "^3.18.0" }, "devDependencies": { + "@eddeee888/gcg-typescript-resolver-files": "^0.7.2", "@graphql-codegen/cli": "^5.0.0", "@graphql-codegen/core": "^4.0.0", "@graphql-codegen/typescript": "^4.0.1", @@ -17431,6 +17537,7 @@ "requires": { "@apollo/server": "^4.10.0", "@as-integrations/koa": "^1.1.1", + "@eddeee888/gcg-typescript-resolver-files": "^0.7.2", "@graphql-codegen/cli": "^5.0.0", "@graphql-codegen/core": "^4.0.0", "@graphql-codegen/typescript": "^4.0.1", @@ -18746,6 +18853,31 @@ "kuler": "^2.0.0" } }, + "@eddeee888/gcg-server-config": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eddeee888/gcg-server-config/-/gcg-server-config-0.1.0.tgz", + "integrity": "sha512-ZM4Cfem3FWelpz5sdCfJ+fZTCyY1WDdcT6K5GZ/UZpr7JjMApSMKnf+o9VMT2T+BB91Hffr0AH8W4oLEWUEWuw==", + "dev": true, + "requires": { + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/typescript-resolvers": "^4.0.0" + } + }, + "@eddeee888/gcg-typescript-resolver-files": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@eddeee888/gcg-typescript-resolver-files/-/gcg-typescript-resolver-files-0.7.2.tgz", + "integrity": "sha512-9LBkn6pGtXSQmH9rLoF/CkUUlsNwX4A539pRolr/yS++arGN871IptmZ89ezM4iGbbW/OPwp+Zp7AmNTgBExmA==", + "dev": true, + "requires": { + "@eddeee888/gcg-server-config": "0.1.0", + "@graphql-codegen/add": "^5.0.0", + "@graphql-codegen/plugin-helpers": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.0", + "@graphql-codegen/typescript-resolvers": "^4.0.0", + "ts-morph": "^19.0.0", + "tslib": "^2.3.0" + } + }, "@eslint/eslintrc": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.1.tgz", @@ -18790,6 +18922,16 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "@graphql-codegen/add": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@graphql-codegen/add/-/add-5.0.0.tgz", + "integrity": "sha512-ynWDOsK2yxtFHwcJTB9shoSkUd7YXd6ZE57f0nk7W5cu/nAgxZZpEsnTPEpZB/Mjf14YRGe2uJHQ7AfElHjqUQ==", + "dev": true, + "requires": { + "@graphql-codegen/plugin-helpers": "^5.0.0", + "tslib": "~2.5.0" + } + }, "@graphql-codegen/cli": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@graphql-codegen/cli/-/cli-5.0.0.tgz", @@ -21472,6 +21614,35 @@ "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", "dev": true }, + "@ts-morph/common": { + "version": "0.20.0", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.20.0.tgz", + "integrity": "sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==", + "dev": true, + "requires": { + "fast-glob": "^3.2.12", + "minimatch": "^7.4.3", + "mkdirp": "^2.1.6", + "path-browserify": "^1.0.1" + }, + "dependencies": { + "minimatch": { + "version": "7.4.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.6.tgz", + "integrity": "sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "mkdirp": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", + "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", + "dev": true + } + } + }, "@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -22937,6 +23108,12 @@ "type-is": "^1.6.16" } }, + "code-block-writer": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz", + "integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==", + "dev": true + }, "collect-v8-coverage": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", @@ -24176,9 +24353,9 @@ "dev": true }, "fast-glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", - "integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", @@ -28349,6 +28526,12 @@ "util": "^0.10.3" } }, + "path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true + }, "path-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/path-case/-/path-case-3.0.4.tgz", @@ -29866,6 +30049,16 @@ "integrity": "sha512-DEQrfv6l7IvN2jlzc/VTdZJYsWUnQNCsueYjMkC/iXoEoi5fNan6MjeDqkvhfzbmHgdz9UxDUluX3V5HdjTydQ==", "dev": true }, + "ts-morph": { + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-19.0.0.tgz", + "integrity": "sha512-D6qcpiJdn46tUqV45vr5UGM2dnIEuTGNxVhg0sk5NX11orcouwj6i1bMqZIz2mZTZB1Hcgy7C3oEVhAT+f6mbQ==", + "dev": true, + "requires": { + "@ts-morph/common": "~0.20.0", + "code-block-writer": "^12.0.0" + } + }, "ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", diff --git a/packages/server/codegen.yml b/packages/server/codegen.yml index 6d36d6c..2fd3a0d 100644 --- a/packages/server/codegen.yml +++ b/packages/server/codegen.yml @@ -1,14 +1,11 @@ overwrite: true -schema: "schema.gql" +schema: "**/schema.graphql" documents: null generates: - src/generated/graphql.ts: - plugins: - - "typescript" - - "typescript-resolvers" + src/schema: + preset: "@eddeee888/gcg-typescript-resolver-files" + watchPattern: "**/*.mappers.ts" config: - scalars: - DateTime: Date enumsAsTypes: true contextType: ../server#AppContext mappers: diff --git a/packages/server/package.json b/packages/server/package.json index 2143ea6..6d94f67 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -36,6 +36,7 @@ "zod": "^3.18.0" }, "devDependencies": { + "@eddeee888/gcg-typescript-resolver-files": "^0.7.2", "@graphql-codegen/cli": "^5.0.0", "@graphql-codegen/core": "^4.0.0", "@graphql-codegen/typescript": "^4.0.1", diff --git a/packages/server/schema.gql b/packages/server/schema.gql deleted file mode 100644 index f3bb247..0000000 --- a/packages/server/schema.gql +++ /dev/null @@ -1,522 +0,0 @@ -scalar DateTime - -# client app -type Client { - # client id - id: ID! - name: String! - # callback url - url: String! - # yours - self: Boolean - # create date - date: DateTime! - # update date - update: DateTime! -} - -# topic edit history -type History { - # history id - id: ID! - # target topic - topic: TopicNormal! - # topic title - title: String! - # topic tags - tags: [String!]! - # topic text - text: String! - # history create date - date: DateTime! - # hash(user,date,topic) - hash: String! - # yours - self: Boolean -} - -# user profile -type Profile { - # profile id - id: ID! - # yours - self: Boolean - # profile name - name: String! - # profile text - text: String! - # create date - date: DateTime! - # update - update: DateTime! - # screen name - sn: String! -} - -# res vote flag -enum VoteFlag { - # up voted - uv - # down voted - dv - # not voted - not -} - -# res delete flag -enum ResDeleteFlag { - # by user - self - # by manager - freeze -} - -interface Res { - # res id - id: ID! - # posted topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(user,topic,date) - hash: String! - # reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag -} - -# normal res -type ResNormal implements Res { - # res id - id: ID! - # posted topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(user,topic,date) - hash: String! - # reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag - - # res name - name: String - # res text - text: String! - # reply res - reply: Res - # res profile - profile: Profile - # is yours reply - isReply: Boolean -} - -# post history notice res -type ResHistory implements Res { - # res id - id: ID! - # post topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(date,user,topic) - hash: String! - # was reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag - - # target history - history: History! -} - -# first res in One/Fork Topic -type ResTopic implements Res { - # res id - id: ID! - # post topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(user,topic,date) - hash: String! - # reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag -} - -# new fork topic notice res -type ResFork implements Res { - # res id - id: ID! - # post topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(user,topic,date) - hash: String! - # reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag - - # target fork topic - fork: TopicFork! -} - -# deteled res -type ResDelete implements Res { - # res id - id: ID! - # post topic - topic: Topic! - # post date - date: DateTime! - # yours - self: Boolean - # up vote count - uv: Int! - # down vote count - dv: Int! - # hash(user,topic,date) - hash: String! - # reply count - replyCount: Int! - # you vote flag - voteFlag: VoteFlag - - # delete flag - flag: ResDeleteFlag! -} - -type TokenReq { - token: ID! - key: String! -} - -interface Token { - id: ID! - key: String! - date: DateTime! -} - -type TokenMaster implements Token { - id: ID! - key: String! - date: DateTime! -} - -type TokenGeneral implements Token { - id: ID! - key: String! - date: DateTime! - - client: Client! -} - -interface Topic { - id: ID! - title: String! - update: DateTime! - date: DateTime! - resCount: Int! - active: Boolean! - subscribe: Boolean -} - -interface TopicSearch { - id: ID! - title: String! - update: DateTime! - date: DateTime! - resCount: Int! - active: Boolean! - subscribe: Boolean - - tags: [String!]! - text: String! -} - -type TopicNormal implements Topic & TopicSearch { - id: ID! - title: String! - update: DateTime! - date: DateTime! - resCount: Int! - active: Boolean! - subscribe: Boolean - - tags: [String!]! - text: String! -} - -type TopicOne implements Topic & TopicSearch { - id: ID! - title: String! - update: DateTime! - date: DateTime! - resCount: Int! - active: Boolean! - subscribe: Boolean - - tags: [String!]! - text: String! -} - -type TopicFork implements Topic { - id: ID! - title: String! - update: DateTime! - date: DateTime! - resCount: Int! - active: Boolean! - subscribe: Boolean - - parent: TopicNormal! -} - -type Storage { - key: String! - value: String! -} - -input DateQuery { - date: DateTime! - type: DateType! -} - -enum DateType { - gt - gte - lt - lte -} - -type User { - id: ID! - sn: String! -} - -type Tags { - name: String! - count: Int! -} - -input ClientQuery { - id: [ID!] - self: Boolean -} - -input HistoryQuery { - id: [ID!] - topic: [ID!] - date: DateQuery -} - -input ProfileQuery { - id: [ID!] - self: Boolean -} - -input ResQuery { - id: [ID!] - topic: ID - notice: Boolean - hash: String - reply: ID - profile: ID - self: Boolean - text: String - date: DateQuery -} - -input AuthUser { - id: String - sn: String - pass: String! -} - -input StorageQuery { - key: [String!] - keyPrefix: String -} - -input TopicQuery { - id: [ID!] - title: String - tags: [String!] - activeOnly: Boolean - parent: ID -} - -type Query { - query: Query! - clients(query: ClientQuery!): [Client!]! - histories(query: HistoryQuery!, limit: Int! = 100): [History!]! - profiles(query: ProfileQuery!): [Profile!]! - reses(query: ResQuery!, limit: Int! = 100): [Res!]! - storages(query: StorageQuery!): [Storage!]! - token: Token! - tokens: [Token!]! - topics(query: TopicQuery!, skip: Int! = 0, limit: Int! = 100): [Topic!]! - topicTags(limit: Int! = 100): [Tags!]! - userID(sn: String!): ID! - userSN(id: ID!): String! - user: User! -} - -enum VoteType { - uv - dv - cv -} - -type UpdateUserResponse { - user: User! - token: TokenMaster! -} - -type CreateUserResponse { - user: User! - token: TokenMaster! -} - -type CreateTokenGeneralResponse { - token: TokenGeneral! - req: TokenReq! -} - -enum CharType { - lc - uc - d - ub - hy - hira - kana - han -} - -type ValidateData { - char: [CharType] - min: Int - max: Int -} - -type CreateClientResponseError { - name: ValidateData! - url: Boolean! -} - -union CreateClientResponse = Client | CreateClientResponseError - -input SetStoragesInput { - storages: [StorageInput!]! -} - -input StorageInput { - key: String! - value: String! -} - -type SetStoragesPayload { - storages: [Storage!]! -} - -type Mutation { - createClient(name: String!, url: String!): Client! - updateClient(id: ID!, name: String, url: String): Client! - createProfile(name: String!, text: String!, sn: String!): Profile! - updateProfile(id: ID!, name: String, text: String, sn: String): Profile! - createRes( - topic: String! - name: String - text: String! - reply: String - profile: String - age: Boolean! - ): ResNormal! - voteRes(res: ID!, type: VoteType!): Res! - delRes(res: ID!): ResDelete! - setStorages(input: SetStoragesInput!): SetStoragesPayload! - delStorage(key: String!): Boolean - delTokenClient(client: ID!): Boolean - createTokenGeneral(client: ID!): CreateTokenGeneralResponse! - createTokenReq: TokenReq! - createTokenMaster(auth: AuthUser!): TokenMaster! - authTokenReq(id: ID!, key: String!): TokenGeneral! - createTopicNormal( - title: String! - tags: [String!]! - text: String! - ): TopicNormal! - createTopicOne(title: String!, tags: [String!]!, text: String!): TopicOne! - createTopicFork(title: String!, parent: ID!): TopicFork! - updateTopic( - id: ID! - title: String - tags: [String!] - text: String - ): TopicNormal! - createUser( - sn: String! - pass: String! - recaptcha: String! - ): CreateUserResponse! - updateUser(sn: String, pass: String, auth: AuthUser!): UpdateUserResponse! - resisterPushSubscription( - endpoint: String! - p256dh: String! - auth: String! - ): Boolean # void - subscribeTopic(topic: ID!): Boolean # void - unsubscribeTopic(topic: ID!): Boolean # void -} - -type ResSubscript { - res: Res! - count: Int! -} - -type Subscription { - resAdded(topic: ID!): ResSubscript! -} - -schema { - query: Query - mutation: Mutation - subscription: Subscription -} diff --git a/packages/server/src/schema/base/schema.graphql b/packages/server/src/schema/base/schema.graphql new file mode 100644 index 0000000..f8834fa --- /dev/null +++ b/packages/server/src/schema/base/schema.graphql @@ -0,0 +1,51 @@ +scalar DateTime + +input DateQuery { + date: DateTime! + type: DateType! +} + +enum DateType { + gt + gte + lt + lte +} + +enum CharType { + lc + uc + d + ub + hy + hira + kana + han +} + +type ValidateData { + char: [CharType] + min: Int + max: Int +} + + +type Query { + query: Query! +} + +type Mutation { + # TODO: 移動 + resisterPushSubscription( + endpoint: String! + p256dh: String! + auth: String! + ): Boolean # void +} +type Subscription + +schema { + query: Query + mutation: Mutation + subscription: Subscription +} diff --git a/packages/server/src/schema/client/schema.graphql b/packages/server/src/schema/client/schema.graphql new file mode 100644 index 0000000..5a91725 --- /dev/null +++ b/packages/server/src/schema/client/schema.graphql @@ -0,0 +1,35 @@ +# client app +type Client { + # client id + id: ID! + name: String! + # callback url + url: String! + # yours + self: Boolean + # create date + date: DateTime! + # update date + update: DateTime! +} + +input ClientQuery { + id: [ID!] + self: Boolean +} + +type CreateClientResponseError { + name: ValidateData! + url: Boolean! +} + +union CreateClientResponse = Client | CreateClientResponseError + +extend type Mutation { + createClient(name: String!, url: String!): Client! + updateClient(id: ID!, name: String, url: String): Client! +} + +extend type Query { + clients(query: ClientQuery!): [Client!]! +} diff --git a/packages/server/src/schema/history/schema.graphql b/packages/server/src/schema/history/schema.graphql new file mode 100644 index 0000000..5d40681 --- /dev/null +++ b/packages/server/src/schema/history/schema.graphql @@ -0,0 +1,29 @@ +# topic edit history +type History { + # history id + id: ID! + # target topic + topic: TopicNormal! + # topic title + title: String! + # topic tags + tags: [String!]! + # topic text + text: String! + # history create date + date: DateTime! + # hash(user,date,topic) + hash: String! + # yours + self: Boolean +} + +input HistoryQuery { + id: [ID!] + topic: [ID!] + date: DateQuery +} + +extend type Query { + histories(query: HistoryQuery!, limit: Int! = 100): [History!]! +} diff --git a/packages/server/src/schema/profile/schema.graphql b/packages/server/src/schema/profile/schema.graphql new file mode 100644 index 0000000..747d0cf --- /dev/null +++ b/packages/server/src/schema/profile/schema.graphql @@ -0,0 +1,31 @@ +# user profile +type Profile { + # profile id + id: ID! + # yours + self: Boolean + # profile name + name: String! + # profile text + text: String! + # create date + date: DateTime! + # update + update: DateTime! + # screen name + sn: String! +} + +input ProfileQuery { + id: [ID!] + self: Boolean +} + +extend type Mutation { + createProfile(name: String!, text: String!, sn: String!): Profile! + updateProfile(id: ID!, name: String, text: String, sn: String): Profile! +} + +extend type Query { + profiles(query: ProfileQuery!): [Profile!]! +} diff --git a/packages/server/src/schema/res/schema.graphql b/packages/server/src/schema/res/schema.graphql new file mode 100644 index 0000000..5ab156e --- /dev/null +++ b/packages/server/src/schema/res/schema.graphql @@ -0,0 +1,212 @@ +# res vote flag +enum VoteFlag { + # up voted + uv + # down voted + dv + # not voted + not +} + +# res delete flag +enum ResDeleteFlag { + # by user + self + # by manager + freeze +} + +interface Res { + # res id + id: ID! + # posted topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(user,topic,date) + hash: String! + # reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag +} + +# normal res +type ResNormal implements Res { + # res id + id: ID! + # posted topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(user,topic,date) + hash: String! + # reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag + + # res name + name: String + # res text + text: String! + # reply res + reply: Res + # res profile + profile: Profile + # is yours reply + isReply: Boolean +} + +# post history notice res +type ResHistory implements Res { + # res id + id: ID! + # post topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(date,user,topic) + hash: String! + # was reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag + + # target history + history: History! +} + +# first res in One/Fork Topic +type ResTopic implements Res { + # res id + id: ID! + # post topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(user,topic,date) + hash: String! + # reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag +} + +# new fork topic notice res +type ResFork implements Res { + # res id + id: ID! + # post topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(user,topic,date) + hash: String! + # reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag + + # target fork topic + fork: TopicFork! +} +# deteled res +type ResDelete implements Res { + # res id + id: ID! + # post topic + topic: Topic! + # post date + date: DateTime! + # yours + self: Boolean + # up vote count + uv: Int! + # down vote count + dv: Int! + # hash(user,topic,date) + hash: String! + # reply count + replyCount: Int! + # you vote flag + voteFlag: VoteFlag + + # delete flag + flag: ResDeleteFlag! +} + +input ResQuery { + id: [ID!] + topic: ID + notice: Boolean + hash: String + reply: ID + profile: ID + self: Boolean + text: String + date: DateQuery +} + +enum VoteType { + uv + dv + cv +} + + +extend type Query { + reses(query: ResQuery!, limit: Int! = 100): [Res!]! +} + +extend type Mutation { + createRes( + topic: String! + name: String + text: String! + reply: String + profile: String + age: Boolean! + ): ResNormal! + voteRes(res: ID!, type: VoteType!): Res! + delRes(res: ID!): ResDelete! +} + +type ResSubscript { + res: Res! + count: Int! +} + +extend type Subscription { + resAdded(topic: ID!): ResSubscript! +} diff --git a/packages/server/src/schema/storage/schema.graphql b/packages/server/src/schema/storage/schema.graphql new file mode 100644 index 0000000..43e42cb --- /dev/null +++ b/packages/server/src/schema/storage/schema.graphql @@ -0,0 +1,31 @@ +type Storage { + key: String! + value: String! +} + +input StorageQuery { + key: [String!] + keyPrefix: String +} + +extend type Query { + storages(query: StorageQuery!): [Storage!]! +} + +input SetStoragesInput { + storages: [StorageInput!]! +} + +input StorageInput { + key: String! + value: String! +} + +type SetStoragesPayload { + storages: [Storage!]! +} + +extend type Mutation { + setStorages(input: SetStoragesInput!): SetStoragesPayload! + delStorage(key: String!): Boolean +} diff --git a/packages/server/src/schema/token/schema.graphql b/packages/server/src/schema/token/schema.graphql new file mode 100644 index 0000000..532eeb5 --- /dev/null +++ b/packages/server/src/schema/token/schema.graphql @@ -0,0 +1,42 @@ +type TokenReq { + token: ID! + key: String! +} + +interface Token { + id: ID! + key: String! + date: DateTime! +} + +type TokenMaster implements Token { + id: ID! + key: String! + date: DateTime! +} + +type TokenGeneral implements Token { + id: ID! + key: String! + date: DateTime! + + client: Client! +} + +extend type Query { + token: Token! + tokens: [Token!]! +} + +type CreateTokenGeneralResponse { + token: TokenGeneral! + req: TokenReq! +} + +extend type Mutation { + delTokenClient(client: ID!): Boolean + createTokenGeneral(client: ID!): CreateTokenGeneralResponse! + createTokenReq: TokenReq! + createTokenMaster(auth: AuthUser!): TokenMaster! + authTokenReq(id: ID!, key: String!): TokenGeneral! +} diff --git a/packages/server/src/schema/topic/schema.graphql b/packages/server/src/schema/topic/schema.graphql new file mode 100644 index 0000000..d17eb85 --- /dev/null +++ b/packages/server/src/schema/topic/schema.graphql @@ -0,0 +1,96 @@ +interface Topic { + id: ID! + title: String! + update: DateTime! + date: DateTime! + resCount: Int! + active: Boolean! + subscribe: Boolean +} + +interface TopicSearch { + id: ID! + title: String! + update: DateTime! + date: DateTime! + resCount: Int! + active: Boolean! + subscribe: Boolean + + tags: [String!]! + text: String! +} + +type TopicNormal implements Topic & TopicSearch { + id: ID! + title: String! + update: DateTime! + date: DateTime! + resCount: Int! + active: Boolean! + subscribe: Boolean + + tags: [String!]! + text: String! +} + +type TopicOne implements Topic & TopicSearch { + id: ID! + title: String! + update: DateTime! + date: DateTime! + resCount: Int! + active: Boolean! + subscribe: Boolean + + tags: [String!]! + text: String! +} + +type TopicFork implements Topic { + id: ID! + title: String! + update: DateTime! + date: DateTime! + resCount: Int! + active: Boolean! + subscribe: Boolean + + parent: TopicNormal! +} + +type Tags { + name: String! + count: Int! +} + +input TopicQuery { + id: [ID!] + title: String + tags: [String!] + activeOnly: Boolean + parent: ID +} + +extend type Mutation { + createTopicNormal( + title: String! + tags: [String!]! + text: String! + ): TopicNormal! + createTopicOne(title: String!, tags: [String!]!, text: String!): TopicOne! + createTopicFork(title: String!, parent: ID!): TopicFork! + updateTopic( + id: ID! + title: String + tags: [String!] + text: String + ): TopicNormal! + subscribeTopic(topic: ID!): Boolean # void + unsubscribeTopic(topic: ID!): Boolean # void +} + +extend type Query { + topics(query: TopicQuery!, skip: Int! = 0, limit: Int! = 100): [Topic!]! + topicTags(limit: Int! = 100): [Tags!]! +} diff --git a/packages/server/src/schema/user/schema.graphql b/packages/server/src/schema/user/schema.graphql new file mode 100644 index 0000000..1274898 --- /dev/null +++ b/packages/server/src/schema/user/schema.graphql @@ -0,0 +1,36 @@ +type User { + id: ID! + sn: String! +} + +input AuthUser { + id: String + sn: String + pass: String! +} + +extend type Query { + userID(sn: String!): ID! + userSN(id: ID!): String! + user: User! +} + + +type UpdateUserResponse { + user: User! + token: TokenMaster! +} + +type CreateUserResponse { + user: User! + token: TokenMaster! +} + +extend type Mutation { + createUser( + sn: String! + pass: String! + recaptcha: String! + ): CreateUserResponse! + updateUser(sn: String, pass: String, auth: AuthUser!): UpdateUserResponse! +} From 95778f96b10be27c7606c8d976c552703ce43ad8 Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 18:45:42 +0900 Subject: [PATCH 02/10] =?UTF-8?q?mapper=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/codegen.yml | 23 ------------------- .../src/schema/client/schema.mappers.ts | 1 + .../src/schema/history/schema.mappers.ts | 1 + .../server/src/schema/res/schema.mappers.ts | 9 ++++++++ .../src/schema/storage/schema.mappers.ts | 1 + .../server/src/schema/token/schema.mappers.ts | 7 ++++++ .../server/src/schema/topic/schema.mappers.ts | 8 +++++++ .../server/src/schema/user/schema.mappers.ts | 1 + 8 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 packages/server/src/schema/client/schema.mappers.ts create mode 100644 packages/server/src/schema/history/schema.mappers.ts create mode 100644 packages/server/src/schema/res/schema.mappers.ts create mode 100644 packages/server/src/schema/storage/schema.mappers.ts create mode 100644 packages/server/src/schema/token/schema.mappers.ts create mode 100644 packages/server/src/schema/topic/schema.mappers.ts create mode 100644 packages/server/src/schema/user/schema.mappers.ts diff --git a/packages/server/codegen.yml b/packages/server/codegen.yml index 2fd3a0d..ff1f59b 100644 --- a/packages/server/codegen.yml +++ b/packages/server/codegen.yml @@ -8,26 +8,3 @@ generates: config: enumsAsTypes: true contextType: ../server#AppContext - mappers: - Client: ../entities#IClientAPI - History: ../entities#IHistoryAPI - Res: ../entities#IResAPI - ResNormal: ../entities#IResNormalAPI - ResHistory: ../entities#IResHistoryAPI - ResTopic: ../entities#IResTopicAPI - ResFork: ../entities#IResForkAPI - ResDelete: ../entities#IResDeleteAPI - TokenReq: ../entities#ITokenReqAPI - Token: ../entities#ITokenAPI - TokenMaster: ../entities#ITokenMasterAPI - TokenGeneral: ../entities#ITokenGeneralAPI - Topic: ../entities#ITopicAPI - TopicSearch: ../entities#ITopicSearchAPI - TopicNormal: ../entities#ITopicNormalAPI - TopicOne: ../entities#ITopicOneAPI - TopicFork: ../entities#ITopicForkAPI - Storage: ../entities#IStorageAPI - User: ../entities#IUserAPI - Tags: ../entities#ITagsAPI - ResSubscript: ../entities#IResAddedAPI - CreateTokenGeneralResponse: ../entities#CreateTokenGeneralResponseAPI diff --git a/packages/server/src/schema/client/schema.mappers.ts b/packages/server/src/schema/client/schema.mappers.ts new file mode 100644 index 0000000..271a5f1 --- /dev/null +++ b/packages/server/src/schema/client/schema.mappers.ts @@ -0,0 +1 @@ +export { IClientAPI as ClientMapper } from "../../entities"; diff --git a/packages/server/src/schema/history/schema.mappers.ts b/packages/server/src/schema/history/schema.mappers.ts new file mode 100644 index 0000000..463c79e --- /dev/null +++ b/packages/server/src/schema/history/schema.mappers.ts @@ -0,0 +1 @@ +export { IHistoryAPI as HistoryMapper } from "../../entities"; diff --git a/packages/server/src/schema/res/schema.mappers.ts b/packages/server/src/schema/res/schema.mappers.ts new file mode 100644 index 0000000..79b04a0 --- /dev/null +++ b/packages/server/src/schema/res/schema.mappers.ts @@ -0,0 +1,9 @@ +export { + IResAPI as ResMapper, + IResNormalAPI as ResNormalMapper, + IResHistoryAPI as ResHistoryMapper, + IResTopicAPI as ResTopicMapper, + IResForkAPI as ResForkMapper, + IResDeleteAPI as ResDeleteMapper, + IResAddedAPI as ResSubscriptMapper, +} from "../../entities"; diff --git a/packages/server/src/schema/storage/schema.mappers.ts b/packages/server/src/schema/storage/schema.mappers.ts new file mode 100644 index 0000000..16f6b55 --- /dev/null +++ b/packages/server/src/schema/storage/schema.mappers.ts @@ -0,0 +1 @@ +export { IStorageAPI as StorageMapper } from "../../entities"; diff --git a/packages/server/src/schema/token/schema.mappers.ts b/packages/server/src/schema/token/schema.mappers.ts new file mode 100644 index 0000000..55c4133 --- /dev/null +++ b/packages/server/src/schema/token/schema.mappers.ts @@ -0,0 +1,7 @@ +export { + ITokenReqAPI as TokenReqMapper, + ITokenAPI as TokenMapper, + ITokenMasterAPI as TokenMasterMapper, + ITokenGeneralAPI as TokenGeneralMapper, + CreateTokenGeneralResponseAPI as CreateTokenGeneralResponseMapper, +} from "../../entities"; diff --git a/packages/server/src/schema/topic/schema.mappers.ts b/packages/server/src/schema/topic/schema.mappers.ts new file mode 100644 index 0000000..4e8ef5e --- /dev/null +++ b/packages/server/src/schema/topic/schema.mappers.ts @@ -0,0 +1,8 @@ +export { + ITopicAPI as TopicMapper, + ITopicSearchAPI as TopicSearchMapper, + ITopicNormalAPI as TopicNormalMapper, + ITopicOneAPI as TopicOneMapper, + ITopicForkAPI as TopicForkMapper, + ITagsAPI as TagsMapper, +} from "../../entities"; diff --git a/packages/server/src/schema/user/schema.mappers.ts b/packages/server/src/schema/user/schema.mappers.ts new file mode 100644 index 0000000..8d1211b --- /dev/null +++ b/packages/server/src/schema/user/schema.mappers.ts @@ -0,0 +1 @@ +export { IUserAPI as UserMapper } from "../../entities"; From b6d08aca49223750d611a8f84152bca7f01ccde3 Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 19:27:35 +0900 Subject: [PATCH 03/10] WIP --- .eslintignore | 2 +- .prettierignore | 2 +- codegen.ts | 14 ++++++++++++++ packages/server/.gitignore | 2 +- packages/server/codegen.yml | 10 ---------- packages/server/src/resolvers/token.ts | 7 ------- .../Mutation/resisterPushSubscription.ts | 2 ++ .../src/schema/base/resolvers/Query/query.ts | 2 ++ .../src/schema/base/resolvers/ValidateData.ts | 4 ++++ .../server/src/schema/client/resolvers/Client.ts | 4 ++++ .../client/resolvers/CreateClientResponseError.ts | 4 ++++ .../client/resolvers/Mutation/createClient.ts | 2 ++ .../client/resolvers/Mutation/updateClient.ts | 2 ++ .../src/schema/client/resolvers/Query/clients.ts | 2 ++ .../history/resolvers/History.ts} | 6 +++--- .../schema/history/resolvers/Query/histories.ts | 2 ++ .../profile/resolvers/Mutation/createProfile.ts | 2 ++ .../profile/resolvers/Mutation/updateProfile.ts | 2 ++ .../src/schema/profile/resolvers/Profile.ts | 4 ++++ .../schema/profile/resolvers/Query/profiles.ts | 2 ++ .../schema/res/resolvers/Mutation/createRes.ts | 2 ++ .../src/schema/res/resolvers/Mutation/delRes.ts | 2 ++ .../src/schema/res/resolvers/Mutation/voteRes.ts | 2 ++ .../src/schema/res/resolvers/Query/reses.ts | 2 ++ .../server/src/schema/res/resolvers/ResDelete.ts | 13 +++++++++++++ .../server/src/schema/res/resolvers/ResFork.ts | 14 ++++++++++++++ .../server/src/schema/res/resolvers/ResHistory.ts | 14 ++++++++++++++ .../server/src/schema/res/resolvers/ResNormal.ts | 15 +++++++++++++++ .../src/schema/res/resolvers/ResSubscript.ts | 8 ++++++++ .../server/src/schema/res/resolvers/ResTopic.ts | 5 +++++ .../schema/res/resolvers/Subscription/resAdded.ts | 4 ++++ .../storage/resolvers/Mutation/delStorage.ts | 2 ++ .../storage/resolvers/Mutation/setStorages.ts | 2 ++ .../schema/storage/resolvers/Query/storages.ts | 2 ++ .../storage/resolvers/SetStoragesPayload.ts | 4 ++++ .../src/schema/storage/resolvers/Storage.ts | 4 ++++ .../token/resolvers/CreateTokenGeneralResponse.ts | 3 +++ .../token/resolvers/Mutation/authTokenReq.ts | 2 ++ .../resolvers/Mutation/createTokenGeneral.ts | 2 ++ .../token/resolvers/Mutation/createTokenMaster.ts | 2 ++ .../token/resolvers/Mutation/createTokenReq.ts | 2 ++ .../token/resolvers/Mutation/delTokenClient.ts | 2 ++ .../src/schema/token/resolvers/Query/token.ts | 8 ++++++++ .../src/schema/token/resolvers/Query/tokens.ts | 2 ++ .../src/schema/token/resolvers/TokenGeneral.ts | 7 +++++++ .../src/schema/token/resolvers/TokenMaster.ts | 2 ++ .../server/src/schema/token/resolvers/TokenReq.ts | 2 ++ .../topic/resolvers/Mutation/createTopicFork.ts | 2 ++ .../topic/resolvers/Mutation/createTopicNormal.ts | 2 ++ .../topic/resolvers/Mutation/createTopicOne.ts | 2 ++ .../topic/resolvers/Mutation/subscribeTopic.ts | 2 ++ .../topic/resolvers/Mutation/unsubscribeTopic.ts | 2 ++ .../topic/resolvers/Mutation/updateTopic.ts | 2 ++ .../src/schema/topic/resolvers/Query/topicTags.ts | 2 ++ .../src/schema/topic/resolvers/Query/topics.ts | 2 ++ .../server/src/schema/topic/resolvers/Tags.ts | 4 ++++ .../src/schema/topic/resolvers/TopicFork.ts | 12 ++++++++++++ .../src/schema/topic/resolvers/TopicNormal.ts | 5 +++++ .../server/src/schema/topic/resolvers/TopicOne.ts | 5 +++++ .../schema/user/resolvers/CreateUserResponse.ts | 4 ++++ .../schema/user/resolvers/Mutation/createUser.ts | 2 ++ .../schema/user/resolvers/Mutation/updateUser.ts | 2 ++ .../src/schema/user/resolvers/Query/user.ts | 2 ++ .../src/schema/user/resolvers/Query/userID.ts | 2 ++ .../src/schema/user/resolvers/Query/userSN.ts | 2 ++ .../schema/user/resolvers/UpdateUserResponse.ts | 4 ++++ packages/server/src/schema/user/resolvers/User.ts | 4 ++++ 67 files changed, 247 insertions(+), 23 deletions(-) create mode 100644 codegen.ts delete mode 100644 packages/server/codegen.yml create mode 100644 packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts create mode 100644 packages/server/src/schema/base/resolvers/Query/query.ts create mode 100644 packages/server/src/schema/base/resolvers/ValidateData.ts create mode 100644 packages/server/src/schema/client/resolvers/Client.ts create mode 100644 packages/server/src/schema/client/resolvers/CreateClientResponseError.ts create mode 100644 packages/server/src/schema/client/resolvers/Mutation/createClient.ts create mode 100644 packages/server/src/schema/client/resolvers/Mutation/updateClient.ts create mode 100644 packages/server/src/schema/client/resolvers/Query/clients.ts rename packages/server/src/{resolvers/history.ts => schema/history/resolvers/History.ts} (58%) create mode 100644 packages/server/src/schema/history/resolvers/Query/histories.ts create mode 100644 packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts create mode 100644 packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts create mode 100644 packages/server/src/schema/profile/resolvers/Profile.ts create mode 100644 packages/server/src/schema/profile/resolvers/Query/profiles.ts create mode 100644 packages/server/src/schema/res/resolvers/Mutation/createRes.ts create mode 100644 packages/server/src/schema/res/resolvers/Mutation/delRes.ts create mode 100644 packages/server/src/schema/res/resolvers/Mutation/voteRes.ts create mode 100644 packages/server/src/schema/res/resolvers/Query/reses.ts create mode 100644 packages/server/src/schema/res/resolvers/ResDelete.ts create mode 100644 packages/server/src/schema/res/resolvers/ResFork.ts create mode 100644 packages/server/src/schema/res/resolvers/ResHistory.ts create mode 100644 packages/server/src/schema/res/resolvers/ResNormal.ts create mode 100644 packages/server/src/schema/res/resolvers/ResSubscript.ts create mode 100644 packages/server/src/schema/res/resolvers/ResTopic.ts create mode 100644 packages/server/src/schema/res/resolvers/Subscription/resAdded.ts create mode 100644 packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts create mode 100644 packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts create mode 100644 packages/server/src/schema/storage/resolvers/Query/storages.ts create mode 100644 packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts create mode 100644 packages/server/src/schema/storage/resolvers/Storage.ts create mode 100644 packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts create mode 100644 packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts create mode 100644 packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts create mode 100644 packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts create mode 100644 packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts create mode 100644 packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts create mode 100644 packages/server/src/schema/token/resolvers/Query/token.ts create mode 100644 packages/server/src/schema/token/resolvers/Query/tokens.ts create mode 100644 packages/server/src/schema/token/resolvers/TokenGeneral.ts create mode 100644 packages/server/src/schema/token/resolvers/TokenMaster.ts create mode 100644 packages/server/src/schema/token/resolvers/TokenReq.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts create mode 100644 packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts create mode 100644 packages/server/src/schema/topic/resolvers/Query/topicTags.ts create mode 100644 packages/server/src/schema/topic/resolvers/Query/topics.ts create mode 100644 packages/server/src/schema/topic/resolvers/Tags.ts create mode 100644 packages/server/src/schema/topic/resolvers/TopicFork.ts create mode 100644 packages/server/src/schema/topic/resolvers/TopicNormal.ts create mode 100644 packages/server/src/schema/topic/resolvers/TopicOne.ts create mode 100644 packages/server/src/schema/user/resolvers/CreateUserResponse.ts create mode 100644 packages/server/src/schema/user/resolvers/Mutation/createUser.ts create mode 100644 packages/server/src/schema/user/resolvers/Mutation/updateUser.ts create mode 100644 packages/server/src/schema/user/resolvers/Query/user.ts create mode 100644 packages/server/src/schema/user/resolvers/Query/userID.ts create mode 100644 packages/server/src/schema/user/resolvers/Query/userSN.ts create mode 100644 packages/server/src/schema/user/resolvers/UpdateUserResponse.ts create mode 100644 packages/server/src/schema/user/resolvers/User.ts diff --git a/.eslintignore b/.eslintignore index 04b03fe..ae6c8a1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,2 @@ -*/**/generated/* +*/**/*.generated.ts *.js diff --git a/.prettierignore b/.prettierignore index 84dd27b..6514240 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1 @@ -*/**/generated/* +*/**/*.generated.ts diff --git a/codegen.ts b/codegen.ts new file mode 100644 index 0000000..c3557f5 --- /dev/null +++ b/codegen.ts @@ -0,0 +1,14 @@ +import type { CodegenConfig } from "@graphql-codegen/cli"; +import { defineConfig } from "@eddeee888/gcg-typescript-resolver-files"; + +const config: CodegenConfig = { + schema: "src/schema/**/schema.graphql", + generates: { + "src/schema": defineConfig({ + typesPluginsConfig: { + contextType: "../server#AppContext", + }, + }), + }, +}; +export default config; diff --git a/packages/server/.gitignore b/packages/server/.gitignore index 8214188..bda403e 100644 --- a/packages/server/.gitignore +++ b/packages/server/.gitignore @@ -1,3 +1,3 @@ /dist /coverage -src/generated/* +*/**/*.generated.ts diff --git a/packages/server/codegen.yml b/packages/server/codegen.yml deleted file mode 100644 index ff1f59b..0000000 --- a/packages/server/codegen.yml +++ /dev/null @@ -1,10 +0,0 @@ -overwrite: true -schema: "**/schema.graphql" -documents: null -generates: - src/schema: - preset: "@eddeee888/gcg-typescript-resolver-files" - watchPattern: "**/*.mappers.ts" -config: - enumsAsTypes: true - contextType: ../server#AppContext diff --git a/packages/server/src/resolvers/token.ts b/packages/server/src/resolvers/token.ts index 092b9e2..7a8440b 100644 --- a/packages/server/src/resolvers/token.ts +++ b/packages/server/src/resolvers/token.ts @@ -10,10 +10,3 @@ export const token: G.TokenResolvers = { } }, }; - -export const tokenGeneral: G.TokenGeneralResolvers = { - client: async (token, _args, context, _info) => { - const client = await context.ports.clientLoader.load(token.clientID); - return client.toAPI(context.ports.authContainer.getTokenMasterOrNull()); - }, -}; diff --git a/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts b/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts new file mode 100644 index 0000000..9baf6d0 --- /dev/null +++ b/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const resisterPushSubscription: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.resisterPushSubscription resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/base/resolvers/Query/query.ts b/packages/server/src/schema/base/resolvers/Query/query.ts new file mode 100644 index 0000000..f4049e6 --- /dev/null +++ b/packages/server/src/schema/base/resolvers/Query/query.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const query: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.query resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/base/resolvers/ValidateData.ts b/packages/server/src/schema/base/resolvers/ValidateData.ts new file mode 100644 index 0000000..6a55a1d --- /dev/null +++ b/packages/server/src/schema/base/resolvers/ValidateData.ts @@ -0,0 +1,4 @@ +import type { ValidateDataResolvers } from './../../types.generated'; + export const ValidateData: ValidateDataResolvers = { + /* Implement ValidateData resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/client/resolvers/Client.ts b/packages/server/src/schema/client/resolvers/Client.ts new file mode 100644 index 0000000..1ef3ed4 --- /dev/null +++ b/packages/server/src/schema/client/resolvers/Client.ts @@ -0,0 +1,4 @@ +import type { ClientResolvers } from './../../types.generated'; + export const Client: ClientResolvers = { + /* Implement Client resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/client/resolvers/CreateClientResponseError.ts b/packages/server/src/schema/client/resolvers/CreateClientResponseError.ts new file mode 100644 index 0000000..c4db721 --- /dev/null +++ b/packages/server/src/schema/client/resolvers/CreateClientResponseError.ts @@ -0,0 +1,4 @@ +import type { CreateClientResponseErrorResolvers } from "./../../types.generated"; +export const CreateClientResponseError: CreateClientResponseErrorResolvers = { + /* Implement CreateClientResponseError resolver logic here */ +}; diff --git a/packages/server/src/schema/client/resolvers/Mutation/createClient.ts b/packages/server/src/schema/client/resolvers/Mutation/createClient.ts new file mode 100644 index 0000000..cc5487c --- /dev/null +++ b/packages/server/src/schema/client/resolvers/Mutation/createClient.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createClient resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts b/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts new file mode 100644 index 0000000..56f0f92 --- /dev/null +++ b/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const updateClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateClient resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/client/resolvers/Query/clients.ts b/packages/server/src/schema/client/resolvers/Query/clients.ts new file mode 100644 index 0000000..1131b00 --- /dev/null +++ b/packages/server/src/schema/client/resolvers/Query/clients.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const clients: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.clients resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/resolvers/history.ts b/packages/server/src/schema/history/resolvers/History.ts similarity index 58% rename from packages/server/src/resolvers/history.ts rename to packages/server/src/schema/history/resolvers/History.ts index 263d165..0d07089 100644 --- a/packages/server/src/resolvers/history.ts +++ b/packages/server/src/schema/history/resolvers/History.ts @@ -1,7 +1,7 @@ -import * as G from "../generated/graphql"; -import { getTopic } from "../usecases"; +import type { HistoryResolvers } from "./../../types.generated"; +import { getTopic } from "../../../usecases"; -export const history: G.HistoryResolvers = { +export const History: HistoryResolvers = { topic: async (history, _args, context, _info) => { const topic = await getTopic({ id: history.topicID }, context.ports); if (topic.type !== "normal") { diff --git a/packages/server/src/schema/history/resolvers/Query/histories.ts b/packages/server/src/schema/history/resolvers/Query/histories.ts new file mode 100644 index 0000000..85a0b2e --- /dev/null +++ b/packages/server/src/schema/history/resolvers/Query/histories.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const histories: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.histories resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts b/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts new file mode 100644 index 0000000..91ab778 --- /dev/null +++ b/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createProfile: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createProfile resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts b/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts new file mode 100644 index 0000000..a7e08a0 --- /dev/null +++ b/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const updateProfile: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateProfile resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/profile/resolvers/Profile.ts b/packages/server/src/schema/profile/resolvers/Profile.ts new file mode 100644 index 0000000..8d50af6 --- /dev/null +++ b/packages/server/src/schema/profile/resolvers/Profile.ts @@ -0,0 +1,4 @@ +import type { ProfileResolvers } from './../../types.generated'; + export const Profile: ProfileResolvers = { + /* Implement Profile resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/profile/resolvers/Query/profiles.ts b/packages/server/src/schema/profile/resolvers/Query/profiles.ts new file mode 100644 index 0000000..d4e66ca --- /dev/null +++ b/packages/server/src/schema/profile/resolvers/Query/profiles.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const profiles: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.profiles resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/Mutation/createRes.ts b/packages/server/src/schema/res/resolvers/Mutation/createRes.ts new file mode 100644 index 0000000..9c63601 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/Mutation/createRes.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createRes resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/Mutation/delRes.ts b/packages/server/src/schema/res/resolvers/Mutation/delRes.ts new file mode 100644 index 0000000..7b03182 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/Mutation/delRes.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const delRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delRes resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts b/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts new file mode 100644 index 0000000..8c208b0 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const voteRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.voteRes resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/Query/reses.ts b/packages/server/src/schema/res/resolvers/Query/reses.ts new file mode 100644 index 0000000..ed28cc8 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/Query/reses.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const reses: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.reses resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResDelete.ts b/packages/server/src/schema/res/resolvers/ResDelete.ts new file mode 100644 index 0000000..feac80b --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResDelete.ts @@ -0,0 +1,13 @@ +import type { ResDeleteResolvers } from './../../types.generated'; + export const ResDelete: ResDeleteResolvers = { + /* Implement ResDelete resolver logic here */ + date: () => { /* ResDelete.date resolver is required because ResDelete.date exists but ResDeleteMapper.date does not */ }, + dv: () => { /* ResDelete.dv resolver is required because ResDelete.dv exists but ResDeleteMapper.dv does not */ }, + hash: () => { /* ResDelete.hash resolver is required because ResDelete.hash exists but ResDeleteMapper.hash does not */ }, + id: () => { /* ResDelete.id resolver is required because ResDelete.id exists but ResDeleteMapper.id does not */ }, + replyCount: () => { /* ResDelete.replyCount resolver is required because ResDelete.replyCount exists but ResDeleteMapper.replyCount does not */ }, + self: () => { /* ResDelete.self resolver is required because ResDelete.self exists but ResDeleteMapper.self does not */ }, + topic: () => { /* ResDelete.topic resolver is required because ResDelete.topic exists but ResDeleteMapper.topic does not */ }, + uv: () => { /* ResDelete.uv resolver is required because ResDelete.uv exists but ResDeleteMapper.uv does not */ }, + voteFlag: () => { /* ResDelete.voteFlag resolver is required because ResDelete.voteFlag exists but ResDeleteMapper.voteFlag does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResFork.ts b/packages/server/src/schema/res/resolvers/ResFork.ts new file mode 100644 index 0000000..d2ec54c --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResFork.ts @@ -0,0 +1,14 @@ +import type { ResForkResolvers } from './../../types.generated'; + export const ResFork: ResForkResolvers = { + /* Implement ResFork resolver logic here */ + date: () => { /* ResFork.date resolver is required because ResFork.date exists but ResForkMapper.date does not */ }, + dv: () => { /* ResFork.dv resolver is required because ResFork.dv exists but ResForkMapper.dv does not */ }, + hash: () => { /* ResFork.hash resolver is required because ResFork.hash exists but ResForkMapper.hash does not */ }, + id: () => { /* ResFork.id resolver is required because ResFork.id exists but ResForkMapper.id does not */ }, + replyCount: () => { /* ResFork.replyCount resolver is required because ResFork.replyCount exists but ResForkMapper.replyCount does not */ }, + self: () => { /* ResFork.self resolver is required because ResFork.self exists but ResForkMapper.self does not */ }, + topic: () => { /* ResFork.topic resolver is required because ResFork.topic exists but ResForkMapper.topic does not */ }, + uv: () => { /* ResFork.uv resolver is required because ResFork.uv exists but ResForkMapper.uv does not */ }, + voteFlag: () => { /* ResFork.voteFlag resolver is required because ResFork.voteFlag exists but ResForkMapper.voteFlag does not */ }, + fork: () => { /* ResFork.fork resolver is required because ResFork.fork exists but ResForkMapper.fork does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResHistory.ts b/packages/server/src/schema/res/resolvers/ResHistory.ts new file mode 100644 index 0000000..ce82d48 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResHistory.ts @@ -0,0 +1,14 @@ +import type { ResHistoryResolvers } from './../../types.generated'; + export const ResHistory: ResHistoryResolvers = { + /* Implement ResHistory resolver logic here */ + date: () => { /* ResHistory.date resolver is required because ResHistory.date exists but ResHistoryMapper.date does not */ }, + dv: () => { /* ResHistory.dv resolver is required because ResHistory.dv exists but ResHistoryMapper.dv does not */ }, + hash: () => { /* ResHistory.hash resolver is required because ResHistory.hash exists but ResHistoryMapper.hash does not */ }, + id: () => { /* ResHistory.id resolver is required because ResHistory.id exists but ResHistoryMapper.id does not */ }, + replyCount: () => { /* ResHistory.replyCount resolver is required because ResHistory.replyCount exists but ResHistoryMapper.replyCount does not */ }, + self: () => { /* ResHistory.self resolver is required because ResHistory.self exists but ResHistoryMapper.self does not */ }, + topic: () => { /* ResHistory.topic resolver is required because ResHistory.topic exists but ResHistoryMapper.topic does not */ }, + uv: () => { /* ResHistory.uv resolver is required because ResHistory.uv exists but ResHistoryMapper.uv does not */ }, + voteFlag: () => { /* ResHistory.voteFlag resolver is required because ResHistory.voteFlag exists but ResHistoryMapper.voteFlag does not */ }, + history: () => { /* ResHistory.history resolver is required because ResHistory.history exists but ResHistoryMapper.history does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResNormal.ts b/packages/server/src/schema/res/resolvers/ResNormal.ts new file mode 100644 index 0000000..29fa310 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResNormal.ts @@ -0,0 +1,15 @@ +import type { ResNormalResolvers } from './../../types.generated'; + export const ResNormal: ResNormalResolvers = { + /* Implement ResNormal resolver logic here */ + date: () => { /* ResNormal.date resolver is required because ResNormal.date exists but ResNormalMapper.date does not */ }, + dv: () => { /* ResNormal.dv resolver is required because ResNormal.dv exists but ResNormalMapper.dv does not */ }, + hash: () => { /* ResNormal.hash resolver is required because ResNormal.hash exists but ResNormalMapper.hash does not */ }, + id: () => { /* ResNormal.id resolver is required because ResNormal.id exists but ResNormalMapper.id does not */ }, + replyCount: () => { /* ResNormal.replyCount resolver is required because ResNormal.replyCount exists but ResNormalMapper.replyCount does not */ }, + self: () => { /* ResNormal.self resolver is required because ResNormal.self exists but ResNormalMapper.self does not */ }, + topic: () => { /* ResNormal.topic resolver is required because ResNormal.topic exists but ResNormalMapper.topic does not */ }, + uv: () => { /* ResNormal.uv resolver is required because ResNormal.uv exists but ResNormalMapper.uv does not */ }, + voteFlag: () => { /* ResNormal.voteFlag resolver is required because ResNormal.voteFlag exists but ResNormalMapper.voteFlag does not */ }, + profile: () => { /* ResNormal.profile resolver is required because ResNormal.profile exists but ResNormalMapper.profile does not */ }, + reply: () => { /* ResNormal.reply resolver is required because ResNormal.reply exists but ResNormalMapper.reply does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResSubscript.ts b/packages/server/src/schema/res/resolvers/ResSubscript.ts new file mode 100644 index 0000000..585bf2c --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResSubscript.ts @@ -0,0 +1,8 @@ +import type { ResSubscriptResolvers } from './../../types.generated'; + export const ResSubscript: ResSubscriptResolvers = { + /* Implement ResSubscript resolver logic here */ + res: ({ res }) => { + /* ResSubscript.res resolver is required because ResSubscript.res and ResSubscriptMapper.res are not compatible */ + return res + } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/ResTopic.ts b/packages/server/src/schema/res/resolvers/ResTopic.ts new file mode 100644 index 0000000..22a19cd --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResTopic.ts @@ -0,0 +1,5 @@ +import type { ResTopicResolvers } from './../../types.generated'; + export const ResTopic: ResTopicResolvers = { + /* Implement ResTopic resolver logic here */ + topic: () => { /* ResTopic.topic resolver is required because ResTopic.topic exists but ResTopicMapper.topic does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts b/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts new file mode 100644 index 0000000..511b3ae --- /dev/null +++ b/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts @@ -0,0 +1,4 @@ +import type { SubscriptionResolvers } from './../../../types.generated'; + export const resAdded: NonNullable = { + subscribe: async (_parent, _arg, _ctx) => { /* Implement Subscription.resAdded resolver logic here */ }, + } \ No newline at end of file diff --git a/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts b/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts new file mode 100644 index 0000000..13a2e54 --- /dev/null +++ b/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const delStorage: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delStorage resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts b/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts new file mode 100644 index 0000000..0ad70cc --- /dev/null +++ b/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const setStorages: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.setStorages resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/storage/resolvers/Query/storages.ts b/packages/server/src/schema/storage/resolvers/Query/storages.ts new file mode 100644 index 0000000..e8293b0 --- /dev/null +++ b/packages/server/src/schema/storage/resolvers/Query/storages.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const storages: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.storages resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts b/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts new file mode 100644 index 0000000..b680e60 --- /dev/null +++ b/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts @@ -0,0 +1,4 @@ +import type { SetStoragesPayloadResolvers } from './../../types.generated'; + export const SetStoragesPayload: SetStoragesPayloadResolvers = { + /* Implement SetStoragesPayload resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/storage/resolvers/Storage.ts b/packages/server/src/schema/storage/resolvers/Storage.ts new file mode 100644 index 0000000..7951510 --- /dev/null +++ b/packages/server/src/schema/storage/resolvers/Storage.ts @@ -0,0 +1,4 @@ +import type { StorageResolvers } from './../../types.generated'; + export const Storage: StorageResolvers = { + /* Implement Storage resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts new file mode 100644 index 0000000..553bb07 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts @@ -0,0 +1,3 @@ +import type { CreateTokenGeneralResponseResolvers } from "./../../types.generated"; +export const CreateTokenGeneralResponse: CreateTokenGeneralResponseResolvers = + {}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts new file mode 100644 index 0000000..525806f --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const authTokenReq: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.authTokenReq resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts new file mode 100644 index 0000000..d93038b --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTokenGeneral: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenGeneral resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts new file mode 100644 index 0000000..28e31f8 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTokenMaster: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenMaster resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts new file mode 100644 index 0000000..61b5480 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTokenReq: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenReq resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts b/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts new file mode 100644 index 0000000..a74ee41 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const delTokenClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delTokenClient resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/Query/token.ts b/packages/server/src/schema/token/resolvers/Query/token.ts new file mode 100644 index 0000000..effbeb8 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Query/token.ts @@ -0,0 +1,8 @@ +import type { QueryResolvers } from "./../../../types.generated"; +export const token: NonNullable = async ( + _parent, + _arg, + _ctx +) => { + /* Implement Query.token resolver logic here */ +}; diff --git a/packages/server/src/schema/token/resolvers/Query/tokens.ts b/packages/server/src/schema/token/resolvers/Query/tokens.ts new file mode 100644 index 0000000..a908ef9 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/Query/tokens.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const tokens: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.tokens resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/token/resolvers/TokenGeneral.ts b/packages/server/src/schema/token/resolvers/TokenGeneral.ts new file mode 100644 index 0000000..1c27775 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/TokenGeneral.ts @@ -0,0 +1,7 @@ +import type { TokenGeneralResolvers } from "./../../types.generated"; +export const TokenGeneral: TokenGeneralResolvers = { + client: async (token, _args, context, _info) => { + const client = await context.ports.clientLoader.load(token.clientID); + return client.toAPI(context.ports.authContainer.getTokenMasterOrNull()); + }, +}; diff --git a/packages/server/src/schema/token/resolvers/TokenMaster.ts b/packages/server/src/schema/token/resolvers/TokenMaster.ts new file mode 100644 index 0000000..c4991d6 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/TokenMaster.ts @@ -0,0 +1,2 @@ +import type { TokenMasterResolvers } from "./../../types.generated"; +export const TokenMaster: TokenMasterResolvers = {}; diff --git a/packages/server/src/schema/token/resolvers/TokenReq.ts b/packages/server/src/schema/token/resolvers/TokenReq.ts new file mode 100644 index 0000000..3c12da7 --- /dev/null +++ b/packages/server/src/schema/token/resolvers/TokenReq.ts @@ -0,0 +1,2 @@ +import type { TokenReqResolvers } from "./../../types.generated"; +export const TokenReq: TokenReqResolvers = {}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts new file mode 100644 index 0000000..1127c6b --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTopicFork: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicFork resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts new file mode 100644 index 0000000..7c27ca6 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTopicNormal: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicNormal resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts new file mode 100644 index 0000000..99de195 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createTopicOne: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicOne resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts new file mode 100644 index 0000000..36fc35b --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const subscribeTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.subscribeTopic resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts new file mode 100644 index 0000000..e211563 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const unsubscribeTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.unsubscribeTopic resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts new file mode 100644 index 0000000..b08c2fc --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const updateTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateTopic resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Query/topicTags.ts b/packages/server/src/schema/topic/resolvers/Query/topicTags.ts new file mode 100644 index 0000000..932aee7 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Query/topicTags.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const topicTags: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.topicTags resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Query/topics.ts b/packages/server/src/schema/topic/resolvers/Query/topics.ts new file mode 100644 index 0000000..8a7725e --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Query/topics.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const topics: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.topics resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/Tags.ts b/packages/server/src/schema/topic/resolvers/Tags.ts new file mode 100644 index 0000000..eec1dd7 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/Tags.ts @@ -0,0 +1,4 @@ +import type { TagsResolvers } from './../../types.generated'; + export const Tags: TagsResolvers = { + /* Implement Tags resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/TopicFork.ts b/packages/server/src/schema/topic/resolvers/TopicFork.ts new file mode 100644 index 0000000..8563b47 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/TopicFork.ts @@ -0,0 +1,12 @@ +import type { TopicForkResolvers } from './../../types.generated'; + export const TopicFork: TopicForkResolvers = { + /* Implement TopicFork resolver logic here */ + active: () => { /* TopicFork.active resolver is required because TopicFork.active exists but TopicForkMapper.active does not */ }, + date: () => { /* TopicFork.date resolver is required because TopicFork.date exists but TopicForkMapper.date does not */ }, + id: () => { /* TopicFork.id resolver is required because TopicFork.id exists but TopicForkMapper.id does not */ }, + resCount: () => { /* TopicFork.resCount resolver is required because TopicFork.resCount exists but TopicForkMapper.resCount does not */ }, + subscribe: () => { /* TopicFork.subscribe resolver is required because TopicFork.subscribe exists but TopicForkMapper.subscribe does not */ }, + title: () => { /* TopicFork.title resolver is required because TopicFork.title exists but TopicForkMapper.title does not */ }, + update: () => { /* TopicFork.update resolver is required because TopicFork.update exists but TopicForkMapper.update does not */ }, + parent: () => { /* TopicFork.parent resolver is required because TopicFork.parent exists but TopicForkMapper.parent does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/TopicNormal.ts b/packages/server/src/schema/topic/resolvers/TopicNormal.ts new file mode 100644 index 0000000..1137325 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/TopicNormal.ts @@ -0,0 +1,5 @@ +import type { TopicNormalResolvers } from './../../types.generated'; + export const TopicNormal: TopicNormalResolvers = { + /* Implement TopicNormal resolver logic here */ + subscribe: () => { /* TopicNormal.subscribe resolver is required because TopicNormal.subscribe exists but TopicNormalMapper.subscribe does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/topic/resolvers/TopicOne.ts b/packages/server/src/schema/topic/resolvers/TopicOne.ts new file mode 100644 index 0000000..75c02d1 --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/TopicOne.ts @@ -0,0 +1,5 @@ +import type { TopicOneResolvers } from './../../types.generated'; + export const TopicOne: TopicOneResolvers = { + /* Implement TopicOne resolver logic here */ + subscribe: () => { /* TopicOne.subscribe resolver is required because TopicOne.subscribe exists but TopicOneMapper.subscribe does not */ } + }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/CreateUserResponse.ts b/packages/server/src/schema/user/resolvers/CreateUserResponse.ts new file mode 100644 index 0000000..669116e --- /dev/null +++ b/packages/server/src/schema/user/resolvers/CreateUserResponse.ts @@ -0,0 +1,4 @@ +import type { CreateUserResponseResolvers } from './../../types.generated'; + export const CreateUserResponse: CreateUserResponseResolvers = { + /* Implement CreateUserResponse resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/Mutation/createUser.ts b/packages/server/src/schema/user/resolvers/Mutation/createUser.ts new file mode 100644 index 0000000..671320f --- /dev/null +++ b/packages/server/src/schema/user/resolvers/Mutation/createUser.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const createUser: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createUser resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts b/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts new file mode 100644 index 0000000..d492797 --- /dev/null +++ b/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts @@ -0,0 +1,2 @@ +import type { MutationResolvers } from './../../../types.generated'; + export const updateUser: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateUser resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/Query/user.ts b/packages/server/src/schema/user/resolvers/Query/user.ts new file mode 100644 index 0000000..cdb1088 --- /dev/null +++ b/packages/server/src/schema/user/resolvers/Query/user.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const user: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.user resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/Query/userID.ts b/packages/server/src/schema/user/resolvers/Query/userID.ts new file mode 100644 index 0000000..efbbe93 --- /dev/null +++ b/packages/server/src/schema/user/resolvers/Query/userID.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const userID: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.userID resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/Query/userSN.ts b/packages/server/src/schema/user/resolvers/Query/userSN.ts new file mode 100644 index 0000000..47f8cc6 --- /dev/null +++ b/packages/server/src/schema/user/resolvers/Query/userSN.ts @@ -0,0 +1,2 @@ +import type { QueryResolvers } from './../../../types.generated'; + export const userSN: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.userSN resolver logic here */ }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts b/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts new file mode 100644 index 0000000..d0644e5 --- /dev/null +++ b/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts @@ -0,0 +1,4 @@ +import type { UpdateUserResponseResolvers } from './../../types.generated'; + export const UpdateUserResponse: UpdateUserResponseResolvers = { + /* Implement UpdateUserResponse resolver logic here */ + }; \ No newline at end of file diff --git a/packages/server/src/schema/user/resolvers/User.ts b/packages/server/src/schema/user/resolvers/User.ts new file mode 100644 index 0000000..56ad1ab --- /dev/null +++ b/packages/server/src/schema/user/resolvers/User.ts @@ -0,0 +1,4 @@ +import type { UserResolvers } from './../../types.generated'; + export const User: UserResolvers = { + /* Implement User resolver logic here */ + }; \ No newline at end of file From c0ae3d3cb2a327c5910b0a3ba01f214b45ebc3ad Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 20:03:12 +0900 Subject: [PATCH 04/10] =?UTF-8?q?Token=E3=82=92server-preset=E3=81=AB?= =?UTF-8?q?=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codegen.ts | 2 + packages/server/src/resolvers/mutation.ts | 69 ------------------- packages/server/src/resolvers/query.ts | 12 ---- packages/server/src/resolvers/res.ts | 17 ----- packages/server/src/resolvers/token.ts | 12 ---- .../src/schema/history/resolvers/History.ts | 2 +- packages/server/src/schema/resolveTypes.ts | 30 ++++++++ .../resolvers/CreateTokenGeneralResponse.ts | 3 +- .../token/resolvers/Mutation/authTokenReq.ts | 13 +++- .../resolvers/Mutation/createTokenGeneral.ts | 29 +++++++- .../resolvers/Mutation/createTokenMaster.ts | 23 ++++++- .../resolvers/Mutation/createTokenReq.ts | 22 +++++- .../resolvers/Mutation/delTokenClient.ts | 13 +++- .../src/schema/token/resolvers/Query/token.ts | 14 ++-- .../schema/token/resolvers/Query/tokens.ts | 14 +++- .../schema/token/resolvers/TokenGeneral.ts | 3 + .../src/schema/token/resolvers/TokenMaster.ts | 3 +- .../src/schema/token/resolvers/TokenReq.ts | 3 +- packages/server/src/server/server.ts | 15 ++-- 19 files changed, 160 insertions(+), 139 deletions(-) delete mode 100644 packages/server/src/resolvers/token.ts create mode 100644 packages/server/src/schema/resolveTypes.ts diff --git a/codegen.ts b/codegen.ts index c3557f5..c838aa2 100644 --- a/codegen.ts +++ b/codegen.ts @@ -7,6 +7,8 @@ const config: CodegenConfig = { "src/schema": defineConfig({ typesPluginsConfig: { contextType: "../server#AppContext", + optionalResolveType: false, + resolversNonOptionalTypename: false, }, }), }, diff --git a/packages/server/src/resolvers/mutation.ts b/packages/server/src/resolvers/mutation.ts index 0f0f7c1..cec826e 100644 --- a/packages/server/src/resolvers/mutation.ts +++ b/packages/server/src/resolvers/mutation.ts @@ -308,75 +308,6 @@ export const mutation: G.MutationResolvers = { await context.ports.storageRepo.del(storage); return null; }, - delTokenClient: async (_obj, args, context, _info) => { - const client = await context.ports.clientRepo.findOne(args.client); - await context.ports.tokenRepo.delClientToken( - context.ports.authContainer.getTokenMaster(), - client.id - ); - return null; - }, - createTokenGeneral: async (_obj, args, context, _info) => { - const client = await context.ports.clientRepo.findOne(args.client); - const token = TokenGeneral.create( - context.ports.objectIdGenerator, - context.ports.authContainer.getTokenMaster(), - client, - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - - const { req, token: newToken } = token.createReq( - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - - await context.ports.tokenRepo.insert(newToken); - - return { - token: token.toAPI(), - req, - }; - }, - createTokenMaster: async (_obj, args, context, _info) => { - const authUser = await authFromApiParam.authUserRequestToUser( - context.ports.userRepo, - args.auth - ); - const token = TokenMaster.create( - context.ports.objectIdGenerator, - authUser, - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - await context.ports.tokenRepo.insert(token); - - return token.toAPI(); - }, - authTokenReq: async (_obj, args, context, _info) => { - const token = await context.ports.tokenRepo.findOne(args.id); - if (token.type !== "general") { - throw new AtNotFoundError("トークンが見つかりません"); - } - token.authReq(args.key, context.ports.clock.now()); - return token.toAPI(); - }, - createTokenReq: async (_obj, _args, context, _info) => { - const token = await context.ports.tokenRepo.findOne( - context.ports.authContainer.getToken().id - ); - if (token.type !== "general") { - throw new AtNotFoundError("トークンが見つかりません"); - } - const { req, token: newToken } = token.createReq( - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - - await context.ports.tokenRepo.update(newToken); - - return req; - }, createTopicNormal: async (_obj, args, context, _info) => { const user = await context.ports.userRepo.findOne( context.ports.authContainer.getToken().user diff --git a/packages/server/src/resolvers/query.ts b/packages/server/src/resolvers/query.ts index 80dd812..1f0ed3f 100644 --- a/packages/server/src/resolvers/query.ts +++ b/packages/server/src/resolvers/query.ts @@ -95,18 +95,6 @@ export const query: G.QueryResolvers = { ); return storages.map((x) => x.toAPI(context.ports.authContainer.getToken())); }, - token: async (_obj, _args, context, _info) => { - const token = await context.ports.tokenRepo.findOne( - context.ports.authContainer.getToken().id - ); - return token.toAPI(); - }, - tokens: async (_obj, _args, context, _info: any) => { - const tokens = await context.ports.tokenRepo.findAll( - context.ports.authContainer.getTokenMaster() - ); - return tokens.map((t) => t.toAPI()); - }, topics: async (_obj, args, context, _info) => { const topic = await context.ports.topicRepo.find( { diff --git a/packages/server/src/resolvers/res.ts b/packages/server/src/resolvers/res.ts index a4346be..19ac541 100644 --- a/packages/server/src/resolvers/res.ts +++ b/packages/server/src/resolvers/res.ts @@ -8,23 +8,6 @@ const resBase: Pick = { }, }; -export const res: G.ResResolvers = { - __resolveType(obj) { - switch (obj.type) { - case "normal": - return "ResNormal"; - case "history": - return "ResHistory"; - case "topic": - return "ResTopic"; - case "fork": - return "ResFork"; - case "delete": - return "ResDelete"; - } - }, -}; - export const resNormal: G.ResNormalResolvers = { ...resBase, reply: async (res, _args, context, _info) => { diff --git a/packages/server/src/resolvers/token.ts b/packages/server/src/resolvers/token.ts deleted file mode 100644 index 7a8440b..0000000 --- a/packages/server/src/resolvers/token.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as G from "../generated/graphql"; - -export const token: G.TokenResolvers = { - __resolveType(obj) { - switch (obj.type) { - case "general": - return "TokenGeneral"; - case "master": - return "TokenMaster"; - } - }, -}; diff --git a/packages/server/src/schema/history/resolvers/History.ts b/packages/server/src/schema/history/resolvers/History.ts index 0d07089..bd43a2c 100644 --- a/packages/server/src/schema/history/resolvers/History.ts +++ b/packages/server/src/schema/history/resolvers/History.ts @@ -8,5 +8,5 @@ export const History: HistoryResolvers = { throw new Error(); } return topic; - }, + } }; diff --git a/packages/server/src/schema/resolveTypes.ts b/packages/server/src/schema/resolveTypes.ts new file mode 100644 index 0000000..ca68854 --- /dev/null +++ b/packages/server/src/schema/resolveTypes.ts @@ -0,0 +1,30 @@ +import type { Resolvers } from "./types.generated"; + +export const resolveTypes: Resolvers = { + Token: { + __resolveType(obj) { + switch (obj.type) { + case "general": + return "TokenGeneral"; + case "master": + return "TokenMaster"; + } + }, + }, + Res: { + __resolveType(obj) { + switch (obj.type) { + case "normal": + return "ResNormal"; + case "history": + return "ResHistory"; + case "topic": + return "ResTopic"; + case "fork": + return "ResFork"; + case "delete": + return "ResDelete"; + } + }, + }, +}; diff --git a/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts index 553bb07..fcab606 100644 --- a/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts +++ b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts @@ -1,3 +1,4 @@ import type { CreateTokenGeneralResponseResolvers } from "./../../types.generated"; export const CreateTokenGeneralResponse: CreateTokenGeneralResponseResolvers = - {}; + { +}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts index 525806f..d1b8c0b 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts @@ -1,2 +1,11 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const authTokenReq: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.authTokenReq resolver logic here */ }; \ No newline at end of file +import { AtNotFoundError } from "../../../../at-error"; +import type { MutationResolvers } from "./../../../types.generated"; + +export const authTokenReq: NonNullable = async (_obj, args, context, _info) => { + const token = await context.ports.tokenRepo.findOne(args.id); + if (token.type !== "general") { + throw new AtNotFoundError("トークンが見つかりません"); + } + token.authReq(args.key, context.ports.clock.now()); + return token.toAPI(); +}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts index d93038b..2bc736b 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenGeneral.ts @@ -1,2 +1,27 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTokenGeneral: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenGeneral resolver logic here */ }; \ No newline at end of file +import { TokenGeneral } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; + +export const createTokenGeneral: NonNullable< + MutationResolvers["createTokenGeneral"] +> = async (_obj, args, context, _info) => { + const client = await context.ports.clientRepo.findOne(args.client); + const token = TokenGeneral.create( + context.ports.objectIdGenerator, + context.ports.authContainer.getTokenMaster(), + client, + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + + const { req, token: newToken } = token.createReq( + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + + await context.ports.tokenRepo.insert(newToken); + + return { + token: token.toAPI(), + req, + }; +}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts index 28e31f8..6aac1ae 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenMaster.ts @@ -1,2 +1,21 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTokenMaster: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenMaster resolver logic here */ }; \ No newline at end of file +import { TokenMaster } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as authFromApiParam from "../../../../server/auth-from-api-param"; + +export const createTokenMaster: NonNullable< + MutationResolvers["createTokenMaster"] +> = async (_obj, args, context, _info) => { + const authUser = await authFromApiParam.authUserRequestToUser( + context.ports.userRepo, + args.auth + ); + const token = TokenMaster.create( + context.ports.objectIdGenerator, + authUser, + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + await context.ports.tokenRepo.insert(token); + + return token.toAPI(); +}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts b/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts index 61b5480..895ae77 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/createTokenReq.ts @@ -1,2 +1,20 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTokenReq: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTokenReq resolver logic here */ }; \ No newline at end of file +import { AtNotFoundError } from "../../../../at-error"; +import type { MutationResolvers } from "./../../../types.generated"; +export const createTokenReq: NonNullable< + MutationResolvers["createTokenReq"] +> = async (_obj, _args, context, _info) => { + const token = await context.ports.tokenRepo.findOne( + context.ports.authContainer.getToken().id + ); + if (token.type !== "general") { + throw new AtNotFoundError("トークンが見つかりません"); + } + const { req, token: newToken } = token.createReq( + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + + await context.ports.tokenRepo.update(newToken); + + return req; +}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts b/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts index a74ee41..d22479d 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/delTokenClient.ts @@ -1,2 +1,11 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const delTokenClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delTokenClient resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +export const delTokenClient: NonNullable< + MutationResolvers["delTokenClient"] +> = async (_obj, args, context, _info) => { + const client = await context.ports.clientRepo.findOne(args.client); + await context.ports.tokenRepo.delClientToken( + context.ports.authContainer.getTokenMaster(), + client.id + ); + return null; +}; diff --git a/packages/server/src/schema/token/resolvers/Query/token.ts b/packages/server/src/schema/token/resolvers/Query/token.ts index effbeb8..c30ce90 100644 --- a/packages/server/src/schema/token/resolvers/Query/token.ts +++ b/packages/server/src/schema/token/resolvers/Query/token.ts @@ -1,8 +1,12 @@ import type { QueryResolvers } from "./../../../types.generated"; -export const token: NonNullable = async ( - _parent, - _arg, - _ctx +export const token: NonNullable = async ( + _obj, + _args, + context, + _info ) => { - /* Implement Query.token resolver logic here */ + const token = await context.ports.tokenRepo.findOne( + context.ports.authContainer.getToken().id + ); + return token.toAPI(); }; diff --git a/packages/server/src/schema/token/resolvers/Query/tokens.ts b/packages/server/src/schema/token/resolvers/Query/tokens.ts index a908ef9..a9571cf 100644 --- a/packages/server/src/schema/token/resolvers/Query/tokens.ts +++ b/packages/server/src/schema/token/resolvers/Query/tokens.ts @@ -1,2 +1,12 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const tokens: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.tokens resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; +export const tokens: NonNullable = async ( + _obj, + _args, + context, + _info +) => { + const tokens = await context.ports.tokenRepo.findAll( + context.ports.authContainer.getTokenMaster() + ); + return tokens.map((t) => t.toAPI()); +}; diff --git a/packages/server/src/schema/token/resolvers/TokenGeneral.ts b/packages/server/src/schema/token/resolvers/TokenGeneral.ts index 1c27775..5b49861 100644 --- a/packages/server/src/schema/token/resolvers/TokenGeneral.ts +++ b/packages/server/src/schema/token/resolvers/TokenGeneral.ts @@ -4,4 +4,7 @@ export const TokenGeneral: TokenGeneralResolvers = { const client = await context.ports.clientLoader.load(token.clientID); return client.toAPI(context.ports.authContainer.getTokenMasterOrNull()); }, + date: () => { /* TokenGeneral.date resolver is required because TokenGeneral.date exists but TokenGeneralMapper.date does not */ }, + id: () => { /* TokenGeneral.id resolver is required because TokenGeneral.id exists but TokenGeneralMapper.id does not */ }, + key: () => { /* TokenGeneral.key resolver is required because TokenGeneral.key exists but TokenGeneralMapper.key does not */ } }; diff --git a/packages/server/src/schema/token/resolvers/TokenMaster.ts b/packages/server/src/schema/token/resolvers/TokenMaster.ts index c4991d6..bd32e8f 100644 --- a/packages/server/src/schema/token/resolvers/TokenMaster.ts +++ b/packages/server/src/schema/token/resolvers/TokenMaster.ts @@ -1,2 +1,3 @@ import type { TokenMasterResolvers } from "./../../types.generated"; -export const TokenMaster: TokenMasterResolvers = {}; +export const TokenMaster: TokenMasterResolvers = { +}; diff --git a/packages/server/src/schema/token/resolvers/TokenReq.ts b/packages/server/src/schema/token/resolvers/TokenReq.ts index 3c12da7..2370c55 100644 --- a/packages/server/src/schema/token/resolvers/TokenReq.ts +++ b/packages/server/src/schema/token/resolvers/TokenReq.ts @@ -1,2 +1,3 @@ import type { TokenReqResolvers } from "./../../types.generated"; -export const TokenReq: TokenReqResolvers = {}; +export const TokenReq: TokenReqResolvers = { +}; diff --git a/packages/server/src/server/server.ts b/packages/server/src/server/server.ts index ed76402..af97b09 100644 --- a/packages/server/src/server/server.ts +++ b/packages/server/src/server/server.ts @@ -1,10 +1,11 @@ import cors from "@koa/cors"; import Koa from "koa"; -import * as fs from "fs/promises"; import { createServer } from "http"; import { AtError } from "../at-error"; import { Config } from "../config"; -import { resolvers as appResolvers } from "../resolvers"; +import { resolvers } from "../schema/resolvers.generated"; +import { resolveTypes } from "../schema/resolveTypes"; +import { typeDefs } from "../schema/typeDefs.generated"; import { runWorker } from "../worker"; import { AppContext, createContext } from "./context"; import Router from "@koa/router"; @@ -22,18 +23,16 @@ import bodyParser from "koa-bodyparser"; import { GraphQLError } from "graphql"; export async function serverRun() { - const typeDefs = await fs.readFile( - require.resolve("../../schema.gql"), - "utf8" - ); - const app = new Koa(); app.use(cors()); app.use(bodyParser()); const router = new Router(); const httpServer = createServer(app.callback()); - const schema = makeExecutableSchema({ typeDefs, resolvers: appResolvers }); + const schema = makeExecutableSchema({ + typeDefs, + resolvers: [resolvers, resolveTypes], + }); const wsServer = new WebSocketServer({ server: httpServer, path: "/", From 2989cc7a0ceeaed5a09753a52e27d0c6b4fb8fcc Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 20:17:51 +0900 Subject: [PATCH 05/10] =?UTF-8?q?mutation=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/resolvers/mutation.ts | 483 ------------------ .../Mutation/resisterPushSubscription.ts | 19 +- .../client/resolvers/Mutation/createClient.ts | 23 +- .../client/resolvers/Mutation/updateClient.ts | 23 +- .../resolvers/Mutation/createProfile.ts | 24 +- .../resolvers/Mutation/updateProfile.ts | 24 +- .../res/resolvers/Mutation/createRes.ts | 95 +++- .../schema/res/resolvers/Mutation/delRes.ts | 36 +- .../schema/res/resolvers/Mutation/voteRes.ts | 61 ++- .../storage/resolvers/Mutation/delStorage.ts | 16 +- .../storage/resolvers/Mutation/setStorages.ts | 22 +- .../resolvers/Mutation/createTopicFork.ts | 48 +- .../resolvers/Mutation/createTopicNormal.ts | 43 +- .../resolvers/Mutation/createTopicOne.ts | 37 +- .../resolvers/Mutation/subscribeTopic.ts | 12 +- .../resolvers/Mutation/unsubscribeTopic.ts | 13 +- .../topic/resolvers/Mutation/updateTopic.ts | 45 +- .../user/resolvers/Mutation/createUser.ts | 30 +- .../user/resolvers/Mutation/updateUser.ts | 35 +- 19 files changed, 570 insertions(+), 519 deletions(-) delete mode 100644 packages/server/src/resolvers/mutation.ts diff --git a/packages/server/src/resolvers/mutation.ts b/packages/server/src/resolvers/mutation.ts deleted file mode 100644 index cec826e..0000000 --- a/packages/server/src/resolvers/mutation.ts +++ /dev/null @@ -1,483 +0,0 @@ -import { isNullish, nullToUndefined } from "@kgtkr/utils"; -import { fromNullable, some } from "fp-ts/lib/Option"; -import { AtNotFoundError } from "../at-error"; -import { - Client, - IStorageAPI, - Profile, - ResNormal, - Storage, - TokenGeneral, - TokenMaster, - TopicFork, - TopicNormal, - TopicOne, - User, -} from "../entities"; -import * as formatter from "../formatter"; -import * as G from "../generated/graphql"; -import * as authFromApiParam from "../server/auth-from-api-param"; -import * as O from "fp-ts/Option"; - -export const mutation: G.MutationResolvers = { - createUser: async (_obj, args, context, _info) => { - await context.ports.recaptcha.verify(args.recaptcha); - - const user = User.create( - context.ports.objectIdGenerator, - args.sn, - args.pass, - context.ports.clock.now() - ); - await context.ports.userRepo.insert(user); - - const token = TokenMaster.create( - context.ports.objectIdGenerator, - user.auth(args.pass), - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - await context.ports.tokenRepo.insert(token); - - return { user: user.toAPI(), token: token.toAPI() }; - }, - updateUser: async (_obj, args, context, _info) => { - const authUser = await authFromApiParam.authUserRequestToUser( - context.ports.userRepo, - args.auth - ); - const user = await context.ports.userRepo.findOne(authUser.id); - const newUser = user.change( - authUser, - nullToUndefined(args.pass), - nullToUndefined(args.sn) - ); - await context.ports.userRepo.update(newUser); - await context.ports.tokenRepo.delMasterToken(authUser); - - const token = TokenMaster.create( - context.ports.objectIdGenerator, - authUser, - context.ports.clock.now(), - context.ports.safeIdGenerator - ); - await context.ports.tokenRepo.insert(token); - return { user: newUser.toAPI(), token: token.toAPI() }; - }, - createClient: async (_obj, args, context, _info) => { - const client = Client.create( - context.ports.objectIdGenerator, - context.ports.authContainer.getTokenMaster(), - args.name, - args.url, - context.ports.clock.now() - ); - await context.ports.clientRepo.insert(client); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "clients", client.id) - ); - return client.toAPI(some(context.ports.authContainer.getTokenMaster())); - }, - updateClient: async (_obj, args, context, _info) => { - const client = await context.ports.clientRepo.findOne(args.id); - const newClient = client.changeData( - context.ports.authContainer.getTokenMaster(), - nullToUndefined(args.name), - nullToUndefined(args.url), - context.ports.clock.now() - ); - await context.ports.clientRepo.update(newClient); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "clients", client.id) - ); - return newClient.toAPI(some(context.ports.authContainer.getTokenMaster())); - }, - createProfile: async (_obj, args, context, _info) => { - const profile = Profile.create( - context.ports.objectIdGenerator, - context.ports.authContainer.getToken(), - args.name, - args.text, - args.sn, - context.ports.clock.now() - ); - await context.ports.profileRepo.insert(profile); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "profiles", profile.id) - ); - return profile.toAPI(some(context.ports.authContainer.getToken())); - }, - updateProfile: async (_obj, args, context, _info: any) => { - const profile = await context.ports.profileRepo.findOne(args.id); - const newProfile = profile.changeData( - context.ports.authContainer.getToken(), - nullToUndefined(args.name), - nullToUndefined(args.text), - nullToUndefined(args.sn), - context.ports.clock.now() - ); - await context.ports.profileRepo.update(newProfile); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "profiles", newProfile.id) - ); - return newProfile.toAPI(some(context.ports.authContainer.getToken())); - }, - createRes: async (_obj, args, context, _info) => { - const [topic, user, reply, profile] = await Promise.all([ - context.ports.topicRepo.findOne(args.topic), - context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ), - !isNullish(args.reply) - ? context.ports.resRepo.findOne(args.reply) - : Promise.resolve(null), - !isNullish(args.profile) - ? context.ports.profileRepo.findOne(args.profile) - : Promise.resolve(null), - ] as const); - - const { - res, - user: newUser, - topic: newTopic, - } = ResNormal.create( - context.ports.objectIdGenerator, - topic, - user, - context.ports.authContainer.getToken(), - fromNullable(args.name), - args.text, - fromNullable(reply), - fromNullable(profile), - args.age, - context.ports.clock.now() - ); - - await Promise.all([ - context.ports.resRepo.insert(res), - context.ports.topicRepo.update(newTopic), - context.ports.userRepo.update(newUser), - ]); - - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "reses", res.id) - ); - const api = res.toAPI(some(context.ports.authContainer.getToken())); - if (api.type !== "normal") { - throw new Error(); - } - - if (O.isSome(res.reply) && res.user !== res.reply.value.user) { - await context.ports.notificationQueue.enqueue([ - { - userId: res.reply.value.user, - payload: JSON.stringify({ - title: "あなたのレスにリプライがありました", - // TODO: markdownを解釈する - body: res.text, - data: { - // TODO: フロントのURLを設定できるように - url: `https://anontown.com/topics/${res.topic}/reses/${res.id}`, - }, - }), - }, - ]); - } - const subscriptionUsers = await context.ports.topicRepo.subscriptionUserIds( - res.topic - ); - await context.ports.notificationQueue.enqueue( - subscriptionUsers - .filter((userId) => userId !== res.user) - .filter( - (userId) => O.isNone(res.reply) || userId !== res.reply.value.user - ) - .map((userId) => ({ - userId, - payload: JSON.stringify({ - title: "あなたが購読しているトピックに新しいレスがありました", - body: res.text, - data: { - url: `https://anontown.com/topics/${res.topic}/reses/${res.id}`, - }, - }), - })) - ); - - return api; - }, - voteRes: async (_obj, args, context, _info) => { - if (args.type === "cv") { - const [res, user] = await Promise.all([ - context.ports.resRepo.findOne(args.res), - context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ), - ]); - - // レスを書き込んだユーザー - const resUser = await context.ports.userRepo.findOne(res.user); - - const { res: newRes, resUser: newResUser } = res.cv( - resUser, - user, - context.ports.authContainer.getToken() - ); - - await Promise.all([ - context.ports.resRepo.update(newRes), - context.ports.userRepo.update(newResUser), - context.ports.userRepo.update(user), // TODO: user更新されてないから保存する必要ない - ]); - - return newRes.toAPI(some(context.ports.authContainer.getToken())); - } else { - const [res, user] = await Promise.all([ - context.ports.resRepo.findOne(args.res), - context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ), - ]); - - // レスを書き込んだユーザー - const resUser = await context.ports.userRepo.findOne(res.user); - - const { res: newRes, resUser: newResUser } = res.v( - resUser, - user, - args.type, - context.ports.authContainer.getToken() - ); - - await Promise.all([ - context.ports.resRepo.update(newRes), - context.ports.userRepo.update(newResUser), - context.ports.userRepo.update(user), // TODO: user更新されてないから保存する必要ない - ]); - - return newRes.toAPI(some(context.ports.authContainer.getToken())); - } - }, - delRes: async (_obj, args, context, _info) => { - const res = await context.ports.resRepo.findOne(args.res); - - if (res.type !== "normal") { - throw new AtNotFoundError("レスが見つかりません"); - } - - // レスを書き込んだユーザー - const resUser = await context.ports.userRepo.findOne(res.user); - - const { res: newRes, resUser: newResUser } = res.del( - resUser, - context.ports.authContainer.getToken() - ); - - await Promise.all([ - context.ports.resRepo.update(newRes), - context.ports.userRepo.update(newResUser), - ]); - - const api = newRes.toAPI(some(context.ports.authContainer.getToken())); - if (api.type !== "delete") { - throw new Error(); - } - return api; - }, - setStorages: async (_obj, args, context, _info) => { - // TODO: トランザクション - const results: IStorageAPI[] = []; - for (const storageInput of args.input.storages) { - const storage = Storage.create( - context.ports.authContainer.getToken(), - storageInput.key, - storageInput.value - ); - await context.ports.storageRepo.save(storage); - results.push(storage.toAPI(context.ports.authContainer.getToken())); - } - return { - storages: results, - }; - }, - delStorage: async (_obj, args, context, _info) => { - const storage = await context.ports.storageRepo.findOneKey( - context.ports.authContainer.getToken(), - args.key - ); - await context.ports.storageRepo.del(storage); - return null; - }, - createTopicNormal: async (_obj, args, context, _info) => { - const user = await context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ); - const create = TopicNormal.create( - context.ports.objectIdGenerator, - args.title, - args.tags, - args.text, - user, - context.ports.authContainer.getToken(), - context.ports.clock.now() - ); - - await context.ports.topicRepo.insert(create.topic); - await Promise.all([ - context.ports.userRepo.update(create.user), - context.ports.resRepo.insert(create.res), - context.ports.historyRepo.insert(create.history), - ]); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) - ); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "reses", create.res.id) - ); - context.ports.logger.info( - formatter.mutation( - context.ports.ipContainer, - "histories", - create.history.id - ) - ); - return create.topic.toAPI(); - }, - createTopicOne: async (_obj, args, context, _info) => { - const user = await context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ); - const create = TopicOne.create( - context.ports.objectIdGenerator, - args.title, - args.tags, - args.text, - user, - context.ports.authContainer.getToken(), - context.ports.clock.now() - ); - - await context.ports.topicRepo.insert(create.topic); - await Promise.all([ - context.ports.userRepo.update(create.user), - context.ports.resRepo.insert(create.res), - ]); - - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) - ); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "reses", create.res.id) - ); - - return create.topic.toAPI(); - }, - createTopicFork: async (_obj, args, context, _info) => { - const user = await context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ); - const parent = await context.ports.topicRepo.findOne(args.parent); - - if (parent.type !== "normal") { - throw new AtNotFoundError("トピックが見つかりません"); - } - - const create = TopicFork.create( - context.ports.objectIdGenerator, - args.title, - parent, - user, - context.ports.authContainer.getToken(), - context.ports.clock.now() - ); - - await context.ports.topicRepo.insert(create.topic); - await context.ports.topicRepo.update(create.parent); - await Promise.all([ - context.ports.userRepo.update(create.user), - context.ports.resRepo.insert(create.res), - context.ports.resRepo.insert(create.resParent), - ]); - - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) - ); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "reses", create.res.id) - ); - context.ports.logger.info( - formatter.mutation( - context.ports.ipContainer, - "reses", - create.resParent.id - ) - ); - - return create.topic.toAPI(); - }, - updateTopic: async (_obj, args, context, _info) => { - const [topic, user] = await Promise.all([ - context.ports.topicRepo.findOne(args.id), - context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ), - ]); - - if (topic.type !== "normal") { - throw new AtNotFoundError("トピックが見つかりません"); - } - - const val = topic.changeData( - context.ports.objectIdGenerator, - user, - context.ports.authContainer.getToken(), - nullToUndefined(args.title), - nullToUndefined(args.tags), - nullToUndefined(args.text), - context.ports.clock.now() - ); - - await Promise.all([ - context.ports.resRepo.insert(val.res), - context.ports.historyRepo.insert(val.history), - context.ports.topicRepo.update(val.topic), - context.ports.userRepo.update(val.user), - ]); - - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "reses", val.res.id) - ); - context.ports.logger.info( - formatter.mutation(context.ports.ipContainer, "histories", val.history.id) - ); - - return topic.toAPI(); - }, - resisterPushSubscription: async (_obj, args, context, _info) => { - await context.ports.pushSubscriptionsRepo.upsert( - context.ports.authContainer.getToken().user, - { - endpoint: args.endpoint, - keys: { - p256dh: args.p256dh, - auth: args.auth, - }, - } - ); - return null; - }, - subscribeTopic: async (_obj, args, context, _info) => { - await context.ports.topicRepo.enableSubscription( - args.topic, - context.ports.authContainer.getToken().user - ); - return null; - }, - unsubscribeTopic: async (_obj, args, context, _info) => { - await context.ports.topicRepo.disableSubscription( - args.topic, - context.ports.authContainer.getToken().user - ); - return null; - }, -}; diff --git a/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts b/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts index 9baf6d0..13a84ec 100644 --- a/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts +++ b/packages/server/src/schema/base/resolvers/Mutation/resisterPushSubscription.ts @@ -1,2 +1,17 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const resisterPushSubscription: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.resisterPushSubscription resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; + +export const resisterPushSubscription: NonNullable< + MutationResolvers["resisterPushSubscription"] +> = async (_obj, args, context, _info) => { + await context.ports.pushSubscriptionsRepo.upsert( + context.ports.authContainer.getToken().user, + { + endpoint: args.endpoint, + keys: { + p256dh: args.p256dh, + auth: args.auth, + }, + } + ); + return null; +}; diff --git a/packages/server/src/schema/client/resolvers/Mutation/createClient.ts b/packages/server/src/schema/client/resolvers/Mutation/createClient.ts index cc5487c..d2b4f84 100644 --- a/packages/server/src/schema/client/resolvers/Mutation/createClient.ts +++ b/packages/server/src/schema/client/resolvers/Mutation/createClient.ts @@ -1,2 +1,21 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createClient resolver logic here */ }; \ No newline at end of file +import { some } from "fp-ts/lib/Option"; +import { Client } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; + +export const createClient: NonNullable< + MutationResolvers["createClient"] +> = async (_obj, args, context, _info) => { + const client = Client.create( + context.ports.objectIdGenerator, + context.ports.authContainer.getTokenMaster(), + args.name, + args.url, + context.ports.clock.now() + ); + await context.ports.clientRepo.insert(client); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "clients", client.id) + ); + return client.toAPI(some(context.ports.authContainer.getTokenMaster())); +}; diff --git a/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts b/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts index 56f0f92..3005803 100644 --- a/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts +++ b/packages/server/src/schema/client/resolvers/Mutation/updateClient.ts @@ -1,2 +1,21 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const updateClient: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateClient resolver logic here */ }; \ No newline at end of file +import { nullToUndefined } from "@kgtkr/utils"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { some } from "fp-ts/lib/Option"; + +export const updateClient: NonNullable< + MutationResolvers["updateClient"] +> = async (_obj, args, context, _info) => { + const client = await context.ports.clientRepo.findOne(args.id); + const newClient = client.changeData( + context.ports.authContainer.getTokenMaster(), + nullToUndefined(args.name), + nullToUndefined(args.url), + context.ports.clock.now() + ); + await context.ports.clientRepo.update(newClient); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "clients", client.id) + ); + return newClient.toAPI(some(context.ports.authContainer.getTokenMaster())); +}; diff --git a/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts b/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts index 91ab778..00de270 100644 --- a/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts +++ b/packages/server/src/schema/profile/resolvers/Mutation/createProfile.ts @@ -1,2 +1,22 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createProfile: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createProfile resolver logic here */ }; \ No newline at end of file +import { Profile } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { some } from "fp-ts/lib/Option"; + +export const createProfile: NonNullable< + MutationResolvers["createProfile"] +> = async (_obj, args, context, _info) => { + const profile = Profile.create( + context.ports.objectIdGenerator, + context.ports.authContainer.getToken(), + args.name, + args.text, + args.sn, + context.ports.clock.now() + ); + await context.ports.profileRepo.insert(profile); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "profiles", profile.id) + ); + return profile.toAPI(some(context.ports.authContainer.getToken())); +}; diff --git a/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts b/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts index a7e08a0..ccc937b 100644 --- a/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts +++ b/packages/server/src/schema/profile/resolvers/Mutation/updateProfile.ts @@ -1,2 +1,22 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const updateProfile: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateProfile resolver logic here */ }; \ No newline at end of file +import { nullToUndefined } from "@kgtkr/utils"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { some } from "fp-ts/lib/Option"; + +export const updateProfile: NonNullable< + MutationResolvers["updateProfile"] +> = async (_obj, args, context, _info) => { + const profile = await context.ports.profileRepo.findOne(args.id); + const newProfile = profile.changeData( + context.ports.authContainer.getToken(), + nullToUndefined(args.name), + nullToUndefined(args.text), + nullToUndefined(args.sn), + context.ports.clock.now() + ); + await context.ports.profileRepo.update(newProfile); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "profiles", newProfile.id) + ); + return newProfile.toAPI(some(context.ports.authContainer.getToken())); +}; diff --git a/packages/server/src/schema/res/resolvers/Mutation/createRes.ts b/packages/server/src/schema/res/resolvers/Mutation/createRes.ts index 9c63601..d87f177 100644 --- a/packages/server/src/schema/res/resolvers/Mutation/createRes.ts +++ b/packages/server/src/schema/res/resolvers/Mutation/createRes.ts @@ -1,2 +1,93 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createRes resolver logic here */ }; \ No newline at end of file +import { isNullish } from "@kgtkr/utils"; +import type { MutationResolvers } from "./../../../types.generated"; +import { ResNormal } from "../../../../entities"; +import * as formatter from "../../../../formatter"; +import * as O from "fp-ts/lib/Option"; + +export const createRes: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const [topic, user, reply, profile] = await Promise.all([ + context.ports.topicRepo.findOne(args.topic), + context.ports.userRepo.findOne(context.ports.authContainer.getToken().user), + !isNullish(args.reply) + ? context.ports.resRepo.findOne(args.reply) + : Promise.resolve(null), + !isNullish(args.profile) + ? context.ports.profileRepo.findOne(args.profile) + : Promise.resolve(null), + ] as const); + + const { + res, + user: newUser, + topic: newTopic, + } = ResNormal.create( + context.ports.objectIdGenerator, + topic, + user, + context.ports.authContainer.getToken(), + O.fromNullable(args.name), + args.text, + O.fromNullable(reply), + O.fromNullable(profile), + args.age, + context.ports.clock.now() + ); + + await Promise.all([ + context.ports.resRepo.insert(res), + context.ports.topicRepo.update(newTopic), + context.ports.userRepo.update(newUser), + ]); + + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", res.id) + ); + const api = res.toAPI(O.some(context.ports.authContainer.getToken())); + if (api.type !== "normal") { + throw new Error(); + } + + if (O.isSome(res.reply) && res.user !== res.reply.value.user) { + await context.ports.notificationQueue.enqueue([ + { + userId: res.reply.value.user, + payload: JSON.stringify({ + title: "あなたのレスにリプライがありました", + // TODO: markdownを解釈する + body: res.text, + data: { + // TODO: フロントのURLを設定できるように + url: `https://anontown.com/topics/${res.topic}/reses/${res.id}`, + }, + }), + }, + ]); + } + const subscriptionUsers = await context.ports.topicRepo.subscriptionUserIds( + res.topic + ); + await context.ports.notificationQueue.enqueue( + subscriptionUsers + .filter((userId) => userId !== res.user) + .filter( + (userId) => O.isNone(res.reply) || userId !== res.reply.value.user + ) + .map((userId) => ({ + userId, + payload: JSON.stringify({ + title: "あなたが購読しているトピックに新しいレスがありました", + body: res.text, + data: { + url: `https://anontown.com/topics/${res.topic}/reses/${res.id}`, + }, + }), + })) + ); + + return api; +}; diff --git a/packages/server/src/schema/res/resolvers/Mutation/delRes.ts b/packages/server/src/schema/res/resolvers/Mutation/delRes.ts index 7b03182..87cdb29 100644 --- a/packages/server/src/schema/res/resolvers/Mutation/delRes.ts +++ b/packages/server/src/schema/res/resolvers/Mutation/delRes.ts @@ -1,2 +1,34 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const delRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delRes resolver logic here */ }; \ No newline at end of file +import { some } from "fp-ts/lib/Option"; +import { AtNotFoundError } from "../../../../at-error"; +import type { MutationResolvers } from "./../../../types.generated"; +export const delRes: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const res = await context.ports.resRepo.findOne(args.res); + + if (res.type !== "normal") { + throw new AtNotFoundError("レスが見つかりません"); + } + + // レスを書き込んだユーザー + const resUser = await context.ports.userRepo.findOne(res.user); + + const { res: newRes, resUser: newResUser } = res.del( + resUser, + context.ports.authContainer.getToken() + ); + + await Promise.all([ + context.ports.resRepo.update(newRes), + context.ports.userRepo.update(newResUser), + ]); + + const api = newRes.toAPI(some(context.ports.authContainer.getToken())); + if (api.type !== "delete") { + throw new Error(); + } + return api; +}; diff --git a/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts b/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts index 8c208b0..907536f 100644 --- a/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts +++ b/packages/server/src/schema/res/resolvers/Mutation/voteRes.ts @@ -1,2 +1,59 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const voteRes: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.voteRes resolver logic here */ }; \ No newline at end of file +import { some } from "fp-ts/lib/Option"; +import type { MutationResolvers } from "./../../../types.generated"; +export const voteRes: NonNullable = async ( + _obj, + args, + context, + _info +) => { + if (args.type === "cv") { + const [res, user] = await Promise.all([ + context.ports.resRepo.findOne(args.res), + context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ), + ]); + + // レスを書き込んだユーザー + const resUser = await context.ports.userRepo.findOne(res.user); + + const { res: newRes, resUser: newResUser } = res.cv( + resUser, + user, + context.ports.authContainer.getToken() + ); + + await Promise.all([ + context.ports.resRepo.update(newRes), + context.ports.userRepo.update(newResUser), + context.ports.userRepo.update(user), // TODO: user更新されてないから保存する必要ない + ]); + + return newRes.toAPI(some(context.ports.authContainer.getToken())); + } else { + const [res, user] = await Promise.all([ + context.ports.resRepo.findOne(args.res), + context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ), + ]); + + // レスを書き込んだユーザー + const resUser = await context.ports.userRepo.findOne(res.user); + + const { res: newRes, resUser: newResUser } = res.v( + resUser, + user, + args.type, + context.ports.authContainer.getToken() + ); + + await Promise.all([ + context.ports.resRepo.update(newRes), + context.ports.userRepo.update(newResUser), + context.ports.userRepo.update(user), // TODO: user更新されてないから保存する必要ない + ]); + + return newRes.toAPI(some(context.ports.authContainer.getToken())); + } +}; diff --git a/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts b/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts index 13a2e54..21331ca 100644 --- a/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts +++ b/packages/server/src/schema/storage/resolvers/Mutation/delStorage.ts @@ -1,2 +1,14 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const delStorage: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.delStorage resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +export const delStorage: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const storage = await context.ports.storageRepo.findOneKey( + context.ports.authContainer.getToken(), + args.key + ); + await context.ports.storageRepo.del(storage); + return null; +}; diff --git a/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts b/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts index 0ad70cc..77935c7 100644 --- a/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts +++ b/packages/server/src/schema/storage/resolvers/Mutation/setStorages.ts @@ -1,2 +1,20 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const setStorages: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.setStorages resolver logic here */ }; \ No newline at end of file +import { IStorageAPI, Storage } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; +export const setStorages: NonNullable< + MutationResolvers["setStorages"] +> = async (_obj, args, context, _info) => { + // TODO: トランザクション + const results: IStorageAPI[] = []; + for (const storageInput of args.input.storages) { + const storage = Storage.create( + context.ports.authContainer.getToken(), + storageInput.key, + storageInput.value + ); + await context.ports.storageRepo.save(storage); + results.push(storage.toAPI(context.ports.authContainer.getToken())); + } + return { + storages: results, + }; +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts index 1127c6b..9d8ad0f 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicFork.ts @@ -1,2 +1,46 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTopicFork: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicFork resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { TopicFork } from "../../../../entities"; +import { AtNotFoundError } from "../../../../at-error"; + +export const createTopicFork: NonNullable< + MutationResolvers["createTopicFork"] +> = async (_obj, args, context, _info) => { + const user = await context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ); + const parent = await context.ports.topicRepo.findOne(args.parent); + + if (parent.type !== "normal") { + throw new AtNotFoundError("トピックが見つかりません"); + } + + const create = TopicFork.create( + context.ports.objectIdGenerator, + args.title, + parent, + user, + context.ports.authContainer.getToken(), + context.ports.clock.now() + ); + + await context.ports.topicRepo.insert(create.topic); + await context.ports.topicRepo.update(create.parent); + await Promise.all([ + context.ports.userRepo.update(create.user), + context.ports.resRepo.insert(create.res), + context.ports.resRepo.insert(create.resParent), + ]); + + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) + ); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", create.res.id) + ); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", create.resParent.id) + ); + + return create.topic.toAPI(); +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts index 7c27ca6..49280db 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicNormal.ts @@ -1,2 +1,41 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTopicNormal: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicNormal resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { TopicNormal } from "../../../../entities"; + +export const createTopicNormal: NonNullable< + MutationResolvers["createTopicNormal"] +> = async (_obj, args, context, _info) => { + const user = await context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ); + const create = TopicNormal.create( + context.ports.objectIdGenerator, + args.title, + args.tags, + args.text, + user, + context.ports.authContainer.getToken(), + context.ports.clock.now() + ); + + await context.ports.topicRepo.insert(create.topic); + await Promise.all([ + context.ports.userRepo.update(create.user), + context.ports.resRepo.insert(create.res), + context.ports.historyRepo.insert(create.history), + ]); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) + ); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", create.res.id) + ); + context.ports.logger.info( + formatter.mutation( + context.ports.ipContainer, + "histories", + create.history.id + ) + ); + return create.topic.toAPI(); +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts b/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts index 99de195..85e5469 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/createTopicOne.ts @@ -1,2 +1,35 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createTopicOne: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createTopicOne resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; +import { TopicOne } from "../../../../entities"; + +export const createTopicOne: NonNullable< + MutationResolvers["createTopicOne"] +> = async (_obj, args, context, _info) => { + const user = await context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ); + const create = TopicOne.create( + context.ports.objectIdGenerator, + args.title, + args.tags, + args.text, + user, + context.ports.authContainer.getToken(), + context.ports.clock.now() + ); + + await context.ports.topicRepo.insert(create.topic); + await Promise.all([ + context.ports.userRepo.update(create.user), + context.ports.resRepo.insert(create.res), + ]); + + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "topics", create.topic.id) + ); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", create.res.id) + ); + + return create.topic.toAPI(); +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts index 36fc35b..acaf499 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/subscribeTopic.ts @@ -1,2 +1,10 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const subscribeTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.subscribeTopic resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +export const subscribeTopic: NonNullable< + MutationResolvers["subscribeTopic"] +> = async (_obj, args, context, _info) => { + await context.ports.topicRepo.enableSubscription( + args.topic, + context.ports.authContainer.getToken().user + ); + return null; +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts index e211563..b42c6ad 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/unsubscribeTopic.ts @@ -1,2 +1,11 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const unsubscribeTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.unsubscribeTopic resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; + +export const unsubscribeTopic: NonNullable< + MutationResolvers["unsubscribeTopic"] +> = async (_obj, args, context, _info) => { + await context.ports.topicRepo.disableSubscription( + args.topic, + context.ports.authContainer.getToken().user + ); + return null; +}; diff --git a/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts b/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts index b08c2fc..b7c5f98 100644 --- a/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts +++ b/packages/server/src/schema/topic/resolvers/Mutation/updateTopic.ts @@ -1,2 +1,43 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const updateTopic: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateTopic resolver logic here */ }; \ No newline at end of file +import { nullToUndefined } from "@kgtkr/utils"; +import { AtNotFoundError } from "../../../../at-error"; +import type { MutationResolvers } from "./../../../types.generated"; +import * as formatter from "../../../../formatter"; + +export const updateTopic: NonNullable< + MutationResolvers["updateTopic"] +> = async (_obj, args, context, _info) => { + const [topic, user] = await Promise.all([ + context.ports.topicRepo.findOne(args.id), + context.ports.userRepo.findOne(context.ports.authContainer.getToken().user), + ]); + + if (topic.type !== "normal") { + throw new AtNotFoundError("トピックが見つかりません"); + } + + const val = topic.changeData( + context.ports.objectIdGenerator, + user, + context.ports.authContainer.getToken(), + nullToUndefined(args.title), + nullToUndefined(args.tags), + nullToUndefined(args.text), + context.ports.clock.now() + ); + + await Promise.all([ + context.ports.resRepo.insert(val.res), + context.ports.historyRepo.insert(val.history), + context.ports.topicRepo.update(val.topic), + context.ports.userRepo.update(val.user), + ]); + + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "reses", val.res.id) + ); + context.ports.logger.info( + formatter.mutation(context.ports.ipContainer, "histories", val.history.id) + ); + + return topic.toAPI(); +}; diff --git a/packages/server/src/schema/user/resolvers/Mutation/createUser.ts b/packages/server/src/schema/user/resolvers/Mutation/createUser.ts index 671320f..5a487df 100644 --- a/packages/server/src/schema/user/resolvers/Mutation/createUser.ts +++ b/packages/server/src/schema/user/resolvers/Mutation/createUser.ts @@ -1,2 +1,28 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const createUser: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.createUser resolver logic here */ }; \ No newline at end of file +import { TokenMaster, User } from "../../../../entities"; +import type { MutationResolvers } from "./../../../types.generated"; +export const createUser: NonNullable = async ( + _obj, + args, + context, + _info +) => { + await context.ports.recaptcha.verify(args.recaptcha); + + const user = User.create( + context.ports.objectIdGenerator, + args.sn, + args.pass, + context.ports.clock.now() + ); + await context.ports.userRepo.insert(user); + + const token = TokenMaster.create( + context.ports.objectIdGenerator, + user.auth(args.pass), + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + await context.ports.tokenRepo.insert(token); + + return { user: user.toAPI(), token: token.toAPI() }; +}; diff --git a/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts b/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts index d492797..2ea7620 100644 --- a/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts +++ b/packages/server/src/schema/user/resolvers/Mutation/updateUser.ts @@ -1,2 +1,33 @@ -import type { MutationResolvers } from './../../../types.generated'; - export const updateUser: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Mutation.updateUser resolver logic here */ }; \ No newline at end of file +import type { MutationResolvers } from "./../../../types.generated"; +import * as authFromApiParam from "../../../../server/auth-from-api-param"; +import { nullToUndefined } from "@kgtkr/utils"; +import { TokenMaster } from "../../../../entities"; + +export const updateUser: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const authUser = await authFromApiParam.authUserRequestToUser( + context.ports.userRepo, + args.auth + ); + const user = await context.ports.userRepo.findOne(authUser.id); + const newUser = user.change( + authUser, + nullToUndefined(args.pass), + nullToUndefined(args.sn) + ); + await context.ports.userRepo.update(newUser); + await context.ports.tokenRepo.delMasterToken(authUser); + + const token = TokenMaster.create( + context.ports.objectIdGenerator, + authUser, + context.ports.clock.now(), + context.ports.safeIdGenerator + ); + await context.ports.tokenRepo.insert(token); + return { user: newUser.toAPI(), token: token.toAPI() }; +}; From d21f1af7b48925e848983079d317f8dd74ac6cdd Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 20:28:06 +0900 Subject: [PATCH 06/10] =?UTF-8?q?query=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/resolvers/query.ts | 115 ------------------ .../src/schema/base/resolvers/Query/query.ts | 11 +- .../schema/client/resolvers/Query/clients.ts | 20 ++- .../server/src/schema/convertDateQuery.ts | 13 ++ .../history/resolvers/Query/histories.ts | 23 +++- .../profile/resolvers/Query/profiles.ts | 21 +++- .../src/schema/res/resolvers/Query/reses.ts | 29 ++++- .../storage/resolvers/Query/storages.ts | 19 ++- packages/server/src/schema/stringToDate.ts | 6 + .../schema/topic/resolvers/Query/topicTags.ts | 12 +- .../schema/topic/resolvers/Query/topics.ts | 23 +++- .../src/schema/user/resolvers/Query/user.ts | 16 ++- .../src/schema/user/resolvers/Query/userID.ts | 11 +- .../src/schema/user/resolvers/Query/userSN.ts | 12 +- 14 files changed, 194 insertions(+), 137 deletions(-) delete mode 100644 packages/server/src/resolvers/query.ts create mode 100644 packages/server/src/schema/convertDateQuery.ts create mode 100644 packages/server/src/schema/stringToDate.ts diff --git a/packages/server/src/resolvers/query.ts b/packages/server/src/resolvers/query.ts deleted file mode 100644 index 1f0ed3f..0000000 --- a/packages/server/src/resolvers/query.ts +++ /dev/null @@ -1,115 +0,0 @@ -import * as G from "../generated/graphql"; -import { DateQuery } from "../ports/types"; - -function convertDateQuery(query: G.DateQuery | null): DateQuery | null { - if (query === null) { - return null; - } - return { - date: query.date.toISOString(), - type: query.type, - }; -} - -export const query: G.QueryResolvers = { - query: async (_obj, _args, _context, _info) => { - return query; - }, - userID: async (_obj, args, context, _info) => { - return await context.ports.userRepo.findID(args.sn); - }, - userSN: async (_obj, args, context, _info) => { - return (await context.ports.userRepo.findOne(args.id)).sn; - }, - user: async (_obj, _args, context, _info) => { - return ( - await context.ports.userRepo.findOne( - context.ports.authContainer.getToken().user - ) - ).toAPI(); - }, - clients: async (_obj, args, context, _info) => { - const clients = await context.ports.clientRepo.find( - context.ports.authContainer.getTokenMasterOrNull(), - { - id: args.query.id ?? null, - self: args.query.self ?? null, - } - ); - return clients.map((c) => - c.toAPI(context.ports.authContainer.getTokenMasterOrNull()) - ); - }, - histories: async (_obj, args, context, _info) => { - const histories = await context.ports.historyRepo.find( - { - id: args.query.id ?? null, - date: convertDateQuery(args.query.date ?? null), - topic: args.query.topic ?? null, - }, - args.limit - ); - return histories.map((x) => - x.toAPI(context.ports.authContainer.getTokenOrNull()) - ); - }, - profiles: async (_obj, args, context, _info) => { - const profiles = await context.ports.profileRepo.find( - context.ports.authContainer, - { - id: args.query.id ?? null, - self: args.query.self ?? null, - } - ); - return profiles.map((p) => - p.toAPI(context.ports.authContainer.getTokenOrNull()) - ); - }, - reses: async (_obj, args, context, _info: any) => { - const reses = await context.ports.resRepo.find( - context.ports.authContainer, - { - id: args.query.id ?? null, - date: convertDateQuery(args.query.date ?? null), - topic: args.query.topic ?? null, - hash: args.query.hash ?? null, - profile: args.query.profile ?? null, - notice: args.query.notice ?? null, - reply: args.query.reply ?? null, - self: args.query.self ?? null, - text: args.query.text ?? null, - }, - args.limit - ); - return reses.map((x) => - x.toAPI(context.ports.authContainer.getTokenOrNull()) - ); - }, - storages: async (_obj, args, context, _info) => { - const storages = await context.ports.storageRepo.find( - context.ports.authContainer.getToken(), - { - key: args.query.key ?? null, - keyPrefix: args.query.keyPrefix ?? null, - } - ); - return storages.map((x) => x.toAPI(context.ports.authContainer.getToken())); - }, - topics: async (_obj, args, context, _info) => { - const topic = await context.ports.topicRepo.find( - { - id: args.query.id ?? null, - title: args.query.title ?? null, - tags: args.query.tags ?? null, - activeOnly: args.query.activeOnly ?? null, - parent: args.query.parent ?? null, - }, - args.skip, - args.limit - ); - return topic.map((t) => t.toAPI()); - }, - topicTags: async (_obj, args, context, _info) => { - return await context.ports.topicRepo.findTags(args.limit); - }, -}; diff --git a/packages/server/src/schema/base/resolvers/Query/query.ts b/packages/server/src/schema/base/resolvers/Query/query.ts index f4049e6..a156f4a 100644 --- a/packages/server/src/schema/base/resolvers/Query/query.ts +++ b/packages/server/src/schema/base/resolvers/Query/query.ts @@ -1,2 +1,9 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const query: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.query resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; +export const query: NonNullable = async ( + _obj, + _args, + _ctx, + _info +) => { + return {}; +}; diff --git a/packages/server/src/schema/client/resolvers/Query/clients.ts b/packages/server/src/schema/client/resolvers/Query/clients.ts index 1131b00..1da86e3 100644 --- a/packages/server/src/schema/client/resolvers/Query/clients.ts +++ b/packages/server/src/schema/client/resolvers/Query/clients.ts @@ -1,2 +1,18 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const clients: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.clients resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; +export const clients: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const clients = await context.ports.clientRepo.find( + context.ports.authContainer.getTokenMasterOrNull(), + { + id: args.query.id ?? null, + self: args.query.self ?? null, + } + ); + return clients.map((c) => + c.toAPI(context.ports.authContainer.getTokenMasterOrNull()) + ); +}; diff --git a/packages/server/src/schema/convertDateQuery.ts b/packages/server/src/schema/convertDateQuery.ts new file mode 100644 index 0000000..e7c96d1 --- /dev/null +++ b/packages/server/src/schema/convertDateQuery.ts @@ -0,0 +1,13 @@ +import { DateQuery } from "../ports/types"; +import { stringToDate } from "./stringToDate"; +import * as G from "./types.generated"; + +export function convertDateQuery(query: G.DateQuery | null): DateQuery | null { + if (query === null) { + return null; + } + return { + date: stringToDate(query.date).toISOString(), + type: query.type, + }; +} diff --git a/packages/server/src/schema/history/resolvers/Query/histories.ts b/packages/server/src/schema/history/resolvers/Query/histories.ts index 85a0b2e..5b8d58b 100644 --- a/packages/server/src/schema/history/resolvers/Query/histories.ts +++ b/packages/server/src/schema/history/resolvers/Query/histories.ts @@ -1,2 +1,21 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const histories: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.histories resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; +import { convertDateQuery } from "../../../convertDateQuery"; + +export const histories: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const histories = await context.ports.historyRepo.find( + { + id: args.query.id ?? null, + date: convertDateQuery(args.query.date ?? null), + topic: args.query.topic ?? null, + }, + args.limit + ); + return histories.map((x) => + x.toAPI(context.ports.authContainer.getTokenOrNull()) + ); +}; diff --git a/packages/server/src/schema/profile/resolvers/Query/profiles.ts b/packages/server/src/schema/profile/resolvers/Query/profiles.ts index d4e66ca..aa45242 100644 --- a/packages/server/src/schema/profile/resolvers/Query/profiles.ts +++ b/packages/server/src/schema/profile/resolvers/Query/profiles.ts @@ -1,2 +1,19 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const profiles: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.profiles resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const profiles: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const profiles = await context.ports.profileRepo.find( + context.ports.authContainer, + { + id: args.query.id ?? null, + self: args.query.self ?? null, + } + ); + return profiles.map((p) => + p.toAPI(context.ports.authContainer.getTokenOrNull()) + ); +}; diff --git a/packages/server/src/schema/res/resolvers/Query/reses.ts b/packages/server/src/schema/res/resolvers/Query/reses.ts index ed28cc8..19b0f81 100644 --- a/packages/server/src/schema/res/resolvers/Query/reses.ts +++ b/packages/server/src/schema/res/resolvers/Query/reses.ts @@ -1,2 +1,27 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const reses: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.reses resolver logic here */ }; \ No newline at end of file +import { convertDateQuery } from "../../../convertDateQuery"; +import type { QueryResolvers } from "./../../../types.generated"; +export const reses: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const reses = await context.ports.resRepo.find( + context.ports.authContainer, + { + id: args.query.id ?? null, + date: convertDateQuery(args.query.date ?? null), + topic: args.query.topic ?? null, + hash: args.query.hash ?? null, + profile: args.query.profile ?? null, + notice: args.query.notice ?? null, + reply: args.query.reply ?? null, + self: args.query.self ?? null, + text: args.query.text ?? null, + }, + args.limit + ); + return reses.map((x) => + x.toAPI(context.ports.authContainer.getTokenOrNull()) + ); +}; diff --git a/packages/server/src/schema/storage/resolvers/Query/storages.ts b/packages/server/src/schema/storage/resolvers/Query/storages.ts index e8293b0..26c019f 100644 --- a/packages/server/src/schema/storage/resolvers/Query/storages.ts +++ b/packages/server/src/schema/storage/resolvers/Query/storages.ts @@ -1,2 +1,17 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const storages: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.storages resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const storages: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const storages = await context.ports.storageRepo.find( + context.ports.authContainer.getToken(), + { + key: args.query.key ?? null, + keyPrefix: args.query.keyPrefix ?? null, + } + ); + return storages.map((x) => x.toAPI(context.ports.authContainer.getToken())); +}; diff --git a/packages/server/src/schema/stringToDate.ts b/packages/server/src/schema/stringToDate.ts new file mode 100644 index 0000000..327deb1 --- /dev/null +++ b/packages/server/src/schema/stringToDate.ts @@ -0,0 +1,6 @@ +export function stringToDate(date: string | Date): Date { + if (typeof date === "string") { + return new Date(date); + } + return date; +} diff --git a/packages/server/src/schema/topic/resolvers/Query/topicTags.ts b/packages/server/src/schema/topic/resolvers/Query/topicTags.ts index 932aee7..6c01a1b 100644 --- a/packages/server/src/schema/topic/resolvers/Query/topicTags.ts +++ b/packages/server/src/schema/topic/resolvers/Query/topicTags.ts @@ -1,2 +1,10 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const topicTags: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.topicTags resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const topicTags: NonNullable = async ( + _obj, + args, + context, + _info +) => { + return await context.ports.topicRepo.findTags(args.limit); +}; diff --git a/packages/server/src/schema/topic/resolvers/Query/topics.ts b/packages/server/src/schema/topic/resolvers/Query/topics.ts index 8a7725e..2a4f076 100644 --- a/packages/server/src/schema/topic/resolvers/Query/topics.ts +++ b/packages/server/src/schema/topic/resolvers/Query/topics.ts @@ -1,2 +1,21 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const topics: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.topics resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const topics: NonNullable = async ( + _obj, + args, + context, + _info +) => { + const topic = await context.ports.topicRepo.find( + { + id: args.query.id ?? null, + title: args.query.title ?? null, + tags: args.query.tags ?? null, + activeOnly: args.query.activeOnly ?? null, + parent: args.query.parent ?? null, + }, + args.skip, + args.limit + ); + return topic.map((t) => t.toAPI()); +}; diff --git a/packages/server/src/schema/user/resolvers/Query/user.ts b/packages/server/src/schema/user/resolvers/Query/user.ts index cdb1088..8a19272 100644 --- a/packages/server/src/schema/user/resolvers/Query/user.ts +++ b/packages/server/src/schema/user/resolvers/Query/user.ts @@ -1,2 +1,14 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const user: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.user resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const user: NonNullable = async ( + _obj, + _args, + context, + _info +) => { + return ( + await context.ports.userRepo.findOne( + context.ports.authContainer.getToken().user + ) + ).toAPI(); +}; diff --git a/packages/server/src/schema/user/resolvers/Query/userID.ts b/packages/server/src/schema/user/resolvers/Query/userID.ts index efbbe93..63eea1b 100644 --- a/packages/server/src/schema/user/resolvers/Query/userID.ts +++ b/packages/server/src/schema/user/resolvers/Query/userID.ts @@ -1,2 +1,9 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const userID: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.userID resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; +export const userID: NonNullable = async ( + _obj, + args, + context, + _info +) => { + return await context.ports.userRepo.findID(args.sn); +}; diff --git a/packages/server/src/schema/user/resolvers/Query/userSN.ts b/packages/server/src/schema/user/resolvers/Query/userSN.ts index 47f8cc6..ccb3aad 100644 --- a/packages/server/src/schema/user/resolvers/Query/userSN.ts +++ b/packages/server/src/schema/user/resolvers/Query/userSN.ts @@ -1,2 +1,10 @@ -import type { QueryResolvers } from './../../../types.generated'; - export const userSN: NonNullable = async (_parent, _arg, _ctx) => { /* Implement Query.userSN resolver logic here */ }; \ No newline at end of file +import type { QueryResolvers } from "./../../../types.generated"; + +export const userSN: NonNullable = async ( + _obj, + args, + context, + _info +) => { + return (await context.ports.userRepo.findOne(args.id)).sn; +}; From 9123ad16f4973fdc80b6bc3bd35253efb0edb8fa Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 20:41:30 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E5=85=A8=E9=83=A8=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/resolvers/index.ts | 37 ------------ packages/server/src/resolvers/res.ts | 56 ------------------ packages/server/src/resolvers/subscription.ts | 17 ------ packages/server/src/resolvers/topic.ts | 57 ------------------- .../src/schema/res/resolvers/ResBase.ts | 9 +++ .../src/schema/res/resolvers/ResDelete.ts | 19 ++----- .../src/schema/res/resolvers/ResFork.ts | 28 ++++----- .../src/schema/res/resolvers/ResHistory.ts | 25 ++++---- .../src/schema/res/resolvers/ResNormal.ts | 38 ++++++++----- .../src/schema/res/resolvers/ResTopic.ts | 11 ++-- .../res/resolvers/Subscription/resAdded.ts | 19 +++++-- packages/server/src/schema/resolveTypes.ts | 22 +++++++ .../src/schema/topic/resolvers/TopicBase.ts | 16 ++++++ .../src/schema/topic/resolvers/TopicFork.ts | 26 +++++---- .../src/schema/topic/resolvers/TopicNormal.ts | 11 ++-- .../src/schema/topic/resolvers/TopicOne.ts | 11 ++-- .../schema/topic/resolvers/TopicSearchBase.ts | 6 ++ 17 files changed, 154 insertions(+), 254 deletions(-) delete mode 100644 packages/server/src/resolvers/index.ts delete mode 100644 packages/server/src/resolvers/res.ts delete mode 100644 packages/server/src/resolvers/subscription.ts delete mode 100644 packages/server/src/resolvers/topic.ts create mode 100644 packages/server/src/schema/res/resolvers/ResBase.ts create mode 100644 packages/server/src/schema/topic/resolvers/TopicBase.ts create mode 100644 packages/server/src/schema/topic/resolvers/TopicSearchBase.ts diff --git a/packages/server/src/resolvers/index.ts b/packages/server/src/resolvers/index.ts deleted file mode 100644 index 1e4821a..0000000 --- a/packages/server/src/resolvers/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -import * as G from "../generated/graphql"; -import { history } from "./history"; -import { mutation } from "./mutation"; -import { query } from "./query"; -import { - res, - resDelete, - resFork, - resHistory, - resNormal, - resTopic, -} from "./res"; -import { subscription } from "./subscription"; -import { token, tokenGeneral } from "./token"; -import { topic, topicFork, topicNormal, topicOne, topicSearch } from "./topic"; -import { DateTimeResolver } from "graphql-scalars"; - -export const resolvers: G.Resolvers = { - DateTime: DateTimeResolver, - History: history, - Mutation: mutation, - Query: query, - Res: res, - ResNormal: resNormal, - ResHistory: resHistory, - ResTopic: resTopic, - ResDelete: resDelete, - ResFork: resFork, - Subscription: subscription, - Token: token, - TokenGeneral: tokenGeneral, - Topic: topic, - TopicSearch: topicSearch, - TopicFork: topicFork, - TopicOne: topicOne, - TopicNormal: topicNormal, -}; diff --git a/packages/server/src/resolvers/res.ts b/packages/server/src/resolvers/res.ts deleted file mode 100644 index 19ac541..0000000 --- a/packages/server/src/resolvers/res.ts +++ /dev/null @@ -1,56 +0,0 @@ -import * as G from "../generated/graphql"; -import { getHistory, getProfile, getRes, getTopic } from "../usecases"; - -const resBase: Pick = { - topic: async (res, _args, context, _info) => { - const topic = await getTopic({ id: res.topicID }, context.ports); - return topic; - }, -}; - -export const resNormal: G.ResNormalResolvers = { - ...resBase, - reply: async (res, _args, context, _info) => { - if (res.replyID !== null) { - const reply = await getRes({ id: res.replyID }, context.ports); - return reply; - } else { - return null; - } - }, - profile: async (res, _args, context, _info) => { - if (res.profileID !== null) { - const profile = await getProfile({ id: res.profileID }, context.ports); - return profile; - } else { - return null; - } - }, -}; - -export const resHistory: G.ResHistoryResolvers = { - ...resBase, - history: async (res, _args, context, _info) => { - const history = await getHistory({ id: res.historyID }, context.ports); - return history; - }, -}; - -export const resTopic: G.ResTopicResolvers = { - ...resBase, -}; - -export const resFork: G.ResForkResolvers = { - ...resBase, - fork: async (res, _args, context, _info) => { - const fork = await getTopic({ id: res.forkID }, context.ports); - if (fork.type !== "fork") { - throw new Error(); - } - return fork; - }, -}; - -export const resDelete: G.ResDeleteResolvers = { - ...resBase, -}; diff --git a/packages/server/src/resolvers/subscription.ts b/packages/server/src/resolvers/subscription.ts deleted file mode 100644 index bd8fb19..0000000 --- a/packages/server/src/resolvers/subscription.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as G from "../generated/graphql"; -import * as ixa from "ix/asynciterable"; -import * as ixaOps from "ix/asynciterable/operators"; - -export const subscription: G.SubscriptionResolvers = { - resAdded: { - subscribe: (_parent, args, context, _info) => - ixa.from(context.ports.resRepo.subscribeInsertEvent(args.topic)).pipe( - ixaOps.map((data) => ({ - resAdded: { - count: data.count, - res: data.res.toAPI(context.ports.authContainer.getTokenOrNull()), - }, - })) - ), - }, -}; diff --git a/packages/server/src/resolvers/topic.ts b/packages/server/src/resolvers/topic.ts deleted file mode 100644 index d02bb03..0000000 --- a/packages/server/src/resolvers/topic.ts +++ /dev/null @@ -1,57 +0,0 @@ -import * as G from "../generated/graphql"; -import { getTopic } from "../usecases"; -import * as O from "fp-ts/Option"; - -export const topic: G.TopicResolvers = { - __resolveType(obj) { - switch (obj.type) { - case "normal": - return "TopicNormal"; - case "one": - return "TopicOne"; - case "fork": - return "TopicFork"; - } - }, - subscribe: async (topic, _args, context, _info) => { - // TODO: N+1 - const token = context.ports.authContainer.getTokenOrNull(); - if (O.isNone(token)) { - return null; - } - return await context.ports.topicRepo.getSubscription( - topic.id, - token.value.user - ); - }, -}; - -export const topicSearch: G.TopicSearchResolvers = { - __resolveType(obj) { - switch (obj.type) { - case "normal": - return "TopicNormal"; - case "one": - return "TopicOne"; - } - }, -}; - -export const topicFork: G.TopicForkResolvers = { - parent: async (token, _args, context, _info) => { - const parent = await getTopic({ id: token.parentID }, context.ports); - if (parent.type !== "normal") { - throw new Error(); - } - return parent; - }, - subscribe: topic.subscribe, -}; - -export const topicOne: G.TopicOneResolvers = { - subscribe: topic.subscribe, -}; - -export const topicNormal: G.TopicNormalResolvers = { - subscribe: topic.subscribe, -}; diff --git a/packages/server/src/schema/res/resolvers/ResBase.ts b/packages/server/src/schema/res/resolvers/ResBase.ts new file mode 100644 index 0000000..3430b77 --- /dev/null +++ b/packages/server/src/schema/res/resolvers/ResBase.ts @@ -0,0 +1,9 @@ +import { getTopic } from "../../../usecases"; +import type { ResResolvers } from "./../../types.generated"; + +export const ResBase: Omit = { + topic: async (res, _args, context, _info) => { + const topic = await getTopic({ id: res.topicID }, context.ports); + return topic; + }, +}; diff --git a/packages/server/src/schema/res/resolvers/ResDelete.ts b/packages/server/src/schema/res/resolvers/ResDelete.ts index feac80b..336dac0 100644 --- a/packages/server/src/schema/res/resolvers/ResDelete.ts +++ b/packages/server/src/schema/res/resolvers/ResDelete.ts @@ -1,13 +1,6 @@ -import type { ResDeleteResolvers } from './../../types.generated'; - export const ResDelete: ResDeleteResolvers = { - /* Implement ResDelete resolver logic here */ - date: () => { /* ResDelete.date resolver is required because ResDelete.date exists but ResDeleteMapper.date does not */ }, - dv: () => { /* ResDelete.dv resolver is required because ResDelete.dv exists but ResDeleteMapper.dv does not */ }, - hash: () => { /* ResDelete.hash resolver is required because ResDelete.hash exists but ResDeleteMapper.hash does not */ }, - id: () => { /* ResDelete.id resolver is required because ResDelete.id exists but ResDeleteMapper.id does not */ }, - replyCount: () => { /* ResDelete.replyCount resolver is required because ResDelete.replyCount exists but ResDeleteMapper.replyCount does not */ }, - self: () => { /* ResDelete.self resolver is required because ResDelete.self exists but ResDeleteMapper.self does not */ }, - topic: () => { /* ResDelete.topic resolver is required because ResDelete.topic exists but ResDeleteMapper.topic does not */ }, - uv: () => { /* ResDelete.uv resolver is required because ResDelete.uv exists but ResDeleteMapper.uv does not */ }, - voteFlag: () => { /* ResDelete.voteFlag resolver is required because ResDelete.voteFlag exists but ResDeleteMapper.voteFlag does not */ } - }; \ No newline at end of file +import type { ResDeleteResolvers } from "./../../types.generated"; +import { ResBase } from "./ResBase"; + +export const ResDelete: ResDeleteResolvers = { + ...ResBase, +}; diff --git a/packages/server/src/schema/res/resolvers/ResFork.ts b/packages/server/src/schema/res/resolvers/ResFork.ts index d2ec54c..7c2df03 100644 --- a/packages/server/src/schema/res/resolvers/ResFork.ts +++ b/packages/server/src/schema/res/resolvers/ResFork.ts @@ -1,14 +1,14 @@ -import type { ResForkResolvers } from './../../types.generated'; - export const ResFork: ResForkResolvers = { - /* Implement ResFork resolver logic here */ - date: () => { /* ResFork.date resolver is required because ResFork.date exists but ResForkMapper.date does not */ }, - dv: () => { /* ResFork.dv resolver is required because ResFork.dv exists but ResForkMapper.dv does not */ }, - hash: () => { /* ResFork.hash resolver is required because ResFork.hash exists but ResForkMapper.hash does not */ }, - id: () => { /* ResFork.id resolver is required because ResFork.id exists but ResForkMapper.id does not */ }, - replyCount: () => { /* ResFork.replyCount resolver is required because ResFork.replyCount exists but ResForkMapper.replyCount does not */ }, - self: () => { /* ResFork.self resolver is required because ResFork.self exists but ResForkMapper.self does not */ }, - topic: () => { /* ResFork.topic resolver is required because ResFork.topic exists but ResForkMapper.topic does not */ }, - uv: () => { /* ResFork.uv resolver is required because ResFork.uv exists but ResForkMapper.uv does not */ }, - voteFlag: () => { /* ResFork.voteFlag resolver is required because ResFork.voteFlag exists but ResForkMapper.voteFlag does not */ }, - fork: () => { /* ResFork.fork resolver is required because ResFork.fork exists but ResForkMapper.fork does not */ } - }; \ No newline at end of file +import { getTopic } from "../../../usecases"; +import type { ResForkResolvers } from "./../../types.generated"; +import { ResBase } from "./ResBase"; + +export const ResFork: ResForkResolvers = { + ...ResBase, + fork: async (res, _args, context, _info) => { + const fork = await getTopic({ id: res.forkID }, context.ports); + if (fork.type !== "fork") { + throw new Error(); + } + return fork; + }, +}; diff --git a/packages/server/src/schema/res/resolvers/ResHistory.ts b/packages/server/src/schema/res/resolvers/ResHistory.ts index ce82d48..f6e9a33 100644 --- a/packages/server/src/schema/res/resolvers/ResHistory.ts +++ b/packages/server/src/schema/res/resolvers/ResHistory.ts @@ -1,14 +1,11 @@ -import type { ResHistoryResolvers } from './../../types.generated'; - export const ResHistory: ResHistoryResolvers = { - /* Implement ResHistory resolver logic here */ - date: () => { /* ResHistory.date resolver is required because ResHistory.date exists but ResHistoryMapper.date does not */ }, - dv: () => { /* ResHistory.dv resolver is required because ResHistory.dv exists but ResHistoryMapper.dv does not */ }, - hash: () => { /* ResHistory.hash resolver is required because ResHistory.hash exists but ResHistoryMapper.hash does not */ }, - id: () => { /* ResHistory.id resolver is required because ResHistory.id exists but ResHistoryMapper.id does not */ }, - replyCount: () => { /* ResHistory.replyCount resolver is required because ResHistory.replyCount exists but ResHistoryMapper.replyCount does not */ }, - self: () => { /* ResHistory.self resolver is required because ResHistory.self exists but ResHistoryMapper.self does not */ }, - topic: () => { /* ResHistory.topic resolver is required because ResHistory.topic exists but ResHistoryMapper.topic does not */ }, - uv: () => { /* ResHistory.uv resolver is required because ResHistory.uv exists but ResHistoryMapper.uv does not */ }, - voteFlag: () => { /* ResHistory.voteFlag resolver is required because ResHistory.voteFlag exists but ResHistoryMapper.voteFlag does not */ }, - history: () => { /* ResHistory.history resolver is required because ResHistory.history exists but ResHistoryMapper.history does not */ } - }; \ No newline at end of file +import { getHistory } from "../../../usecases"; +import type { ResHistoryResolvers } from "./../../types.generated"; +import { ResBase } from "./ResBase"; + +export const ResHistory: ResHistoryResolvers = { + ...ResBase, + history: async (res, _args, context, _info) => { + const history = await getHistory({ id: res.historyID }, context.ports); + return history; + }, +}; diff --git a/packages/server/src/schema/res/resolvers/ResNormal.ts b/packages/server/src/schema/res/resolvers/ResNormal.ts index 29fa310..2ba862c 100644 --- a/packages/server/src/schema/res/resolvers/ResNormal.ts +++ b/packages/server/src/schema/res/resolvers/ResNormal.ts @@ -1,15 +1,23 @@ -import type { ResNormalResolvers } from './../../types.generated'; - export const ResNormal: ResNormalResolvers = { - /* Implement ResNormal resolver logic here */ - date: () => { /* ResNormal.date resolver is required because ResNormal.date exists but ResNormalMapper.date does not */ }, - dv: () => { /* ResNormal.dv resolver is required because ResNormal.dv exists but ResNormalMapper.dv does not */ }, - hash: () => { /* ResNormal.hash resolver is required because ResNormal.hash exists but ResNormalMapper.hash does not */ }, - id: () => { /* ResNormal.id resolver is required because ResNormal.id exists but ResNormalMapper.id does not */ }, - replyCount: () => { /* ResNormal.replyCount resolver is required because ResNormal.replyCount exists but ResNormalMapper.replyCount does not */ }, - self: () => { /* ResNormal.self resolver is required because ResNormal.self exists but ResNormalMapper.self does not */ }, - topic: () => { /* ResNormal.topic resolver is required because ResNormal.topic exists but ResNormalMapper.topic does not */ }, - uv: () => { /* ResNormal.uv resolver is required because ResNormal.uv exists but ResNormalMapper.uv does not */ }, - voteFlag: () => { /* ResNormal.voteFlag resolver is required because ResNormal.voteFlag exists but ResNormalMapper.voteFlag does not */ }, - profile: () => { /* ResNormal.profile resolver is required because ResNormal.profile exists but ResNormalMapper.profile does not */ }, - reply: () => { /* ResNormal.reply resolver is required because ResNormal.reply exists but ResNormalMapper.reply does not */ } - }; \ No newline at end of file +import { getProfile, getRes } from "../../../usecases"; +import type { ResNormalResolvers } from "./../../types.generated"; +import { ResBase } from "./ResBase"; + +export const ResNormal: ResNormalResolvers = { + ...ResBase, + reply: async (res, _args, context, _info) => { + if (res.replyID !== null) { + const reply = await getRes({ id: res.replyID }, context.ports); + return reply; + } else { + return null; + } + }, + profile: async (res, _args, context, _info) => { + if (res.profileID !== null) { + const profile = await getProfile({ id: res.profileID }, context.ports); + return profile; + } else { + return null; + } + }, +}; diff --git a/packages/server/src/schema/res/resolvers/ResTopic.ts b/packages/server/src/schema/res/resolvers/ResTopic.ts index 22a19cd..be488ea 100644 --- a/packages/server/src/schema/res/resolvers/ResTopic.ts +++ b/packages/server/src/schema/res/resolvers/ResTopic.ts @@ -1,5 +1,6 @@ -import type { ResTopicResolvers } from './../../types.generated'; - export const ResTopic: ResTopicResolvers = { - /* Implement ResTopic resolver logic here */ - topic: () => { /* ResTopic.topic resolver is required because ResTopic.topic exists but ResTopicMapper.topic does not */ } - }; \ No newline at end of file +import type { ResTopicResolvers } from "./../../types.generated"; +import { ResBase } from "./ResBase"; + +export const ResTopic: ResTopicResolvers = { + ...ResBase, +}; diff --git a/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts b/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts index 511b3ae..50f9b34 100644 --- a/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts +++ b/packages/server/src/schema/res/resolvers/Subscription/resAdded.ts @@ -1,4 +1,15 @@ -import type { SubscriptionResolvers } from './../../../types.generated'; - export const resAdded: NonNullable = { - subscribe: async (_parent, _arg, _ctx) => { /* Implement Subscription.resAdded resolver logic here */ }, - } \ No newline at end of file +import type { SubscriptionResolvers } from "./../../../types.generated"; +import * as ixa from "ix/asynciterable"; +import * as ixaOps from "ix/asynciterable/operators"; + +export const resAdded: NonNullable = { + subscribe: (_parent, args, context, _info) => + ixa.from(context.ports.resRepo.subscribeInsertEvent(args.topic)).pipe( + ixaOps.map((data) => ({ + resAdded: { + count: data.count, + res: data.res.toAPI(context.ports.authContainer.getTokenOrNull()), + }, + })) + ), +}; diff --git a/packages/server/src/schema/resolveTypes.ts b/packages/server/src/schema/resolveTypes.ts index ca68854..00a1009 100644 --- a/packages/server/src/schema/resolveTypes.ts +++ b/packages/server/src/schema/resolveTypes.ts @@ -27,4 +27,26 @@ export const resolveTypes: Resolvers = { } }, }, + Topic: { + __resolveType(obj) { + switch (obj.type) { + case "normal": + return "TopicNormal"; + case "one": + return "TopicOne"; + case "fork": + return "TopicFork"; + } + }, + }, + TopicSearch: { + __resolveType(obj) { + switch (obj.type) { + case "normal": + return "TopicNormal"; + case "one": + return "TopicOne"; + } + }, + }, }; diff --git a/packages/server/src/schema/topic/resolvers/TopicBase.ts b/packages/server/src/schema/topic/resolvers/TopicBase.ts new file mode 100644 index 0000000..ef0468f --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/TopicBase.ts @@ -0,0 +1,16 @@ +import type { TopicResolvers } from "./../../types.generated"; +import * as O from "fp-ts/lib/Option"; + +export const TopicBase: Omit = { + subscribe: async (topic, _args, context, _info) => { + // TODO: N+1 + const token = context.ports.authContainer.getTokenOrNull(); + if (O.isNone(token)) { + return null; + } + return await context.ports.topicRepo.getSubscription( + topic.id, + token.value.user + ); + }, +}; diff --git a/packages/server/src/schema/topic/resolvers/TopicFork.ts b/packages/server/src/schema/topic/resolvers/TopicFork.ts index 8563b47..c5d887a 100644 --- a/packages/server/src/schema/topic/resolvers/TopicFork.ts +++ b/packages/server/src/schema/topic/resolvers/TopicFork.ts @@ -1,12 +1,14 @@ -import type { TopicForkResolvers } from './../../types.generated'; - export const TopicFork: TopicForkResolvers = { - /* Implement TopicFork resolver logic here */ - active: () => { /* TopicFork.active resolver is required because TopicFork.active exists but TopicForkMapper.active does not */ }, - date: () => { /* TopicFork.date resolver is required because TopicFork.date exists but TopicForkMapper.date does not */ }, - id: () => { /* TopicFork.id resolver is required because TopicFork.id exists but TopicForkMapper.id does not */ }, - resCount: () => { /* TopicFork.resCount resolver is required because TopicFork.resCount exists but TopicForkMapper.resCount does not */ }, - subscribe: () => { /* TopicFork.subscribe resolver is required because TopicFork.subscribe exists but TopicForkMapper.subscribe does not */ }, - title: () => { /* TopicFork.title resolver is required because TopicFork.title exists but TopicForkMapper.title does not */ }, - update: () => { /* TopicFork.update resolver is required because TopicFork.update exists but TopicForkMapper.update does not */ }, - parent: () => { /* TopicFork.parent resolver is required because TopicFork.parent exists but TopicForkMapper.parent does not */ } - }; \ No newline at end of file +import { getTopic } from "../../../usecases"; +import type { TopicForkResolvers } from "./../../types.generated"; +import { TopicBase } from "./TopicBase"; + +export const TopicFork: TopicForkResolvers = { + ...TopicBase, + parent: async (token, _args, context, _info) => { + const parent = await getTopic({ id: token.parentID }, context.ports); + if (parent.type !== "normal") { + throw new Error(); + } + return parent; + }, +}; diff --git a/packages/server/src/schema/topic/resolvers/TopicNormal.ts b/packages/server/src/schema/topic/resolvers/TopicNormal.ts index 1137325..effd473 100644 --- a/packages/server/src/schema/topic/resolvers/TopicNormal.ts +++ b/packages/server/src/schema/topic/resolvers/TopicNormal.ts @@ -1,5 +1,6 @@ -import type { TopicNormalResolvers } from './../../types.generated'; - export const TopicNormal: TopicNormalResolvers = { - /* Implement TopicNormal resolver logic here */ - subscribe: () => { /* TopicNormal.subscribe resolver is required because TopicNormal.subscribe exists but TopicNormalMapper.subscribe does not */ } - }; \ No newline at end of file +import type { TopicNormalResolvers } from "./../../types.generated"; +import { TopicSearchBase } from "./TopicSearchBase"; + +export const TopicNormal: TopicNormalResolvers = { + ...TopicSearchBase, +}; diff --git a/packages/server/src/schema/topic/resolvers/TopicOne.ts b/packages/server/src/schema/topic/resolvers/TopicOne.ts index 75c02d1..fb24373 100644 --- a/packages/server/src/schema/topic/resolvers/TopicOne.ts +++ b/packages/server/src/schema/topic/resolvers/TopicOne.ts @@ -1,5 +1,6 @@ -import type { TopicOneResolvers } from './../../types.generated'; - export const TopicOne: TopicOneResolvers = { - /* Implement TopicOne resolver logic here */ - subscribe: () => { /* TopicOne.subscribe resolver is required because TopicOne.subscribe exists but TopicOneMapper.subscribe does not */ } - }; \ No newline at end of file +import type { TopicOneResolvers } from "./../../types.generated"; +import { TopicSearchBase } from "./TopicSearchBase"; + +export const TopicOne: TopicOneResolvers = { + ...TopicSearchBase, +}; diff --git a/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts b/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts new file mode 100644 index 0000000..5a8843b --- /dev/null +++ b/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts @@ -0,0 +1,6 @@ +import type { TopicSearchResolvers } from "./../../types.generated"; +import { TopicBase } from "./TopicBase"; + +export const TopicSearchBase: Omit = { + ...TopicBase, +}; From 3bc0e30635c4a9d43edd13ee8fcdc1efcabbb360 Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 21:05:42 +0900 Subject: [PATCH 08/10] fix codegen --- codegen.ts | 3 +++ packages/server/src/schema/base/resolvers/ValidateData.ts | 8 ++++---- packages/server/src/schema/client/resolvers/Client.ts | 8 ++++---- packages/server/src/schema/history/resolvers/History.ts | 2 +- packages/server/src/schema/profile/resolvers/Profile.ts | 8 ++++---- .../server/src/schema/token/resolvers/TokenGeneral.ts | 3 --- packages/server/src/server/auth-from-api-param.ts | 7 +++++-- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/codegen.ts b/codegen.ts index c838aa2..717bda6 100644 --- a/codegen.ts +++ b/codegen.ts @@ -12,5 +12,8 @@ const config: CodegenConfig = { }, }), }, + hooks: { + afterAllFileWrite: ["prettier --write"], + }, }; export default config; diff --git a/packages/server/src/schema/base/resolvers/ValidateData.ts b/packages/server/src/schema/base/resolvers/ValidateData.ts index 6a55a1d..d74fb5f 100644 --- a/packages/server/src/schema/base/resolvers/ValidateData.ts +++ b/packages/server/src/schema/base/resolvers/ValidateData.ts @@ -1,4 +1,4 @@ -import type { ValidateDataResolvers } from './../../types.generated'; - export const ValidateData: ValidateDataResolvers = { - /* Implement ValidateData resolver logic here */ - }; \ No newline at end of file +import type { ValidateDataResolvers } from "./../../types.generated"; +export const ValidateData: ValidateDataResolvers = { + /* Implement ValidateData resolver logic here */ +}; diff --git a/packages/server/src/schema/client/resolvers/Client.ts b/packages/server/src/schema/client/resolvers/Client.ts index 1ef3ed4..096d3f2 100644 --- a/packages/server/src/schema/client/resolvers/Client.ts +++ b/packages/server/src/schema/client/resolvers/Client.ts @@ -1,4 +1,4 @@ -import type { ClientResolvers } from './../../types.generated'; - export const Client: ClientResolvers = { - /* Implement Client resolver logic here */ - }; \ No newline at end of file +import type { ClientResolvers } from "./../../types.generated"; +export const Client: ClientResolvers = { + /* Implement Client resolver logic here */ +}; diff --git a/packages/server/src/schema/history/resolvers/History.ts b/packages/server/src/schema/history/resolvers/History.ts index bd43a2c..0d07089 100644 --- a/packages/server/src/schema/history/resolvers/History.ts +++ b/packages/server/src/schema/history/resolvers/History.ts @@ -8,5 +8,5 @@ export const History: HistoryResolvers = { throw new Error(); } return topic; - } + }, }; diff --git a/packages/server/src/schema/profile/resolvers/Profile.ts b/packages/server/src/schema/profile/resolvers/Profile.ts index 8d50af6..4c05f03 100644 --- a/packages/server/src/schema/profile/resolvers/Profile.ts +++ b/packages/server/src/schema/profile/resolvers/Profile.ts @@ -1,4 +1,4 @@ -import type { ProfileResolvers } from './../../types.generated'; - export const Profile: ProfileResolvers = { - /* Implement Profile resolver logic here */ - }; \ No newline at end of file +import type { ProfileResolvers } from "./../../types.generated"; +export const Profile: ProfileResolvers = { + /* Implement Profile resolver logic here */ +}; diff --git a/packages/server/src/schema/token/resolvers/TokenGeneral.ts b/packages/server/src/schema/token/resolvers/TokenGeneral.ts index 5b49861..1c27775 100644 --- a/packages/server/src/schema/token/resolvers/TokenGeneral.ts +++ b/packages/server/src/schema/token/resolvers/TokenGeneral.ts @@ -4,7 +4,4 @@ export const TokenGeneral: TokenGeneralResolvers = { const client = await context.ports.clientLoader.load(token.clientID); return client.toAPI(context.ports.authContainer.getTokenMasterOrNull()); }, - date: () => { /* TokenGeneral.date resolver is required because TokenGeneral.date exists but TokenGeneralMapper.date does not */ }, - id: () => { /* TokenGeneral.id resolver is required because TokenGeneral.id exists but TokenGeneralMapper.id does not */ }, - key: () => { /* TokenGeneral.key resolver is required because TokenGeneral.key exists but TokenGeneralMapper.key does not */ } }; diff --git a/packages/server/src/server/auth-from-api-param.ts b/packages/server/src/server/auth-from-api-param.ts index da3eda5..5fc2715 100644 --- a/packages/server/src/server/auth-from-api-param.ts +++ b/packages/server/src/server/auth-from-api-param.ts @@ -4,7 +4,6 @@ import { ITokenRepo, IUserRepo } from "../ports"; import { AtAuthError } from "../at-error"; import { isNullish } from "@kgtkr/utils"; -import * as G from "../generated/graphql"; export async function tokenHeaderToToken( tokenRepo: ITokenRepo, @@ -18,7 +17,11 @@ export async function tokenHeaderToToken( export async function authUserRequestToUser( userRepo: IUserRepo, - apiParamUser: G.AuthUser + apiParamUser: { + id?: string | null; + pass: string; + sn?: string | null; + } ): Promise { let id; if (!isNullish(apiParamUser.id) && isNullish(apiParamUser.sn)) { From 9c321664f0ff8649fc0a06cb5402c6c4c9b3f470 Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 21:17:58 +0900 Subject: [PATCH 09/10] =?UTF-8?q?codegen=E3=81=97=E3=81=A6=E3=82=82diff?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=97=E3=81=AA=E3=81=84=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/entities/res/res.ts | 52 ++++++++++--------- packages/server/src/entities/token/token.ts | 25 +++++---- packages/server/src/entities/topic/topic.ts | 36 +++++++------ .../src/schema/res/resolvers/ResDelete.ts | 4 +- .../src/schema/res/resolvers/ResFork.ts | 4 +- .../src/schema/res/resolvers/ResHistory.ts | 4 +- .../src/schema/res/resolvers/ResNormal.ts | 4 +- .../src/schema/res/resolvers/ResSubscript.ts | 16 +++--- .../src/schema/res/resolvers/ResTopic.ts | 4 +- .../res/resolvers/{ResBase.ts => base_Res.ts} | 2 +- .../storage/resolvers/SetStoragesPayload.ts | 8 +-- .../src/schema/storage/resolvers/Storage.ts | 8 +-- .../resolvers/CreateTokenGeneralResponse.ts | 3 +- .../token/resolvers/Mutation/authTokenReq.ts | 4 +- .../src/schema/token/resolvers/Query/token.ts | 2 +- .../schema/token/resolvers/Query/tokens.ts | 2 +- .../src/schema/token/resolvers/TokenMaster.ts | 3 +- .../src/schema/token/resolvers/TokenReq.ts | 3 +- .../server/src/schema/topic/resolvers/Tags.ts | 8 +-- .../src/schema/topic/resolvers/TopicFork.ts | 4 +- .../src/schema/topic/resolvers/TopicNormal.ts | 4 +- .../src/schema/topic/resolvers/TopicOne.ts | 4 +- .../schema/topic/resolvers/TopicSearchBase.ts | 6 --- .../resolvers/{TopicBase.ts => base_Topic.ts} | 2 +- .../user/resolvers/CreateUserResponse.ts | 8 +-- .../user/resolvers/UpdateUserResponse.ts | 8 +-- .../server/src/schema/user/resolvers/User.ts | 8 +-- 27 files changed, 120 insertions(+), 116 deletions(-) rename packages/server/src/schema/res/resolvers/{ResBase.ts => base_Res.ts} (79%) delete mode 100644 packages/server/src/schema/topic/resolvers/TopicSearchBase.ts rename packages/server/src/schema/topic/resolvers/{TopicBase.ts => base_Topic.ts} (84%) diff --git a/packages/server/src/entities/res/res.ts b/packages/server/src/entities/res/res.ts index 3977f64..d513455 100644 --- a/packages/server/src/entities/res/res.ts +++ b/packages/server/src/entities/res/res.ts @@ -41,41 +41,45 @@ export type IResAPI = | IResForkAPI | IResDeleteAPI; -export interface IResBaseAPI { - readonly id: string; - readonly topicID: string; - readonly date: Date; - readonly self: boolean | null; - readonly uv: number; - readonly dv: number; - readonly hash: string; - readonly replyCount: number; - readonly voteFlag: VoteFlag | null; - readonly type: T; +// -- +// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う +export class IResBaseAPI { + readonly id!: string; + readonly topicID!: string; + readonly date!: Date; + readonly self!: boolean | null; + readonly uv!: number; + readonly dv!: number; + readonly hash!: string; + readonly replyCount!: number; + readonly voteFlag!: VoteFlag | null; + readonly type!: T; } -export interface IResNormalAPI extends IResBaseAPI<"normal"> { - readonly name: string | null; - readonly text: string; - readonly replyID: string | null; - readonly profileID: string | null; - readonly isReply: boolean | null; +export class IResNormalAPI extends IResBaseAPI<"normal"> { + readonly name!: string | null; + readonly text!: string; + readonly replyID!: string | null; + readonly profileID!: string | null; + readonly isReply!: boolean | null; } -export interface IResHistoryAPI extends IResBaseAPI<"history"> { - readonly historyID: string; +export class IResHistoryAPI extends IResBaseAPI<"history"> { + readonly historyID!: string; } -export type IResTopicAPI = IResBaseAPI<"topic">; +export class IResTopicAPI extends IResBaseAPI<"topic"> {} -export interface IResForkAPI extends IResBaseAPI<"fork"> { - readonly forkID: string; +export class IResForkAPI extends IResBaseAPI<"fork"> { + readonly forkID!: string; } -export interface IResDeleteAPI extends IResBaseAPI<"delete"> { - readonly flag: "self" | "freeze"; +export class IResDeleteAPI extends IResBaseAPI<"delete"> { + readonly flag!: "self" | "freeze"; } +// -- + export type VoteFlag = "uv" | "dv" | "not"; export type ResDeleteFlag = "active" | "self" | "freeze"; export interface IReply { diff --git a/packages/server/src/entities/token/token.ts b/packages/server/src/entities/token/token.ts index 3309582..661831e 100644 --- a/packages/server/src/entities/token/token.ts +++ b/packages/server/src/entities/token/token.ts @@ -13,27 +13,30 @@ export interface ITokenReq { readonly active: boolean; } -export interface ITokenReqAPI { - readonly token: string; - readonly key: string; +export class ITokenReqAPI { + readonly token!: string; + readonly key!: string; } export type TokenType = "master" | "general"; export type ITokenAPI = ITokenGeneralAPI | ITokenMasterAPI; -export interface ITokenBaseAPI { - readonly id: string; - readonly key: string; - readonly date: string; - readonly type: T; +// -- +// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う +export class ITokenBaseAPI { + readonly id!: string; + readonly key!: string; + readonly date!: string; + readonly type!: T; } -export type ITokenMasterAPI = ITokenBaseAPI<"master">; +export class ITokenMasterAPI extends ITokenBaseAPI<"master"> {} -export interface ITokenGeneralAPI extends ITokenBaseAPI<"general"> { - readonly clientID: string; +export class ITokenGeneralAPI extends ITokenBaseAPI<"general"> { + readonly clientID!: string; } +// -- export type Token = TokenMaster | TokenGeneral; diff --git a/packages/server/src/entities/topic/topic.ts b/packages/server/src/entities/topic/topic.ts index da73a94..b65ec2c 100644 --- a/packages/server/src/entities/topic/topic.ts +++ b/packages/server/src/entities/topic/topic.ts @@ -18,29 +18,33 @@ export interface ITagsAPI { export type ITopicAPI = ITopicOneAPI | ITopicNormalAPI | ITopicForkAPI; export type ITopicSearchAPI = ITopicOneAPI | ITopicNormalAPI; -export interface ITopicBaseAPI { - readonly id: string; - readonly title: string; - readonly update: string; - readonly date: string; - readonly resCount: number; - readonly type: T; - readonly active: boolean; +// -- +// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う +export class ITopicBaseAPI { + readonly id!: string; + readonly title!: string; + readonly update!: string; + readonly date!: string; + readonly resCount!: number; + readonly type!: T; + readonly active!: boolean; } -export interface ITopicSearchBaseAPI - extends ITopicBaseAPI { - readonly tags: Array; - readonly text: string; +export class ITopicSearchBaseAPI< + T extends TopicSearchType +> extends ITopicBaseAPI { + readonly tags!: Array; + readonly text!: string; } -export type ITopicNormalAPI = ITopicSearchBaseAPI<"normal">; +export class ITopicNormalAPI extends ITopicSearchBaseAPI<"normal"> {} -export type ITopicOneAPI = ITopicSearchBaseAPI<"one">; +export class ITopicOneAPI extends ITopicSearchBaseAPI<"one"> {} -export interface ITopicForkAPI extends ITopicBaseAPI<"fork"> { - readonly parentID: string; +export class ITopicForkAPI extends ITopicBaseAPI<"fork"> { + readonly parentID!: string; } +// -- export type TopicSearchType = "one" | "normal"; export type TopicType = TopicSearchType | "fork"; diff --git a/packages/server/src/schema/res/resolvers/ResDelete.ts b/packages/server/src/schema/res/resolvers/ResDelete.ts index 336dac0..ba72923 100644 --- a/packages/server/src/schema/res/resolvers/ResDelete.ts +++ b/packages/server/src/schema/res/resolvers/ResDelete.ts @@ -1,6 +1,6 @@ import type { ResDeleteResolvers } from "./../../types.generated"; -import { ResBase } from "./ResBase"; +import { base_Res } from "./base_Res"; export const ResDelete: ResDeleteResolvers = { - ...ResBase, + topic: base_Res.topic, }; diff --git a/packages/server/src/schema/res/resolvers/ResFork.ts b/packages/server/src/schema/res/resolvers/ResFork.ts index 7c2df03..cf9ddf7 100644 --- a/packages/server/src/schema/res/resolvers/ResFork.ts +++ b/packages/server/src/schema/res/resolvers/ResFork.ts @@ -1,9 +1,9 @@ import { getTopic } from "../../../usecases"; import type { ResForkResolvers } from "./../../types.generated"; -import { ResBase } from "./ResBase"; +import { base_Res } from "./base_Res"; export const ResFork: ResForkResolvers = { - ...ResBase, + topic: base_Res.topic, fork: async (res, _args, context, _info) => { const fork = await getTopic({ id: res.forkID }, context.ports); if (fork.type !== "fork") { diff --git a/packages/server/src/schema/res/resolvers/ResHistory.ts b/packages/server/src/schema/res/resolvers/ResHistory.ts index f6e9a33..39fcaf9 100644 --- a/packages/server/src/schema/res/resolvers/ResHistory.ts +++ b/packages/server/src/schema/res/resolvers/ResHistory.ts @@ -1,9 +1,9 @@ import { getHistory } from "../../../usecases"; import type { ResHistoryResolvers } from "./../../types.generated"; -import { ResBase } from "./ResBase"; +import { base_Res } from "./base_Res"; export const ResHistory: ResHistoryResolvers = { - ...ResBase, + topic: base_Res.topic, history: async (res, _args, context, _info) => { const history = await getHistory({ id: res.historyID }, context.ports); return history; diff --git a/packages/server/src/schema/res/resolvers/ResNormal.ts b/packages/server/src/schema/res/resolvers/ResNormal.ts index 2ba862c..c2453e6 100644 --- a/packages/server/src/schema/res/resolvers/ResNormal.ts +++ b/packages/server/src/schema/res/resolvers/ResNormal.ts @@ -1,9 +1,9 @@ import { getProfile, getRes } from "../../../usecases"; import type { ResNormalResolvers } from "./../../types.generated"; -import { ResBase } from "./ResBase"; +import { base_Res } from "./base_Res"; export const ResNormal: ResNormalResolvers = { - ...ResBase, + topic: base_Res.topic, reply: async (res, _args, context, _info) => { if (res.replyID !== null) { const reply = await getRes({ id: res.replyID }, context.ports); diff --git a/packages/server/src/schema/res/resolvers/ResSubscript.ts b/packages/server/src/schema/res/resolvers/ResSubscript.ts index 585bf2c..e9858a2 100644 --- a/packages/server/src/schema/res/resolvers/ResSubscript.ts +++ b/packages/server/src/schema/res/resolvers/ResSubscript.ts @@ -1,8 +1,8 @@ -import type { ResSubscriptResolvers } from './../../types.generated'; - export const ResSubscript: ResSubscriptResolvers = { - /* Implement ResSubscript resolver logic here */ - res: ({ res }) => { - /* ResSubscript.res resolver is required because ResSubscript.res and ResSubscriptMapper.res are not compatible */ - return res - } - }; \ No newline at end of file +import type { ResSubscriptResolvers } from "./../../types.generated"; +export const ResSubscript: ResSubscriptResolvers = { + /* Implement ResSubscript resolver logic here */ + res: ({ res }) => { + /* ResSubscript.res resolver is required because ResSubscript.res and ResSubscriptMapper.res are not compatible */ + return res; + }, +}; diff --git a/packages/server/src/schema/res/resolvers/ResTopic.ts b/packages/server/src/schema/res/resolvers/ResTopic.ts index be488ea..40d7e04 100644 --- a/packages/server/src/schema/res/resolvers/ResTopic.ts +++ b/packages/server/src/schema/res/resolvers/ResTopic.ts @@ -1,6 +1,6 @@ import type { ResTopicResolvers } from "./../../types.generated"; -import { ResBase } from "./ResBase"; +import { base_Res } from "./base_Res"; export const ResTopic: ResTopicResolvers = { - ...ResBase, + topic: base_Res.topic, }; diff --git a/packages/server/src/schema/res/resolvers/ResBase.ts b/packages/server/src/schema/res/resolvers/base_Res.ts similarity index 79% rename from packages/server/src/schema/res/resolvers/ResBase.ts rename to packages/server/src/schema/res/resolvers/base_Res.ts index 3430b77..27f5248 100644 --- a/packages/server/src/schema/res/resolvers/ResBase.ts +++ b/packages/server/src/schema/res/resolvers/base_Res.ts @@ -1,7 +1,7 @@ import { getTopic } from "../../../usecases"; import type { ResResolvers } from "./../../types.generated"; -export const ResBase: Omit = { +export const base_Res: Required> = { topic: async (res, _args, context, _info) => { const topic = await getTopic({ id: res.topicID }, context.ports); return topic; diff --git a/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts b/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts index b680e60..69d53cd 100644 --- a/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts +++ b/packages/server/src/schema/storage/resolvers/SetStoragesPayload.ts @@ -1,4 +1,4 @@ -import type { SetStoragesPayloadResolvers } from './../../types.generated'; - export const SetStoragesPayload: SetStoragesPayloadResolvers = { - /* Implement SetStoragesPayload resolver logic here */ - }; \ No newline at end of file +import type { SetStoragesPayloadResolvers } from "./../../types.generated"; +export const SetStoragesPayload: SetStoragesPayloadResolvers = { + /* Implement SetStoragesPayload resolver logic here */ +}; diff --git a/packages/server/src/schema/storage/resolvers/Storage.ts b/packages/server/src/schema/storage/resolvers/Storage.ts index 7951510..c493df7 100644 --- a/packages/server/src/schema/storage/resolvers/Storage.ts +++ b/packages/server/src/schema/storage/resolvers/Storage.ts @@ -1,4 +1,4 @@ -import type { StorageResolvers } from './../../types.generated'; - export const Storage: StorageResolvers = { - /* Implement Storage resolver logic here */ - }; \ No newline at end of file +import type { StorageResolvers } from "./../../types.generated"; +export const Storage: StorageResolvers = { + /* Implement Storage resolver logic here */ +}; diff --git a/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts index fcab606..553bb07 100644 --- a/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts +++ b/packages/server/src/schema/token/resolvers/CreateTokenGeneralResponse.ts @@ -1,4 +1,3 @@ import type { CreateTokenGeneralResponseResolvers } from "./../../types.generated"; export const CreateTokenGeneralResponse: CreateTokenGeneralResponseResolvers = - { -}; + {}; diff --git a/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts index d1b8c0b..2ce530b 100644 --- a/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts +++ b/packages/server/src/schema/token/resolvers/Mutation/authTokenReq.ts @@ -1,7 +1,9 @@ import { AtNotFoundError } from "../../../../at-error"; import type { MutationResolvers } from "./../../../types.generated"; -export const authTokenReq: NonNullable = async (_obj, args, context, _info) => { +export const authTokenReq: NonNullable< + MutationResolvers["authTokenReq"] +> = async (_obj, args, context, _info) => { const token = await context.ports.tokenRepo.findOne(args.id); if (token.type !== "general") { throw new AtNotFoundError("トークンが見つかりません"); diff --git a/packages/server/src/schema/token/resolvers/Query/token.ts b/packages/server/src/schema/token/resolvers/Query/token.ts index c30ce90..5c25ca1 100644 --- a/packages/server/src/schema/token/resolvers/Query/token.ts +++ b/packages/server/src/schema/token/resolvers/Query/token.ts @@ -1,5 +1,5 @@ import type { QueryResolvers } from "./../../../types.generated"; -export const token: NonNullable = async ( +export const token: NonNullable = async ( _obj, _args, context, diff --git a/packages/server/src/schema/token/resolvers/Query/tokens.ts b/packages/server/src/schema/token/resolvers/Query/tokens.ts index a9571cf..892c708 100644 --- a/packages/server/src/schema/token/resolvers/Query/tokens.ts +++ b/packages/server/src/schema/token/resolvers/Query/tokens.ts @@ -1,5 +1,5 @@ import type { QueryResolvers } from "./../../../types.generated"; -export const tokens: NonNullable = async ( +export const tokens: NonNullable = async ( _obj, _args, context, diff --git a/packages/server/src/schema/token/resolvers/TokenMaster.ts b/packages/server/src/schema/token/resolvers/TokenMaster.ts index bd32e8f..c4991d6 100644 --- a/packages/server/src/schema/token/resolvers/TokenMaster.ts +++ b/packages/server/src/schema/token/resolvers/TokenMaster.ts @@ -1,3 +1,2 @@ import type { TokenMasterResolvers } from "./../../types.generated"; -export const TokenMaster: TokenMasterResolvers = { -}; +export const TokenMaster: TokenMasterResolvers = {}; diff --git a/packages/server/src/schema/token/resolvers/TokenReq.ts b/packages/server/src/schema/token/resolvers/TokenReq.ts index 2370c55..3c12da7 100644 --- a/packages/server/src/schema/token/resolvers/TokenReq.ts +++ b/packages/server/src/schema/token/resolvers/TokenReq.ts @@ -1,3 +1,2 @@ import type { TokenReqResolvers } from "./../../types.generated"; -export const TokenReq: TokenReqResolvers = { -}; +export const TokenReq: TokenReqResolvers = {}; diff --git a/packages/server/src/schema/topic/resolvers/Tags.ts b/packages/server/src/schema/topic/resolvers/Tags.ts index eec1dd7..28a767f 100644 --- a/packages/server/src/schema/topic/resolvers/Tags.ts +++ b/packages/server/src/schema/topic/resolvers/Tags.ts @@ -1,4 +1,4 @@ -import type { TagsResolvers } from './../../types.generated'; - export const Tags: TagsResolvers = { - /* Implement Tags resolver logic here */ - }; \ No newline at end of file +import type { TagsResolvers } from "./../../types.generated"; +export const Tags: TagsResolvers = { + /* Implement Tags resolver logic here */ +}; diff --git a/packages/server/src/schema/topic/resolvers/TopicFork.ts b/packages/server/src/schema/topic/resolvers/TopicFork.ts index c5d887a..03cd38e 100644 --- a/packages/server/src/schema/topic/resolvers/TopicFork.ts +++ b/packages/server/src/schema/topic/resolvers/TopicFork.ts @@ -1,9 +1,9 @@ import { getTopic } from "../../../usecases"; import type { TopicForkResolvers } from "./../../types.generated"; -import { TopicBase } from "./TopicBase"; +import { base_Topic } from "./base_Topic"; export const TopicFork: TopicForkResolvers = { - ...TopicBase, + subscribe: base_Topic.subscribe, parent: async (token, _args, context, _info) => { const parent = await getTopic({ id: token.parentID }, context.ports); if (parent.type !== "normal") { diff --git a/packages/server/src/schema/topic/resolvers/TopicNormal.ts b/packages/server/src/schema/topic/resolvers/TopicNormal.ts index effd473..55d3853 100644 --- a/packages/server/src/schema/topic/resolvers/TopicNormal.ts +++ b/packages/server/src/schema/topic/resolvers/TopicNormal.ts @@ -1,6 +1,6 @@ import type { TopicNormalResolvers } from "./../../types.generated"; -import { TopicSearchBase } from "./TopicSearchBase"; +import { base_Topic } from "./base_Topic"; export const TopicNormal: TopicNormalResolvers = { - ...TopicSearchBase, + subscribe: base_Topic.subscribe, }; diff --git a/packages/server/src/schema/topic/resolvers/TopicOne.ts b/packages/server/src/schema/topic/resolvers/TopicOne.ts index fb24373..78cb204 100644 --- a/packages/server/src/schema/topic/resolvers/TopicOne.ts +++ b/packages/server/src/schema/topic/resolvers/TopicOne.ts @@ -1,6 +1,6 @@ import type { TopicOneResolvers } from "./../../types.generated"; -import { TopicSearchBase } from "./TopicSearchBase"; +import { base_Topic } from "./base_Topic"; export const TopicOne: TopicOneResolvers = { - ...TopicSearchBase, + subscribe: base_Topic.subscribe, }; diff --git a/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts b/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts deleted file mode 100644 index 5a8843b..0000000 --- a/packages/server/src/schema/topic/resolvers/TopicSearchBase.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { TopicSearchResolvers } from "./../../types.generated"; -import { TopicBase } from "./TopicBase"; - -export const TopicSearchBase: Omit = { - ...TopicBase, -}; diff --git a/packages/server/src/schema/topic/resolvers/TopicBase.ts b/packages/server/src/schema/topic/resolvers/base_Topic.ts similarity index 84% rename from packages/server/src/schema/topic/resolvers/TopicBase.ts rename to packages/server/src/schema/topic/resolvers/base_Topic.ts index ef0468f..4539692 100644 --- a/packages/server/src/schema/topic/resolvers/TopicBase.ts +++ b/packages/server/src/schema/topic/resolvers/base_Topic.ts @@ -1,7 +1,7 @@ import type { TopicResolvers } from "./../../types.generated"; import * as O from "fp-ts/lib/Option"; -export const TopicBase: Omit = { +export const base_Topic: Required> = { subscribe: async (topic, _args, context, _info) => { // TODO: N+1 const token = context.ports.authContainer.getTokenOrNull(); diff --git a/packages/server/src/schema/user/resolvers/CreateUserResponse.ts b/packages/server/src/schema/user/resolvers/CreateUserResponse.ts index 669116e..c299d35 100644 --- a/packages/server/src/schema/user/resolvers/CreateUserResponse.ts +++ b/packages/server/src/schema/user/resolvers/CreateUserResponse.ts @@ -1,4 +1,4 @@ -import type { CreateUserResponseResolvers } from './../../types.generated'; - export const CreateUserResponse: CreateUserResponseResolvers = { - /* Implement CreateUserResponse resolver logic here */ - }; \ No newline at end of file +import type { CreateUserResponseResolvers } from "./../../types.generated"; +export const CreateUserResponse: CreateUserResponseResolvers = { + /* Implement CreateUserResponse resolver logic here */ +}; diff --git a/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts b/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts index d0644e5..5c505d0 100644 --- a/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts +++ b/packages/server/src/schema/user/resolvers/UpdateUserResponse.ts @@ -1,4 +1,4 @@ -import type { UpdateUserResponseResolvers } from './../../types.generated'; - export const UpdateUserResponse: UpdateUserResponseResolvers = { - /* Implement UpdateUserResponse resolver logic here */ - }; \ No newline at end of file +import type { UpdateUserResponseResolvers } from "./../../types.generated"; +export const UpdateUserResponse: UpdateUserResponseResolvers = { + /* Implement UpdateUserResponse resolver logic here */ +}; diff --git a/packages/server/src/schema/user/resolvers/User.ts b/packages/server/src/schema/user/resolvers/User.ts index 56ad1ab..7eac6d5 100644 --- a/packages/server/src/schema/user/resolvers/User.ts +++ b/packages/server/src/schema/user/resolvers/User.ts @@ -1,4 +1,4 @@ -import type { UserResolvers } from './../../types.generated'; - export const User: UserResolvers = { - /* Implement User resolver logic here */ - }; \ No newline at end of file +import type { UserResolvers } from "./../../types.generated"; +export const User: UserResolvers = { + /* Implement User resolver logic here */ +}; From ffc8e6de87b0ef7efc7d182f6e60a74aa8ec2d4d Mon Sep 17 00:00:00 2001 From: kgtkr Date: Wed, 17 Jan 2024 22:00:17 +0900 Subject: [PATCH 10/10] move codegen.ts --- codegen.ts => packages/server/codegen.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codegen.ts => packages/server/codegen.ts (100%) diff --git a/codegen.ts b/packages/server/codegen.ts similarity index 100% rename from codegen.ts rename to packages/server/codegen.ts