Skip to content

Commit 650ce97

Browse files
committed
first commit
0 parents  commit 650ce97

30 files changed

+14115
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pnpm-lock.yaml
2+
.DS_Store
3+
node_modules

bin/codegen.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# Schema
4+
rm -f ./schema.json ./schema.graphql && curl https://core-api.uk.plain.com/graphql/v1/schema.graphql -s > schema.graphql
5+
6+
# GraphQL Types
7+
graphql-codegen

codegen.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
schema: './schema.graphql'
2+
documents: './graphql/**/*.gql'
3+
generates:
4+
./graphql/types.ts:
5+
plugins:
6+
- typescript
7+
- typescript-operations
8+
- typed-document-node
9+
config:
10+
nonOptionalTypename: true
11+
dedupeFragments: true
12+
arrayInputCoercion: false
13+
avoidOptionals: true

graphql/error.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { PlainGraphQLError } from './utilities';
2+
import type { MutationErrorPartsFragment } from './types';
3+
4+
/* 400 */
5+
export type BadRequestError = {
6+
type: 'bad_request';
7+
message: string;
8+
graphqlErrors: PlainGraphQLError[];
9+
requestId?: string;
10+
};
11+
12+
/* 401 */
13+
export type ForbiddenError = {
14+
type: 'forbidden';
15+
message: string;
16+
requestId?: string;
17+
};
18+
19+
/* 500 */
20+
export type InternalServerError = {
21+
type: 'internal_server_error';
22+
message: string;
23+
requestId?: string;
24+
};
25+
26+
/* Unhandled/unexpected errors */
27+
export type UnknownError = {
28+
type: 'unknown';
29+
message: string;
30+
err?: unknown;
31+
requestId?: string;
32+
};
33+
34+
/* Handled mutation errors */
35+
export type MutationError = {
36+
type: 'mutation_error';
37+
message: string;
38+
errorDetails: MutationErrorPartsFragment;
39+
requestId?: string;
40+
};
41+
42+
export type PlainError =
43+
| ForbiddenError
44+
| BadRequestError
45+
| InternalServerError
46+
| MutationError
47+
| UnknownError;

graphql/fragments/actorParts.gql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fragment ActorParts on Actor {
2+
__typename
3+
... on UserActor {
4+
...UserActorParts
5+
}
6+
... on SystemActor {
7+
...SystemActorParts
8+
}
9+
... on MachineUserActor {
10+
...MachineUserActorParts
11+
}
12+
... on DeletedCustomerActor {
13+
...DeletedCustomerActorParts
14+
}
15+
... on CustomerActor {
16+
...CustomerActorParts
17+
}
18+
}

graphql/fragments/companyParts.gql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fragment CompanyParts on Company {
2+
__typename
3+
id
4+
name
5+
domainName
6+
updatedAt {
7+
...DateTimeParts
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fragment CustomerActorParts on CustomerActor {
2+
__typename
3+
customerId
4+
customer {
5+
id
6+
fullName
7+
avatarUrl
8+
email {
9+
email
10+
}
11+
company {
12+
...CompanyParts
13+
}
14+
}
15+
}

graphql/fragments/customerParts.gql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fragment CustomerParts on Customer {
2+
__typename
3+
id
4+
fullName
5+
shortName
6+
externalId
7+
email {
8+
email
9+
isVerified
10+
verifiedAt {
11+
...DateTimeParts
12+
}
13+
}
14+
updatedAt {
15+
...DateTimeParts
16+
}
17+
createdAt {
18+
...DateTimeParts
19+
}
20+
createdBy {
21+
...ActorParts
22+
}
23+
markedAsSpamAt {
24+
...DateTimeParts
25+
}
26+
}

graphql/fragments/dateTimeParts.gql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fragment DateTimeParts on DateTime {
2+
__typename
3+
iso8601
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fragment DeletedCustomerActorParts on DeletedCustomerActor {
2+
__typename
3+
customerId
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fragment MachineUserActorParts on MachineUserActor {
2+
__typename
3+
machineUserId
4+
machineUser {
5+
__typename
6+
...MachineUserParts
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fragment MachineUserParts on MachineUser {
2+
__typename
3+
id
4+
fullName
5+
publicName
6+
description
7+
updatedAt {
8+
...DateTimeParts
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fragment MutationErrorParts on MutationError {
2+
__typename
3+
message
4+
type
5+
code
6+
fields {
7+
__typename
8+
field
9+
message
10+
type
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fragment SystemActorParts on SystemActor {
2+
__typename
3+
systemId
4+
}

graphql/fragments/threadParts.gql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
fragment ThreadParts on Thread {
2+
__typename
3+
id
4+
externalId
5+
customer {
6+
...CustomerParts
7+
}
8+
statusDetail {
9+
...ThreadStatusDetailParts
10+
}
11+
status
12+
statusChangedAt {
13+
...DateTimeParts
14+
}
15+
16+
title
17+
description
18+
previewText
19+
priority
20+
21+
assignedAt {
22+
...DateTimeParts
23+
}
24+
assignedTo {
25+
__typename
26+
... on User {
27+
id
28+
fullName
29+
}
30+
... on MachineUser {
31+
id
32+
fullName
33+
}
34+
... on System {
35+
id
36+
}
37+
}
38+
39+
createdAt {
40+
...DateTimeParts
41+
}
42+
createdBy {
43+
...ActorParts
44+
}
45+
46+
updatedAt {
47+
...DateTimeParts
48+
}
49+
updatedBy {
50+
...ActorParts
51+
}
52+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
fragment ThreadStatusDetailParts on ThreadStatusDetail {
2+
__typename
3+
... on ThreadStatusDetailCreated {
4+
createdAt {
5+
...DateTimeParts
6+
}
7+
}
8+
... on ThreadStatusDetailSnoozed {
9+
snoozedAt {
10+
...DateTimeParts
11+
}
12+
snoozedUntil {
13+
...DateTimeParts
14+
}
15+
}
16+
... on ThreadStatusDetailUnsnoozed {
17+
snoozedAt {
18+
...DateTimeParts
19+
}
20+
}
21+
... on ThreadStatusDetailNewReply {
22+
newReplyAt {
23+
...DateTimeParts
24+
}
25+
}
26+
... on ThreadStatusDetailThreadLinkUpdated {
27+
updatedAt {
28+
...DateTimeParts
29+
}
30+
linearIssueId
31+
}
32+
... on ThreadStatusDetailReplied {
33+
repliedAt {
34+
...DateTimeParts
35+
}
36+
}
37+
... on ThreadStatusDetailReplied {
38+
repliedAt {
39+
...DateTimeParts
40+
}
41+
}
42+
... on ThreadStatusDetailWaitingForCustomer {
43+
statusChangedAt {
44+
...DateTimeParts
45+
}
46+
}
47+
... on ThreadStatusDetailWaitingForDuration {
48+
statusChangedAt {
49+
...DateTimeParts
50+
}
51+
waitingUntil {
52+
...DateTimeParts
53+
}
54+
}
55+
... on ThreadStatusDetailInProgress {
56+
statusChangedAt {
57+
...DateTimeParts
58+
}
59+
}
60+
... on ThreadStatusDetailThreadDiscussionResolved {
61+
threadDiscussionId
62+
statusChangedAt {
63+
...DateTimeParts
64+
}
65+
}
66+
... on ThreadStatusDetailLinearUpdated {
67+
updatedAt {
68+
...DateTimeParts
69+
}
70+
deprecatedLinearIssueId: linearIssueId
71+
}
72+
}

graphql/fragments/userActorParts.gql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fragment UserActorParts on UserActor {
2+
__typename
3+
userId
4+
user {
5+
__typename
6+
...UserParts
7+
}
8+
}

graphql/fragments/userParts.gql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fragment UserParts on User {
2+
__typename
3+
id
4+
fullName
5+
publicName
6+
email
7+
status
8+
avatarUrl
9+
updatedAt {
10+
...DateTimeParts
11+
}
12+
deletedAt {
13+
...DateTimeParts
14+
}
15+
}

graphql/getOperationName.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2+
import { Kind } from 'graphql';
3+
4+
const fallback = 'unknown';
5+
6+
// biome-ignore lint/suspicious/noExplicitAny:
7+
export function getOperationName(doc: string | TypedDocumentNode<any, any>): string {
8+
if (typeof doc === 'string') {
9+
const trimmed = doc.trim();
10+
const regex = /^(query|mutation) ([a-zA-Z]+)/g;
11+
12+
const matches = regex.exec(trimmed);
13+
14+
if (matches?.length === 3) {
15+
return matches[2];
16+
}
17+
return fallback;
18+
}
19+
20+
try {
21+
const firstDefinition = doc.definitions[0];
22+
23+
if (!firstDefinition) {
24+
return fallback;
25+
}
26+
27+
const operationName = firstDefinition.kind === Kind.OPERATION_DEFINITION
28+
? firstDefinition?.name?.value
29+
: fallback;
30+
31+
if (typeof operationName === 'string') {
32+
return operationName;
33+
}
34+
} catch {}
35+
36+
return fallback;
37+
}

0 commit comments

Comments
 (0)