Skip to content

This projects aims at creating a GraphQL client for GitHub. It fetches the response objects and deserializes it onto some object with the help of design patterns ensuring type safety.

Notifications You must be signed in to change notification settings

jeet1995/github-graphql-rest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Homework 1

Description: object-oriented design and implementation of a GraphQL client for Github.

Grade: 7% + bonus up to 3%

You can obtain this Git repo using the command git clone git clone https://bitbucket.org/cs474_fall2019/homework1.git.

Preliminaries

As part of homework assignment you will gain experience with creating and managing your Git repository, learning GraphQL and the data model of Github, creating your own model and the object-oriented design of a subset of the Github GraphQL model, creating JUnit tests, and creating your SBT or Gradle build and run scripts for your GraphQL client application. Doing this homework is essential for successful completion of the rest of this course, since all other homeworks and the course project will share the same features of this homework: branching, merging, committing, pushing your code into your Git repo, creating test cases and build scripts, and using various tools for diagnosing problems with your applications.

First things first, you must create your account at BitBucket, a Git repo management system. It is imperative that you use your UIC email account that has the extension @uic.edu. Once you create an account with your UIC address, BibBucket will assign you an academic status that allows you to create private repos. Bitbucket users with free accounts cannot create private repos, which are essential for submitting your homeworks and the course project. Your instructor created a team for this class named cs474_Fall2019. Please contact your TA, Mr. Aditya Gupta using your UIC.EDU email account and he will add you to the team repo as developers, since Mr.Gupta already has the admin privileges. Please use your emails from the class registration roster to add you to the team and you will receive an invitation from BitBucket to join the team. Since it is a large class, please use your UIC email address for communications or Piazza and avoid emails from other accounts like [email protected]. If you don't receive a response within 12 hours, please contact us via Piazza, it may be a case that your direct emails went to the spam folder.

Next, if you haven't done so, you will install IntelliJ with your academic license, the JDK, the Scala runtime and the IntelliJ Scala plugin, the Simple Build Toolkit (SBT) or the Gradle build tool and make sure that you can create, compile, and run Java and Scala programs. Please make sure that you can run various Java tools from your chosen JDK.

In this and all consecutive homeworks and in the course project you will use logging and configuration management frameworks. You will comment your code extensively and supply logging statements at different logging levels (e.g., TRACE, INFO, ERROR) to record information at some salient points in the executions of your programs. All input and configuration variables must be supplied through configuration files -- hardcoding these values in the source code is generally prohibited and will be punished by taking a large percentage of points from your total grade! You are expected to use Logback and SLFL4J for logging and Typesafe Conguration Library for managing configuration files. These and other libraries should be imported into your project using your script build.sbt or gradle script. These libraries and frameworks are widely used in the industry, so learning them is the time well spent to improve your resumes.

Even though you can implement your homework in Java, you can also use Scala, for which you will receive an additional bonus of up to 3% for fully pure functional (not imperative) implementation. You will be expected to learn Scala as you go. As you see from the StackOverflow survey, knowledge of Scala is highly paid and in great demand, and it is expected that you pick it relatively fast, especially since it is tightly integrated with Java. I recommend using the book on Programming in Scala: Updated for Scala 2.12 published on May 10, 2016 by Martin Odersky and Lex Spoon. You can obtain this book using the academic subscription on Safari Books Online. There are many other books and resources available on the Internet to learn Scala. Those who know more about functional programming can use the book on Functional Programming in Scala published on Sep 14, 2014 by Paul Chiusano and Runar Bjarnason.

To receive your bonus for writing your implementation in Scala, you should avoid using vars and while/for loops that iterate over collections using induction variables. Instead, you should learn to use collection methods map, flatMap, foreach, filter and many others with lambda functions, which make your code linear and easy to understand. Also, avoid mutable variables at all cost. Points will be deducted for having many vars and inductive variable loops without explanation why mutation is needed in your code - you can always do without it.

Overview

In this homework, you will create an object-oriented design and implementation of a program that extracts and organizes git repositories data from Github. As the first step, you will create your developer account at Github and you will obtain your authorization key. The Github schema is publicly available and you will study it to understand the organization of data items on Github and relationships among them. That is, for a given repo, you may obtain the information on all contributors, commits, URL for each commit, the changeset and many other metadata. For a given contributor, you may determine all projects that this contributor participated in and what type of code s/he committed. A part of this homework is that you come up with your own GraphQL queries that will slice and dice the Github schema and you will create a model and object-oriented design of your program based on your model.

This homework is based on GraphQL and it is a new technology released by Facebook as an open-source software and it is already widely used. There are many resources on the Internet including its official specification, query tools, and a compendium of useful links in addition to youtube videos and various documents and examples on Stackoverflow. It is beneficial that you learn GraphQL as you go, since it is a simple declarative language that can be nicely intergrated into programs written in object-oriented languages.

This homework script is written using a retroscripting technique, in which the homework outlines are generally and loosely drawn, and the individual students improvise to create the implementation that fits their refined objectives. In doing so, students are expected to stay within the basic requirements of the homework and they are free to experiments. That is, it is impossible that two non-collaborating students will submit similar homeworks! Asking questions is important, so please ask away at Piazza!

Functionality

Once you installed and configured your Github developer account, your job is to create various GraphQL queries to understand how the process works. Consider a snippet of the Scala code below that creates a basic HTTP client for Github GraphQL endpoint and serves a basic query and obtains the response. In it, a simple GraphQL query for Github is formed, a connection to the Github endpoint is created, the query is submitted and the response is obtained. Using JSON converters the response is converted into Scala classes. Of course, feel free to experiment and use third-party libraries for your client, but remember that your time is limited and you may not be able to explore the majority of the available tools on the Internet for GraphQL.

val BASE_GHQL_URL = "https://api.github.com/graphql"
val temp="{viewer {email login url}}"
implicit val formats = DefaultFormats

val client = HttpClientBuilder.create.build
val httpUriRequest = new HttpPost(BASE_GHQL_URL)
httpUriRequest.addHeader("Authorization", "Bearer d6150dbc62cdefb310080e1b37008013f46dbbbc")
httpUriRequest.addHeader("Accept", "application/json")
val gqlReq = new StringEntity("{\"query\":\"" + temp + "\"}" )
httpUriRequest.setEntity(gqlReq)

val response = client.execute(httpUriRequest)
System.out.println("Response:" + response)
response.getEntity match {
    case null => System.out.println("Response entity is null")
    case x if x != null => {
      val respJson = fromInputStream(x.getContent).getLines.mkString
      System.out.println(respJson)
      val viewer = parse(respJson).extract[Data]
      System.out.println(viewer)
      System.out.println(write(viewer))
  }
}

Your homework can be divided roughly into five steps. First, you learn how GraphQL-based programs are organized and what your building blocks are for the Github data. I suggest that you load the source code of a GraphQL client into IntelliJ and explore its classes, interfaces, and dependencies and how it interacts with the Github GraphQL endpoint. Second, you create your own model that describes what Github data you want to operate on and for what purpose. You will create various composite objects and define their behavior, e.g., like obtaining git repos where more than one commit happened per week. Next, you will create an implementation of your design where you will use more than TWO different design patterns from the GoF book. Fourth, you will create multiple unit tests using JUnit framework. Finally, you will run your program, measure the CPU and memory usages using Java tools and collect execution logs.

Baseline

To be considered for grading, your project should include at least one of your own written programs in Java or Scala (i.e., not copied examples where you renamed variables or refactored them similarly), your project should be buildable using the SBT or the Gradle, and your documentation must specify how you create and evaluate your models. Your documentation must include your design and model, the reasoning about pros and cons, explanations of your implementation and the chosen design patterns, and the results of your runs, the measurement of the runtime parameters of the program (e.g., CPU and RAM utilization). Simply copying some open-source Java programs from examples and modifying them a bit (e.g., rename some variables) will result in desk-rejecting your submission.

Piazza collaboration

You can post questions and replies, statements, comments, discussion, etc. on Piazza. For this homework, feel free to share your ideas, mistakes, code fragments, commands from scripts, and some of your technical solutions with the rest of the class, and you can ask and advise others using Piazza on where resources and sample programs can be found on the internet, how to resolve dependencies and configuration issues. When posting question and answers on Piazza, please select the appropriate folder, i.e., hw1 to ensure that all discussion threads can be easily located. Active participants and problem solvers will receive bonuses from the big brother :-) who is watching your exchanges on Piazza (i.e., your class instructor and your TA). However, you must not describe your design or specific details related how your construct your models!

Git logistics

This is an individual homework. Separate repositories will be created for each of your homeworks and for the course project. You will find a corresponding entry for this homework at https://bitbucket.org/cs474_fall2019/homework1.git. You will fork this repository and your fork will be private, no one else besides you, the TA and your course instructor will have access to your fork. Please remember to grant a read access to your repository to your TA and your instructor. In future, for the team homeworks and the course project, you should grant the write access to your forkmates, but NOT for this homework. You can commit and push your code as many times as you want. Your code will not be visible and it should not be visible to other students (except for your forkmates for a team project, but not for this homework). When you push the code into the remote repo, your instructor and the TA will see your code in your separate private fork. Making your fork public or inviting other students to join your fork for an individual homework will result in losing your grade. For grading, only the latest push timed before the deadline will be considered. If you push after the deadline, your grade for the homework will be zero. For more information about using the Git and Bitbucket specifically, please use this link as the starting point. For those of you who struggle with the Git, I recommend a book by Ryan Hodson on Ry's Git Tutorial. The other book called Pro Git is written by Scott Chacon and Ben Straub and published by Apress and it is freely available. There are multiple videos on youtube that go into details of the Git organization and use.

Please follow this naming convention while submitting your work : "Firstname_Lastname_hw1" without quotes, where you specify your first and last names exactly as you are registered with the University system, so that we can easily recognize your submission. I repeat, make sure that you will give both your TA and the course instructor the read/write access to your private forked repository so that we can leave the file feedback.txt with the explanation of the grade assigned to your homework.

Discussions and submission

As it is mentioned above, you can post questions and replies, statements, comments, discussion, etc. on Piazza. Remember that you cannot share your code and your solutions privately, but you can ask and advise others using Piazza and StackOverflow or some other developer networks where resources and sample programs can be found on the Internet, how to resolve dependencies and configuration issues. Yet, your implementation should be your own and you cannot share it. Alternatively, you cannot copy and paste someone else's implementation and put your name on it. Your submissions will be checked for plagiarism. Copying code from your classmates or from some sites on the Internet will result in severe academic penalties up to the termination of your enrollment in the University. When posting question and answers on Piazza, please select the appropriate folder, i.e., hw1 to ensure that all discussion threads can be easily located.

Submission deadline and logistics

Wednesday, October 2 at 3AM CST via the bitbucket repository. Your submission will include the code for the program, your documentation with instructions and detailed explanations on how to assemble and deploy your program along with the results of your simulation and a document that explains these results based on the characteristics and the parameters of your models, and what the limitations of your implementation are. Again, do not forget, please make sure that you will give both your TAs and your instructor the read access to your private forked repository. Your name should be shown in your README.md file and other documents. Your code should compile and run from the command line using the commands sbt clean compile test and sbt clean compile run or the corresponding commands for Gradle. Also, you project should be IntelliJ friendly, i.e., your graders should be able to import your code into IntelliJ and run from there. Use .gitignore to exlude files that should not be pushed into the repo.

Evaluation criteria

  • the maximum grade for this homework is 7% with the bonus up to 3%. Points are subtracted from this maximum grade: for example, saying that 2% is lost if some requirement is not completed means that the resulting grade will be 7%-2% => 5%; if the core homework functionality does not work, no bonus points will be given;
  • only some POJO classes are created and nothing else is done: up to 7% lost;
  • having less than five unit and/or integration tests: up to 5% lost;
  • missing comments and explanations from the submitted program: up to 5% lost;
  • logging is not used in your programs: up to 3% lost;
  • hardcoding the input values in the source code instead of using the suggested configuration libraries: up to 4% lost;
  • no instructions in README.md on how to install and run your program: up to 5% lost;
  • the program crashes without completing the core functionality: up to 3% lost;
  • no design and modeling documentation exists that explains your choices: up to 6% lost;
  • the deployment documentation exists but it is insufficient to understand how you assembled and deployed all components of the program: up to 5% lost;
  • the minimum grade for this homework cannot be less than zero.

That's it, folks!

About

This projects aims at creating a GraphQL client for GitHub. It fetches the response objects and deserializes it onto some object with the help of design patterns ensuring type safety.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages