Skip to content

Instantly share code, notes, and snippets.

@kyledetella
Last active June 27, 2018 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyledetella/6d521e29664050220af60495e4032da7 to your computer and use it in GitHub Desktop.
Save kyledetella/6d521e29664050220af60495e4032da7 to your computer and use it in GitHub Desktop.
Notes about the Github GraphQL API
  • Just typing https://api.github.com/graphql into graphiql gave a great error message pointing to documentation

    {"message":"This endpoint requires you to be authenticated.","documentation_url":"https://developer.github.com/v3/#authentication"}
  • Results weren't super clear when fetching gists. It only returned public gists by default – the documentation doesn't explicitly state this. It says: A list of the Gists the user has created.

    query User {
      user(login: "kyledetella") {
        gists(first: 3) {
          nodes {
            name
            description
            isPublic
          }
        }
      }
    }

    However, there is an argument of privacy that is an enum of PUBLIC|SECRET|ALL and providing that, gave me the expected response.

    query User {
      user(login: "kyledetella") {
        gists(first: 3, privacy: ALL) {
          nodes {
            name
            description
            isPublic
          }
        }
      }
    }
  • I received a partial error when querying for colloaborators on repositories. It wasn't clear immediately because some results were returned. Unfortunately, I cannot easily understand/see which repo(s) failed.

    Query

    query Repo {
      repository(owner: "kyledetella", name: "rrr") {
    	databaseId
        owner {
          repositories(first: 55) {
            nodes {
              name
              collaborators(first: 3) {
                nodes {
                  name
                }
              }
            }
          }
        }
      }
    }

    Response (truncated)

    {
      "data": {
        "repository": {
          "databaseId": 27852146,
          "owner": {
            "repositories": {
              "nodes": [
                ...
    	{
                  "name": "grunt-dustjs",
                  "collaborators": {
                    "nodes": [
                      {
                        "name": "Kyle DeTella"
                      }
                    ]
                  }
                },
              ]
            }
          }
        }
      },
      "errors": [
        {
          "message": "Must have push access to view repository collaborators.",
          "type": "FORBIDDEN",
          "path": [
            "repository",
            "owner",
            "repositories",
            "nodes",
            49,
            "collaborators"
          ],
          "locations": [
            {
              "line": 8,
              "column": 11
            }
          ]
        }
      ]
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment