Skip to content

Cant get gatsby-source-github-api to load properly #23

Open

Description

@iamjmitch

Hi,

Sorry if this is not the right place to post this but I cant seem to get this to load up properly.

I goto localhost:8000/___graphql I do now have the option of allGithubData/githubData however there is no user/repo there.

Current gatsby-node.js file

const dotenv = require("dotenv")
    dotenv.config()
    
  plugins: [
    {
      resolve: `gatsby-source-github-api`,
      options: {
        url: "https://api.github.com/graphql",
        token: process.env.GATSBY_GITHUB_ACCESS,
        },
    },
...
]

.env file seems to be working fine for other plugins so I don't think that's the problem.

Have tried uninstall package globally and from --save and reinstalling.

What am I doing wrong?

Edit: no issues thrown on gatsby develop

CT4lV

Activity

  1. changed the title [-]Cant get gatsby-source-github-api to loadproperly[/-] [+]Cant get gatsby-source-github-api to load properly[/+] on Oct 13, 2020
  2. ldd commented on Oct 17, 2020

    @ldd
    Owner

    Maybe take a look at this:
    #21 (comment)

    In particular, you do not really get any data so it's possible that the query that you are using is invalid.
    I looked at that person's source code and found this:
    https://github.com/orlovedev/orlove.dev/blob/master/gatsby-config.js#L32-L56

    Let me know if that helps and if it doesn't, give me a link to your repo and/or a github gist with the relevant code from gatsby-config.js

    I hope that helps!

  3. panzerdp commented on Nov 4, 2020

    @panzerdp

    Unfortunately I faced the same problem. Couldn't get the plugin to provide the GitHub queries.

  4. soVader commented on Apr 26, 2022

    @soVader

    Does anyone have an update on this? I'm unable to get it to work in Gatsby 4.10.3 and I've asked on StackOverflow: "Why am I unable to get any organization repositories from gatsby-source-github-api?"

  5. ldd commented on Apr 26, 2022

    @ldd
    Owner

    author here. @soVader I think you are missing an ending } for your query to work (from the stack overflow question you made)

    so instead of

    exports.githubApiQuery = `
    query($github_login: String!, $repo_count: Int!){
      viewer {
        organization(login: $github_login) {
          login
          id
          location
          name
          url
          repositories(first: $repo_count, privacy:PRIVATE) {
            nodes {
              id
              name
              openGraphImageUrl
              createdAt
              stargazerCount
              url
              description
            }
          }
        }
      }
    `

    it should be

    exports.githubApiQuery = `
    query($github_login: String!, $repo_count: Int!){
      viewer {
        organization(login: $github_login) {
          login
          id
          location
          name
          url
          repositories(first: $repo_count, privacy:PRIVATE) {
            nodes {
              id
              name
              openGraphImageUrl
              createdAt
              stargazerCount
              url
              description
            }
          }
        }
      }
    }
    `

    Let me know if that fixes it (or if it helps)

  6. soVader commented on Apr 27, 2022

    @soVader

    @ldd thanks for reaching out really appreciate it. I've built and tested my query in explorer and in Postman with the token as my password using the query of:

    query ($github_org: String!, $repo_count: Int!) {
      organization(login: $github_org) {
        repositories(
          first: $repo_count
          privacy: PUBLIC
          isFork: false
          orderBy: {field: UPDATED_AT, direction: DESC}
        ) {
          nodes {
            id
            name
            updatedAt
            createdAt
            stargazerCount
            url
            description
          }
        }
      }
    }
    

    variables:

    {
      "github_org": "facebook",
      "repo_count": 3
    }
    

    my gatsby-config.js for the plugin:

    {
          resolve: `gatsby-source-github-api`,
          options: {
            url: 'https://api.github.com/graphql',
    
            // token: required by the GitHub API
            token: process.env.GITHUB_TOKEN,
    
            // GraphQLquery: defaults to a search query
            graphQLQuery: `
            query ($github_org: String!, $repo_count: Int!) {
              organization(login: $github_org) {
                repositories(
                  first: $repo_count
                  privacy: PUBLIC
                  isFork: false
                  orderBy: {field: UPDATED_AT, direction: DESC}
                ) {
                  nodes {
                    id
                    name
                    updatedAt
                    createdAt
                    stargazerCount
                    url
                    description
                  }
                }
              }
            }
            `,
    
            // variables: defaults to variables needed for a search query
            variables: {
              github_org: process.env.GITHUB_ORG,
              repo_count: 3,
            },
          },
        },
    

    the above query works in Postman and Explorer. Let me delete everything and start over after a reboot, VSC update and rebuild my config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions