From cb4cbc828c447cede97602ce264b48c52908dbd4 Mon Sep 17 00:00:00 2001 From: Pratham Date: Thu, 28 Sep 2023 12:26:21 +0530 Subject: [PATCH 1/3] removing unnecesarry dependency graphql --- package-lock.json | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2d64bca..e27175e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "cors": "^2.8.5", "express": "^4.18.2", "express-graphql": "^0.12.0", - "graphql": "^15.8.0", "linkedom": "^0.15.3" }, "devDependencies": { @@ -5101,6 +5100,7 @@ "version": "15.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==", + "peer": true, "engines": { "node": ">= 10.x" } diff --git a/package.json b/package.json index f4eae28..1498ab5 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "cors": "^2.8.5", "express": "^4.18.2", "express-graphql": "^0.12.0", - "graphql": "^15.8.0", "linkedom": "^0.15.3" }, "devDependencies": { From cfc21ba7d249d5aee87f38de65ca3353863b9cf0 Mon Sep 17 00:00:00 2001 From: Pratham Date: Thu, 28 Sep 2023 12:26:31 +0530 Subject: [PATCH 2/3] UPDATE README --- README.md | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/README.md b/README.md index 62247dc..c5fa512 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,140 @@ This route returns a JSON object containing details of a specific GitHub communi } ``` +## Route 4: /graphql + +Checkout the [GraphQL API](https://graphql.org/graphql-js/running-an-express-graphql-server/) section for more details. + +Checkout this video for more details [GraphQL by Web Dev Simplified](https://www.youtube.com/watch?v=ZQL7tL2S0oQ) + +This route returns a JSON object containing details of a specific GitHub community member. This is a GraphQL API. The details provided include: + +- `name`: Name +- `username`: GitHub username +- `profile_pic_url`: Profile picture URL +- `followers`: Number of followers +- `following`: Number of people they follow +- `repositories`: Number of repositories +- `bio`: Bio +- `github_link`: GitHub profile URL + +**Example Response for getting a single user:** + +```http + POST /graphql +``` + +```json +{ + "query": "query { member(username: \"PRATHAM1ST\") { name github_link profile_pic_url bio } }" + // member(username: \"$github_username\") +} +``` + +```json +{ + "data": { + "member": { + "name": "Pratham", + "github_link": "https://github.com/PRATHAM1ST", + "profile_pic_url": "https://avatars.githubusercontent.com/u/52632050?v=4", + "bio": "Interested in Web Development and Coding! ", + } + } +} + +``` + +**Example Response for getting all users:** + +```http + POST /graphql +``` + +```json +{ + "query": "query { members { name github_link profile_pic_url bio } }" +} +``` + +```json +{ + "data": { + "members": [ + { + "name": null, + "github_link": "https://github.com/AyushiVachhani", + "profile_pic_url": "https://avatars.githubusercontent.com/u/133210173?v=4", + "bio": "" + }, + { + "name": null, + "github_link": "https://github.com/chirag-11-k", + "profile_pic_url": "https://avatars.githubusercontent.com/u/104491213?v=4", + "bio": "Chirag Kuriya" + }, + + ... + + { + "name": "Pratham", + "github_link": "https://github.com/PRATHAM1ST", + "profile_pic_url": "https://avatars.githubusercontent.com/u/52632050?v=4", + "bio": "WEB is Love 😌✨" + }, + { + "name": null, + "github_link": "https://github.com/purvipatel183", + "profile_pic_url": "https://avatars.githubusercontent.com/u/100862029?v=4", + "bio": "" + }, + { + "name": null, + "github_link": "https://github.com/zaidkhan16", + "profile_pic_url": "https://avatars.githubusercontent.com/u/121684903?v=4", + "bio": "" + } + ] + } +} + +``` + +**Example Error Response:** + +```http + POST /graphql +``` + +```json +{ + "query": "query { members { name bioData } }" + + // Note that bioData is a custom field that is not available in the database. It is a custom field that is created by the resolver. +} +``` + +```json +{ + "errors": [ + { + "message": "Cannot query field \"bioData\" on type \"Member\".", + "locations": [ + { + "line": 3, + "column": 14 + } + ] + } + ] + + // This is the error that you will get if you try to query a field that is not available in the database. +} + +``` + + + ## Using the API To interact with this API, simply send a GET request to the appropriate route. For example, to retrieve the list of community members, send a GET request to `/members`. @@ -137,5 +271,6 @@ We use Jest for testing. You can run the tests with `npm test`. - Nodemon - ESLint - Dotenv +- Express-Graphql That's it! You are now ready to use our API to access community member data or explore other available routes. If you have any questions or encounter issues, feel free to reach out to us. Happy coding! From 59b5d2f10ee4f4477dc893582c32aca4232bd0a7 Mon Sep 17 00:00:00 2001 From: Pratham Date: Thu, 28 Sep 2023 12:26:46 +0530 Subject: [PATCH 3/3] login variable to username var --- controllers/graphql.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/graphql.ts b/controllers/graphql.ts index 34e7aa4..ef90b54 100644 --- a/controllers/graphql.ts +++ b/controllers/graphql.ts @@ -22,7 +22,7 @@ const schema = buildSchema(` type Query { members: [Member!]! - member(login: String!): Member + member(username: String!): Member } `); @@ -30,8 +30,8 @@ const root = { members: (): Member[] => { return membersListLatest; }, - member: ({ login }: { login: string }): Member | undefined => { - return membersListLatest.find((member) => member.login === login); + member: ({ username }: { username: string }): Member | undefined => { + return membersListLatest.find((member) => member.login === username); }, };