mbohun / gist-view-jsTree

1 stars 0 forks source link

Add support for GitHub GraphQL API #1

Open mbohun opened 5 years ago

mbohun commented 5 years ago

GitHub GraphQL API

GET number of gist-s

query { 
  viewer {
    gists {
      totalCount
    }   
  }
}

result:

{
  "data": {
    "viewer": {
      "gists": {
        "totalCount": 230
      }
    }
  }
}

GET gist-s description and id

query($number_of_gists:Int!) { 
  viewer {
    gists(last: $number_of_gists) {
      nodes {
        description
        id
      }
    }
  }
}
variables {
   "number_of_gists": 230
}

result:

{
  "errors": [
    {
      "type": "EXCESSIVE_PAGINATION",
      "path": [
        "viewer",
        "gists"
      ],
      "locations": [
        {
          "line": 8,
          "column": 5
        }
      ],
      "message": "Requesting 230 records on the `gists` connection exceeds the `last` limit of 100 records."
    }
  ]
}

TODO: HOW to get pagination limit ?

result:

{
  "data": {
    "viewer": {
      "gists": {
        "nodes": [
          {
            "description": "github event type: issues payload example",
            "id": "MDQ6R2lzdGZmMjU0YTFkYzZhYzAyMWRlYTM3"
          },
          {
            "description": "8 queens problem in PROLOG",
            "id": "MDQ6R2lzdDc2MjJiZTBjMDcwNDQ5YzgwMjZm"
          },
          {
            "description": "fast queue with min",
            "id": "MDQ6R2lzdGVjZDk0ODQwYTQ3OWEyN2FlYmUz"
          }
        ]
      }
    }
  }
}
mbohun commented 5 years ago

curl, jq example-s:

mbohun@linux-bswl:~/src> curl -s -H "Authorization: bearer $GITHUB_TOKEN" -X POST -d " \
 { \
   \"query\": \"query { viewer { gists { totalCount} }}\" \
 } \
" https://api.github.com/graphql | jq
{
  "data": {
    "viewer": {
      "gists": {
        "totalCount": 230
      }
    }
  }
}

...with variables:

mbohun@linux-bswl:~/src> curl -s -H "Authorization: bearer $GITHUB_TOKEN" -X POST https://api.github.com/graphql -d '{"query": "query($num_gists:Int!) { viewer { gists(last: $num_gists) { nodes { description id } } } }", "variables": { "num_gists": 2} }' | jq
{
  "data": {
    "viewer": {
      "gists": {
        "nodes": [
          {
            "description": "Google API notes",
            "id": "MDQ6R2lzdDgxZGY5YTI3ZTkwODQ2YmE5MTM4NzFiMDRkNzYyYzRm"
          },
          {
            "description": "gist-view jsTree notes",
            "id": "MDQ6R2lzdDdhYzExNzU0ODQ0ZDdmZDVjZTk5M2I5NGFlN2M1MGVk"
          }
        ]
      }
    }
  }
}
mbohun commented 5 years ago

There might be NUMEROUS LIMITATIONS/RESTRICTIONS compared to the GitHub REST API, this needs proper checking/evaluation: