mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-22 05:02:18 +08:00
26 lines
596 B
TypeScript
26 lines
596 B
TypeScript
import fetch from 'node-fetch';
|
|
|
|
const GITHUB_API = 'https://api.github.com/graphql';
|
|
|
|
export const githubClient = (apiKey: string) => {
|
|
return async (query: string, variables?: { [key: string]: any }) => {
|
|
const res = await fetch(GITHUB_API, {
|
|
method: 'POST',
|
|
headers: {
|
|
authorization: `token ${apiKey}`,
|
|
},
|
|
body: JSON.stringify({
|
|
query,
|
|
variables,
|
|
}),
|
|
});
|
|
|
|
const result = await res.json();
|
|
const { data, errors } = result;
|
|
if (errors) {
|
|
throw new Error(JSON.stringify(errors[0]));
|
|
}
|
|
return data;
|
|
};
|
|
};
|