@commitspark/graphql-api 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +42 -7
- package/dist/cjs/graphql/errors.js +1 -11
- package/dist/cjs/graphql/errors.js.map +1 -1
- package/dist/cjs/graphql/resolvers/field-resolvers/entry-reference-resolver.js +1 -1
- package/dist/cjs/graphql/resolvers/field-resolvers/entry-reference-resolver.js.map +1 -1
- package/dist/cjs/graphql/resolvers/field-resolvers/field-default-value-resolver.js +3 -3
- package/dist/cjs/graphql/resolvers/field-resolvers/field-default-value-resolver.js.map +1 -1
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-create-resolver.js +3 -3
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-create-resolver.js.map +1 -1
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-delete-resolver.js +2 -2
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-delete-resolver.js.map +1 -1
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-update-resolver.js +1 -1
- package/dist/cjs/graphql/resolvers/query-mutation-resolvers/mutation-update-resolver.js.map +1 -1
- package/dist/cjs/graphql/schema-generator.js +1 -1
- package/dist/cjs/graphql/schema-generator.js.map +1 -1
- package/dist/cjs/graphql/schema-utils/entry-reference-util.js +5 -5
- package/dist/cjs/graphql/schema-utils/entry-reference-util.js.map +1 -1
- package/dist/cjs/graphql/schema-utils/union-type-util.js +2 -2
- package/dist/cjs/graphql/schema-utils/union-type-util.js.map +1 -1
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/persistence/persistence.js +34 -13
- package/dist/cjs/persistence/persistence.js.map +1 -1
- package/dist/esm/graphql/errors.js +0 -10
- package/dist/esm/graphql/errors.js.map +1 -1
- package/dist/esm/graphql/resolvers/field-resolvers/entry-reference-resolver.js +2 -2
- package/dist/esm/graphql/resolvers/field-resolvers/entry-reference-resolver.js.map +1 -1
- package/dist/esm/graphql/resolvers/field-resolvers/field-default-value-resolver.js +4 -4
- package/dist/esm/graphql/resolvers/field-resolvers/field-default-value-resolver.js.map +1 -1
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-create-resolver.js +4 -4
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-create-resolver.js.map +1 -1
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-delete-resolver.js +3 -3
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-delete-resolver.js.map +1 -1
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-update-resolver.js +2 -2
- package/dist/esm/graphql/resolvers/query-mutation-resolvers/mutation-update-resolver.js.map +1 -1
- package/dist/esm/graphql/schema-generator.js +2 -2
- package/dist/esm/graphql/schema-generator.js.map +1 -1
- package/dist/esm/graphql/schema-utils/entry-reference-util.js +6 -6
- package/dist/esm/graphql/schema-utils/entry-reference-util.js.map +1 -1
- package/dist/esm/graphql/schema-utils/union-type-util.js +3 -3
- package/dist/esm/graphql/schema-utils/union-type-util.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/persistence/persistence.js +35 -14
- package/dist/esm/persistence/persistence.js.map +1 -1
- package/dist/tsconfig.build.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.build.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.build.types.tsbuildinfo +1 -1
- package/dist/types/graphql/errors.d.ts +3 -2
- package/dist/types/graphql/errors.d.ts.map +1 -1
- package/dist/types/persistence/persistence.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/graphql/errors.ts +3 -2
- package/src/persistence/persistence.ts +32 -15
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"gitops",
|
|
10
10
|
"api"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.4",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"private": false,
|
|
15
15
|
"files": [
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"prepublishOnly": "npm run build"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@apollo/server": "
|
|
46
|
-
"@commitspark/git-adapter": "^0.
|
|
45
|
+
"@apollo/server": "~5.0.0",
|
|
46
|
+
"@commitspark/git-adapter": "^0.20.0",
|
|
47
47
|
"@graphql-tools/schema": "^9.0.0",
|
|
48
48
|
"@graphql-tools/utils": "^9.0.0"
|
|
49
49
|
},
|
package/src/graphql/errors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GraphQLError } from 'graphql'
|
|
2
|
+
import { ErrorCode as AdapterErrorCode } from '@commitspark/git-adapter'
|
|
2
3
|
|
|
3
|
-
export enum ErrorCode {
|
|
4
|
+
export const enum ErrorCode {
|
|
4
5
|
BAD_USER_INPUT = 'BAD_USER_INPUT',
|
|
5
6
|
NOT_FOUND = 'NOT_FOUND',
|
|
6
7
|
BAD_REPOSITORY_DATA = 'BAD_REPOSITORY_DATA',
|
|
@@ -21,7 +22,7 @@ export interface ErrorMetadata {
|
|
|
21
22
|
|
|
22
23
|
export const createError = (
|
|
23
24
|
message: string,
|
|
24
|
-
code: ErrorCode,
|
|
25
|
+
code: ErrorCode | AdapterErrorCode,
|
|
25
26
|
metaData: ErrorMetadata,
|
|
26
27
|
): GraphQLError => {
|
|
27
28
|
const serializedFieldValue =
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entry, GitAdapter } from '@commitspark/git-adapter'
|
|
1
|
+
import { Entry, GitAdapter, GitAdapterError } from '@commitspark/git-adapter'
|
|
2
2
|
import { createError, ErrorCode } from '../graphql/errors'
|
|
3
3
|
|
|
4
4
|
export async function getTypeById(
|
|
@@ -6,15 +6,7 @@ export async function getTypeById(
|
|
|
6
6
|
commitHash: string,
|
|
7
7
|
id: string,
|
|
8
8
|
): Promise<string> {
|
|
9
|
-
const
|
|
10
|
-
const requestedEntry = allEntries.find((entry: Entry) => entry.id === id)
|
|
11
|
-
if (requestedEntry === undefined) {
|
|
12
|
-
throw createError(`No entry with id "${id}" exists.`, ErrorCode.NOT_FOUND, {
|
|
13
|
-
argumentName: 'id',
|
|
14
|
-
argumentValue: id,
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
9
|
+
const requestedEntry = await findById(gitAdapter, commitHash, id)
|
|
18
10
|
return requestedEntry.metadata.type
|
|
19
11
|
}
|
|
20
12
|
|
|
@@ -23,10 +15,18 @@ export async function findById(
|
|
|
23
15
|
commitHash: string,
|
|
24
16
|
id: string,
|
|
25
17
|
): Promise<Entry> {
|
|
26
|
-
|
|
18
|
+
let allEntries: Entry[]
|
|
19
|
+
try {
|
|
20
|
+
allEntries = await gitAdapter.getEntries(commitHash)
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (err instanceof GitAdapterError) {
|
|
23
|
+
throw createError(err.message, err.code, {})
|
|
24
|
+
}
|
|
25
|
+
throw err
|
|
26
|
+
}
|
|
27
27
|
const requestedEntry = allEntries.find((entry: Entry) => entry.id === id)
|
|
28
28
|
if (requestedEntry === undefined) {
|
|
29
|
-
throw createError(`No entry with
|
|
29
|
+
throw createError(`No entry with ID "${id}" exists.`, ErrorCode.NOT_FOUND, {
|
|
30
30
|
argumentName: 'id',
|
|
31
31
|
argumentValue: id,
|
|
32
32
|
})
|
|
@@ -40,7 +40,16 @@ export async function findByType(
|
|
|
40
40
|
commitHash: string,
|
|
41
41
|
type: string,
|
|
42
42
|
): Promise<Entry[]> {
|
|
43
|
-
|
|
43
|
+
let allEntries: Entry[]
|
|
44
|
+
try {
|
|
45
|
+
allEntries = await gitAdapter.getEntries(commitHash)
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (err instanceof GitAdapterError) {
|
|
48
|
+
throw createError(err.message, err.code, {})
|
|
49
|
+
}
|
|
50
|
+
throw err
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
return allEntries.filter((entry: Entry) => entry.metadata.type === type)
|
|
45
54
|
}
|
|
46
55
|
|
|
@@ -50,13 +59,21 @@ export async function findByTypeId(
|
|
|
50
59
|
type: string,
|
|
51
60
|
id: string,
|
|
52
61
|
): Promise<Entry> {
|
|
53
|
-
|
|
62
|
+
let allEntries: Entry[]
|
|
63
|
+
try {
|
|
64
|
+
allEntries = await gitAdapter.getEntries(commitHash)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (err instanceof GitAdapterError) {
|
|
67
|
+
throw createError(err.message, err.code, {})
|
|
68
|
+
}
|
|
69
|
+
throw err
|
|
70
|
+
}
|
|
54
71
|
const requestedEntry = allEntries.find(
|
|
55
72
|
(entry: Entry) => entry.id === id && entry.metadata.type === type,
|
|
56
73
|
)
|
|
57
74
|
if (requestedEntry === undefined) {
|
|
58
75
|
throw createError(
|
|
59
|
-
`No entry of type "${type}" with
|
|
76
|
+
`No entry of type "${type}" with ID "${id}" exists.`,
|
|
60
77
|
ErrorCode.NOT_FOUND,
|
|
61
78
|
{
|
|
62
79
|
typeName: type,
|