Skip to content

Commit

Permalink
refactor: insert GITHUB_ACCESS_TOKEN in env.ts and `graphql-githu…
Browse files Browse the repository at this point in the history
…b-repository.ts``
  • Loading branch information
mrlemoos committed Mar 26, 2024
1 parent 022f6f4 commit bf55ead
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/domains/environment/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ export interface EnvironmentVariables {
*/
CONTENTFUL_ACCESS_TOKEN: string;
/**
* The `GITHUB_USER_PINNED_REPOSITORIES` is the username of the GitHub user
* whose pinned repositories will be fetched.
* The `GITHUB_ACCESS_TOKEN` is the personal access token that is used to
* access the GitHub API.
*/
GITHUB_USER_PINNED_REPOSITORIES: string;
GITHUB_ACCESS_TOKEN: string;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/domains/github/_/graphql-github-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from '@apollo/client';
import { setContext } from '@apollo/client/link/context';

import env from '~/domains/environment/env';

import GitHubRepository from '../github-repository';
import GitHubPinnedRepositoryModel from '../models/github-pinned-repository-model';

Expand Down Expand Up @@ -36,14 +38,15 @@ interface PartialGitHubUser {
* repositories from the GitHub GraphQL API.
*/
export default class GraphQLGitHubRepository extends GitHubRepository {
private readonly GITHUB_ACCESS_TOKEN = env('GITHUB_ACCESS_TOKEN');
private readonly HTTP_LINK = createHttpLink({
uri: 'https://api.github.com/graphql',
});
private readonly AUTH_CONTEXT = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`,
authorization: `Bearer ${this.GITHUB_ACCESS_TOKEN}`,
},
};
});
Expand Down

0 comments on commit bf55ead

Please sign in to comment.