Skip to content

Instantly share code, notes, and snippets.

@angelorobo
Last active October 24, 2019 06:45
Show Gist options
  • Save angelorobo/a3406b2b80943da639dcbe2dc160995d to your computer and use it in GitHub Desktop.
Save angelorobo/a3406b2b80943da639dcbe2dc160995d to your computer and use it in GitHub Desktop.
BlaBla 编程挑战
// **BlaBla 编程挑战**
// Github提供2种公开的API,一种是REST和另一种是GraphQL。BlaBla编程挑战是利用Github GraphQL以查询GitHub的公共数据
// 并解析API的JSON响应以回答我们已下出的问题。我们系统中使用了GraphQL,因此拥有GraphQL的知识对我们团队中的移动开发人员是非常重要的。
// 首先,您可以在以下链接测试Github GraphQL并了解一些实际的例子:
// https://developer.github.com/v4/explorer/
// 这个指南提供了有关GitHub GraphQL入门的信息:
// https://developer.github.com/v4/guides/
// 如何获取GitHub API TOKEN:
// 1. 在 https://github.com/settings/tokens/new 选择您要授予TOKEN的权限。我们目前只需要选择 ‘public_repo’权限。
// 2. 获取TOKEN后,您可以从本地客户端尝试GraphQL查询。
// 3. 我们建议您下载Insomnia去执行GraphQL查询: https://insomnia.rest/download/
// 这个截屏显示如何输入你的TOKEN在Insomnia:
// https://share.weiyun.com/5TAi3Bc
// 这个截屏显示如何去执行GraphQL查询:
// https://share.weiyun.com/5IXQyJ4
// 对于此测试,我们将使用此GraphQL查询来搜索此存储库https://github.com/octocat/Hello-World/ 的最近100个issues。
/*
query {
repository(owner:"octocat", name:"Hello-World") {
issues(last:100) {
edges {
node {
id
author {
login
}
title
state
closed
closedAt
createdViaEmail
publishedAt
url
}
}
}
}
}
*/
// 这个GraphQL查询的结果是:
/*
{
"data": {
"repository": {
"issues": {
"edges": [
{
"node": {
"id": "MDU6SXNzdWUyMTY1MzUyMzQ=",
"author": {
"login": "ghaseminya"
},
"title": "Is this repository a test and sample repo?",
"state": "CLOSED",
"closed": true,
"closedAt": "2017-03-24T11:00:06Z",
"createdViaEmail": false,
"publishedAt": "2017-03-23T18:51:45Z",
"url": "https://github.com/octocat/Hello-World/issues/333"
}
},
...
*/
// 这是一个CURL示例
/*
curl --request POST \
--url https://api.github.com/graphql \
-H 'Content-Type: application/json' -H 'Authorization: Bearer <换成你的TOKEN>' \
-d '{ "query": "query {repository(owner:\"octocat\", name:\"Hello-World\") { issues(last:100) { edges { node { id title } } } } }" }'
*/
// 以下是我们需要您完成的编程任务挑战:
// 1.用 Dart(首选)、Objective-C、Swift或Java编写代码发送以上描述的GraphQL请求来搜索此存储库 https://github.com/octocat/Hello-World/
// 的最近100个issues。
// 2.解析JSON响应以回答以下三个问题(issue最好可以解析成对象):
// a. 找出最近100个issues中所有的标题(title) (不重复)
// b. 找出最近100个issues中所有的作者ID (不重复)
// c. 找出最近100个issues中哪个作者提交了最多的issues
// P.S. 可以考虑使用的GraphQL库
// Flutter可以用https://github.com/zino-app/graphql-flutter
// OC/Swift可以用https://github.com/apollographql/apollo-ios
// Android可以用https://github.com/apollographql/apollo-android
// 感谢您阅读到现在为止。 对于移动端开发人员而言,我们认为了解如何编写REST或GraphQL请求和解析API的JSON响应非常重要。
// 完成挑战后,请把原始码寄到我们的邮箱 hr@blabla.app 并标记你的名字。
// 如果您有任何问题,请询问。谢谢!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment