How to use @octokit/graphql - 10 common examples

To help you get started, we’ve selected a few @octokit/graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-web / index.js View on Github external
options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
        if (options.baseUrl) {
            requestDefaults.baseUrl = options.baseUrl;
        }
        if (options.previews) {
            requestDefaults.mediaType.previews = options.previews;
        }
        if (options.timeZone) {
            requestDefaults.headers["time-zone"] = options.timeZone;
        }
        this.request = request.defaults(requestDefaults);
        this.graphql = withCustomRequest(this.request).defaults({
            ...requestDefaults,
            baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
        });
        this.log = Object.assign({
            debug: () => { },
            info: () => { },
            warn: console.warn.bind(console),
            error: console.error.bind(console),
        }, options.log);
        this.hook = hook;
        // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
        //     is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
        // (2) If only `options.auth` is set, use the default token authentication strategy.
        // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
        // TODO: type `options.auth` based on `options.authStrategy`.
        if (!options.authStrategy) {
github probot / probot / src / github / graphql.ts View on Github external
export function addGraphQL (client: GitHubAPI) {
  const graphqlRequest = (client.request as any as typeof request).defaults({
    ...(process.env.GHE_HOST ? { baseUrl: `https://${process.env.GHE_HOST}/api` } : {})
  })
  const graphql = withCustomRequest(graphqlRequest)

  client.graphql = (...args: any[]): any => {
    if (args[2]) {
      // tslint:disable-next-line:no-console
      console.warn(`github.graphql: passing extra headers as 3rd argument is deprecated. You can pass headers in the 2nd argument instead, using the "headers" key:

    github.graphql(query, { headers })

See https://probot.github.io/docs/github-api/#graphql-api`)

      args[1] = Object.assign(args[1] || {}, { headers: args[2] })
    }

    return graphql(args[0], args[1])
  }
  // tslint:disable-next-line:deprecation
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-node / index.js View on Github external
requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" ");

    if (options.baseUrl) {
      requestDefaults.baseUrl = options.baseUrl;
    }

    if (options.previews) {
      requestDefaults.mediaType.previews = options.previews;
    }

    if (options.timeZone) {
      requestDefaults.headers["time-zone"] = options.timeZone;
    }

    this.request = request.request.defaults(requestDefaults);
    this.graphql = graphql.withCustomRequest(this.request).defaults(_objectSpread2(_objectSpread2({}, requestDefaults), {}, {
      baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api")
    }));
    this.log = Object.assign({
      debug: () => {},
      info: () => {},
      warn: console.warn.bind(console),
      error: console.error.bind(console)
    }, options.log);
    this.hook = hook; // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
    //     is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
    // (2) If only `options.auth` is set, use the default token authentication strategy.
    // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
    // TODO: type `options.auth` based on `options.authStrategy`.

    if (!options.authStrategy) {
      if (!options.auth) {
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-src / index.js View on Github external
options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
        if (options.baseUrl) {
            requestDefaults.baseUrl = options.baseUrl;
        }
        if (options.previews) {
            requestDefaults.mediaType.previews = options.previews;
        }
        if (options.timeZone) {
            requestDefaults.headers["time-zone"] = options.timeZone;
        }
        this.request = request.defaults(requestDefaults);
        this.graphql = withCustomRequest(this.request).defaults({
            ...requestDefaults,
            baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
        });
        this.log = Object.assign({
            debug: () => { },
            info: () => { },
            warn: console.warn.bind(console),
            error: console.error.bind(console),
        }, options.log);
        this.hook = hook;
        // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
        //     is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
        // (2) If only `options.auth` is set, use the default token authentication strategy.
        // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
        // TODO: type `options.auth` based on `options.authStrategy`.
        if (!options.authStrategy) {
github kidonng / scoop-docs / scripts / index-apps.js View on Github external
const { graphql } = require('@octokit/graphql')
const algoliasearch = require('algoliasearch')

const graphqlWithAuth = graphql.defaults({
  headers: { authorization: `token ${process.env.GITHUB_TOKEN}` }
})
const client = algoliasearch('F8ONSWSRN9', process.env.ALGOLIA_APIKEY)
const index = client.initIndex('scoop_apps')
const tmpIndex = client.initIndex('scoop_apps_tmp')

;(async () => {
  try {
    // Get known buckets
    const { repository } = await graphqlWithAuth(`
      {
        repository(owner: "lukesampson", name: "scoop") {
          object(expression: "master:buckets.json") {
            ... on Blob {
              text
            }
github tesseralis / is-react-translated-yet / src / LangList.js View on Github external
async function getProgressList(langs) {
  // TODO this search requires looking for issues with the string "Translation Progress"
  // in the title. Maybe we should replace it with something more robust.
  const { search } = await graphql(
    `
      query($limit: Int!) {
        search(
          type: ISSUE
          query: "org:reactjs Translation Progress in:title"
          first: $limit
        ) {
          nodes {
            ... on Issue {
              title
              body
              createdAt
              lastEditedAt
              number
              repository {
                name
github vector-im / feature-dashboard / src / Github.js View on Github external
userContentEdits(first: 100) {
                                    edges {
                                        node {
                                            editedAt
                                            diff
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }`
        for (const repo of searchRepos) {
            let [owner, project] = repo.split('/');
            let issues = await graphql(query, {
                headers: {
                    authorization: "token f3b7ff551d31170bef759d1a6889ee62ce5b3a83"
                },
                owner: owner,
                project: project,
                labels: labels
            });
            console.log(issues);
        }
    }
github Azure / dev-spaces / actions / add-review-url-ts / src / AddReviewUrl.ts View on Github external
private async addCommentUsingSubjectId(pullRequestId: GraphQlQueryResponseData, comment: string) {
        console.log(`pullRequestId  ===>>>> ${pullRequestId}`)
        let data = JSON.parse(JSON.stringify(pullRequestId));
        console.log(`Parsed pull request id ${data}`)
        const token = core.getInput('repo-token');
        let graphQlResponse = graphql(this.addPullRequestCommentMutation(), {
                headers: {
                    authorization: `token ${token}`,
                },
                subjectId: data.repository.pullRequest.id,
                body: comment,

            },
        );
        console.log(`Adding the comment ...`);
        return await graphQlResponse;
    }
github Azure / dev-spaces / actions / add-review-url-ts / src / AddReviewUrl.ts View on Github external
private async getSubjectId(findPullRequestIdQuery: string, nameAndRepo: string[]) {
        console.log('Inside getSubjectId');
        const token = core.getInput('repo-token');
        let newVar: GraphQlQueryResponseData = await graphql(findPullRequestIdQuery, {
                headers: {
                    authorization: `token ${token}`,
                },
                owner: nameAndRepo[0],
                repo: nameAndRepo[1],
                pullNumber: this.getPullNumber(),
            },
        );
        console.log(`Exiting getSubject Id`);
        return newVar;
    }
github golangci / golangci-lint / .github / contributors / generate.ts View on Github external
const buildContributorInfo = async (contributors: WeightedContributor[]): Promise<ContributorInfo[]> => {
  const query = `{
    ${contributors.map((c, i) => `user${i}: user(login: "${c.login}") {...UserFragment}`).join(`\n`)}
  }
    fragment UserFragment on User {
        login
        name
        websiteUrl
        avatarUrl
    }`

  try {
    const resp = await graphql.graphql(query, {
      headers: {
        authorization: `token ${process.env.GITHUB_TOKEN}`,
      },
    })

    return contributors.map((_, i) => resp[`user${i}`]).filter((v) => v)
  } catch (err) {
    if (err.errors && err.data) {
      console.warn(`github errors:`, err.errors)
      return contributors.map((_, i) => err.data[`user${i}`]).filter((v) => v)
    }
    throw err
  }
}

@octokit/graphql

GitHub GraphQL API client for browsers and Node

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis