Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 58 additions & 32 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,72 @@ import dotenv from 'dotenv';

dotenv.config();

if (!process.env.GITHUB_TOKEN) {
// The Atlassian GraphQL gateway is public and requires no credentials.
const ATLASSIAN_GRAPHQL_URL = 'https://developer.atlassian.com/gateway/api/graphql';

const generates: CodegenConfig['generates'] = {
'src/renderer/utils/forges/bitbucket/graphql/generated/graphql.ts': {
schema: {
// The public Atlassian schema also fails graphql-js v17's stricter
// interface-deprecation-consistency validation, so skip validation.
[ATLASSIAN_GRAPHQL_URL]: { assumeValid: true },
},
documents: ['src/renderer/utils/forges/bitbucket/**/*.graphql'],
plugins: ['typescript-operations', 'typed-document-node'],
config: {
documentMode: 'string',
enumType: 'native',
defaultScalarType: 'string',
useTypeImports: true,
// The public gateway schema diverges from the runtime Atlassian schema
// (for example `notificationFeed` lacks the `flat` argument), so document
// validation against it is skipped. See setchy/atlassify for the same workaround.
skipDocumentsValidation: true,
},
},
};

if (process.env.GITHUB_TOKEN) {
generates['src/renderer/utils/forges/github/graphql/generated/graphql.ts'] = {
schema: {
'https://api.github.com/graphql': {
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
// Hierarchy and issue fields each require their GraphQL schema feature.
'GraphQL-Features': 'sub_issues,issue_fields',
},
// GitHub's live schema currently fails graphql-js's stricter
// interface-deprecation-consistency validation (added in graphql v17).
// Skip validation so introspection can still succeed.
assumeValid: true,
},
},
documents: ['src/renderer/utils/forges/github/**/*.graphql'],
plugins: ['typescript-operations', 'typed-document-node'],
config: {
documentMode: 'string',
// enumType: 'native',
scalars: {
DateTime: 'string',
URI: '../../../../../types#Link',
},
useTypeImports: true,
},
};
} else {
// oxlint-disable-next-line no-console -- CLI script output
console.warn(
'\x1b[33m⚠ GITHUB_TOKEN is not set. Skipping GraphQL codegen.\n' +
' To generate updated types, create a .env file with a valid GitHub PAT.\n' +
'\x1b[33m⚠ GITHUB_TOKEN is not set. Skipping GitHub GraphQL codegen.\n' +
' To generate updated GitHub types, create a .env file with a valid GitHub PAT.\n' +
' See .env.template for details.\x1b[0m',
);
process.exit(0);
}

const config: CodegenConfig = {
overwrite: true,
schema: {
'https://api.github.com/graphql': {
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
// Hierarchy and issue fields each require their GraphQL schema feature.
'GraphQL-Features': 'sub_issues,issue_fields',
},
// GitHub's live schema currently fails graphql-js's stricter
// interface-deprecation-consistency validation (added in graphql v17).
// Skip validation so introspection can still succeed.
assumeValid: true,
},
},
documents: ['src/renderer/utils/forges/github/**/*.graphql'],
generates: {
'src/renderer/utils/forges/github/graphql/generated/graphql.ts': {
plugins: ['typescript-operations', 'typed-document-node'],
config: {
documentMode: 'string',
// enumType: 'native',
scalars: {
DateTime: 'string',
URI: '../../../../../types#Link',
},
useTypeImports: true,
},
},
},
// Per-output schemas are declared on each `generates` entry, so no root schema is needed.
documents: [],
generates,
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class TypedDocumentString<TResult, TVariables>
{
__apiType?: NonNullable<DocumentTypeDecoration<TResult, TVariables>['__apiType']>;
private value: string;
public __meta__?: Record<string, unknown> | undefined;
public __meta__?: Record<string, any> | undefined;

constructor(value: string, __meta__?: Record<string, unknown> | undefined) {
constructor(value: string, __meta__?: Record<string, any> | undefined) {
super(value);
this.value = value;
this.__meta__ = __meta__;
Expand Down Expand Up @@ -157,7 +157,7 @@ export const MyNotificationsDocument = new TypedDocumentString(`
notificationFeed(
flat: $flat
first: $first
filter: {readStateFilter: $readState}
filter: { readStateFilter: $readState }
) {
pageInfo {
hasNextPage
Expand Down Expand Up @@ -221,4 +221,4 @@ export const MarkAsUnreadDocument = new TypedDocumentString(`
markNotificationsByIdsAsUnread(ids: $notificationIDs)
}
}
`) as unknown as TypedDocumentString<MarkAsUnreadMutation, MarkAsUnreadMutationVariables>;
`) as unknown as TypedDocumentString<MarkAsUnreadMutation, MarkAsUnreadMutationVariables>;
Loading