Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iamjmitch opened this issue Oct 13, 2020 · 5 comments
Open

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

iamjmitch opened this issue Oct 13, 2020 · 5 comments

Comments

@iamjmitch
Copy link

iamjmitch commented Oct 13, 2020

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

@iamjmitch iamjmitch changed the title Cant get gatsby-source-github-api to loadproperly Cant get gatsby-source-github-api to load properly Oct 13, 2020
@ldd
Copy link
Owner

ldd commented Oct 17, 2020

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!

@panzerdp
Copy link

panzerdp commented Nov 4, 2020

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

@soVader
Copy link

soVader commented Apr 26, 2022

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?"

@ldd
Copy link
Owner

ldd commented Apr 26, 2022

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)

@soVader
Copy link

soVader commented Apr 27, 2022

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants