项目作者: codacy

项目描述 :
Library with Apollo compiled queries and models for GitHub API V4
高级语言: Scala
项目地址: git://github.com/codacy/codacy-github-graphql.git
创建时间: 2019-09-11T10:34:05Z
项目社区:https://github.com/codacy/codacy-github-graphql

开源协议:

下载


codacy-github-graphql

Codacy Badge
CircleCI
Download

Library with Apollo compiled queries and models for GitHub API V4

Build

  1. sbt compile

Usage

Look for queries under package com.github.api.v4._
and use com.codacy.graphql.apollo.client.ScalaApolloClient to get futures instead of callbacks from the ApolloClient.

Example

  1. import java.net.URL
  2. import com.github.api.v4.ListProjectMembershipsQuery
  3. import com.codacy.graphql.apollo.client.ScalaApolloClient
  4. import scala.collection.JavaConverters._
  5. import scala.compat.java8.OptionConverters._
  6. import scala.concurrent.duration._
  7. val client = ScalaApolloClient(new URL("https://api.example.com/graphql"))
  8. // val client = ScalaApolloClient(new URL("https://api.example.com/graphql"), okHttpClient)
  9. // val client = ScalaApolloClient(apolloClient)
  10. val queryMemberships = ListProjectMembershipsQuery
  11. .builder()
  12. .ownerName("codacy")
  13. .repositoryName("codacy-eslint")
  14. .build()
  15. val result = client.execute(queryMemberships)
  16. val data = result.map { res =>
  17. for {
  18. data <- res.data().asScala
  19. repositoryEntries <- data.repositoryEntries().asScala
  20. collaborators <- repositoryEntries.collaborators().asScala
  21. nodes <- collaborators.nodes().asScala.map(_.asScala)
  22. } yield nodes.map(c => (c.databaseId().asScala, c.login(), Option(c.email()).filter(_.nonEmpty)))
  23. }

FAQ

  1. How to add a new query?

    • Create file in src/main/graphql/com/github/api/v4 with the query
    • Check if any new scalar is needed.
      Look in com.github.api.v4.type.CustomType if all the types there already have CustomTypeAdapter
      that is linked in com.codacy.graphql.apollo.client.ApolloClient (look for a addCustomTypeAdapter)
  2. How to add a CustomTypeAdapter?

    • Check what is the original type of the scalar in the src/main/graphql/com/github/api/v4/schema.graphql (e.g.: Date in a string format, long, …)
    • Check package com.codacy.graphql.adapter for examples and possible implementations for existing API types
    • Add invocation of addCustomTypeAdapter when creating the com.codacy.graphql.apollo.client.ApolloClient
  3. How to handle Inline Fragments?

    • The visitor provided by the generator should help but for some reason it is not being generated.
      For now, since they can be of multiple types you need to check the instance type and to cast :(

What is Codacy

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.