ldd / gatsby-source-github-api

Pull data into Gatsby from Github API v4
MIT License
65 stars 10 forks source link

Unknown type "Blob" #21

Closed orlowdev closed 4 years ago

orlowdev commented 4 years ago

Hi guys. I got a problem with extracting readme from my repos. I tried the following query:

query {
user(login: "priestine") {
      repositories(
        isFork: false
        first: 25
        isLocked: false
        orderBy: { field: UPDATED_AT, direction: DESC }
      ) {
        nodes {
          name
          url
          forkCount
          openGraphImageUrl
          stargazers {
            totalCount
          }
          fundingLinks {
            url
          }
          object(expression: "master:README.md") {
            ... on Blob {
              text
            }
          }
        }
      }
    }
}

It doesn't start and throws the message:

Unknown type "Blob".

GraphQL request:32:20
31 |           object(expression: "master:README.md") {
32 |             ... on Blob {
   |                    ^
33 |               text

I've tested the query in GitHub GraphQL API Explorer and the query itself is valid and it works. Is it me doing something wrong? Any help would be greatly appreciated. Thanks!

orlowdev commented 4 years ago

My apologies, everything works great! Ignore me 😂

ldd commented 4 years ago

was it perhaps

              edges {
                node {
                 [stuff goes here]
                  }
                }

instead of

             nodes {
                 [stuff goes here]
                }

?

orlowdev commented 4 years ago

No, not really. It was just me having a token that cannot access things I tried to get via GraphQL. This caused the query to get nothing from GitHub, which, in turn, made githubData to have no data property. Without it in place, the whole query failed. As it had the type it couldn't understand (Blob), it failed to even start the dev server. That's all, folks 😆

GarciaPL commented 4 years ago

@priestine So I assume that not enough privileges was set for token ? I am asking as I am having the same issue with unrecognized type Blob on my side

orlowdev commented 4 years ago

@GarciaPL, for me a new token fixed the problem. I managed to debug the token issue by removing all the keys in the query related to packages and it worked for me. If you still have issues, read the description of the package carefully, for me it worked.

Things to be attentive to:

You can also take a look at the orlove.dev repo in my profile, in gatsby-config.js and src/pages/index.tsx.

I hope these tips will help. Cheers!

GarciaPL commented 4 years ago

@priestine thank you for your help! Now everything works as expected, much appreciated! :100:

orlowdev commented 4 years ago

Glad I could help. 👍

GarciaPL commented 4 years ago

@priestine Apologize, but I was wrong that it works. It does for sure for the simple case of graphql without spreading used on types like getting info about user etc. When I have below graphql query defined in gatsby-config.js which just returns blob of the files defined in the given repository. This query works in GitHub GraphQL API

        graphQLQuery: `
          query {
            repository(owner: "CodingVoodoo", name: "template") {
              object(expression: "master:") {
                ... on Tree {
                  entries {
                    name
                    type
                    object {
                      ... on Blob {
                        text
                      }
                    }
                  }
                }
              }
            }
          }
        `

it gives me two errors

Unknown type "Tree".

GraphQL request:7:20
6 |           object {
7 |             ... on Tree {
  |                    ^
8 |               entries {

and

Unknown type "Blob".

GraphQL request:12:26
11 |                 object {
12 |                   ... on Blob {
   |                          ^
13 |                     text

Of course I am using query without parameters like

export const query = graphql`
  query {
    githubData {
      data {
        repository {
          object {
            ... on Tree {
              entries {
                name
                type
                object {
                  ... on Blob {
                    text
                  }
                }
              }
            }
          }
        }
      }
    }
  }
`

Would you be so kind and highlight where the problem is ? Only what I have found is that perhaps I need to create type definition as here specified Gatsby Creating type definitions

orlowdev commented 4 years ago

Try this query in the code:

query {
    githubData {
      data {
        repository {
          object {
              entries {
                name
                type
                object {
                    text
                  }
                }
            }
          }
        }
    }
  }

It should work.

GarciaPL commented 4 years ago

Thank you! I would never find out that it should look like that. It works now! Thank you once again!

orlowdev commented 4 years ago

Sure, np. I’m not an expert in the topic but the to me underlying idea here is that at your app launch the GitHub query is executed, producing a new GraphQL schema where the data already has the shape that was returned from github. Thus you no longer have the blob and other stuff. Maybe I’m wrong. 😁

ldd commented 4 years ago

Hey! I really liked this little conversation.

I'll try adding a small FAQ in the readme with the things you discovered to make it easier for other devs using this package.

Otherwise, consider this issue closed (but feel free to add more comments if you want)