@diberry/github-magic
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

GraphQL Data Scrape SDK

Connect with personal access token (PAT)

const { whoami } = require("@diberry/github-magic");

const pat = "ghp_...";
const gitHubGraphQLUrl = "https://api.github.com/graphql";

async function main() {
  if (!pat) throw Error("auth is missing");
  if (!gitHubGraphQLUrl) throw Error("gitHubGraphQLUrl is missing");
  const rawResult = await whoami({ pat, gitHubGraphQlUrl: gitHubGraphQLUrl });
  return rawResult.viewer.login;
}
main().then((result)=>console.log(result)).catch(err=>console.log(err))

Connect with user token

  1. Must have already exchanged user's code for user's token
  2. Use token in place of PAT in client creation. Assumes token returned from GitHub is bearer token.
const { whoami } = require("@diberry/github-magic");

const token = "gho_...";
const gitHubGraphQLUrl = "https://api.github.com/graphql";

async function main() {
  if (!token) throw Error("auth is missing");
  if (!gitHubGraphQLUrl) throw Error("gitHubGraphQLUrl is missing");
  const rawResult = await whoami({ pat, gitHubGraphQlUrl: gitHubGraphQLUrl });
  return rawResult.viewer.login;
}
main().then((result)=>console.log(result)).catch(err=>console.log(err))

Package Sidebar

Install

npm i @diberry/github-magic

Weekly Downloads

4

Version

2.3.1

License

MIT

Unpacked Size

1.73 MB

Total Files

97

Last publish

Collaborators

  • diberry