Library with Apollo compiled queries and models for GitHub API V4
Library with Apollo compiled queries and models for GitHub API V4
sbt compile
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
import java.net.URL
import com.github.api.v4.ListProjectMembershipsQuery
import com.codacy.graphql.apollo.client.ScalaApolloClient
import scala.collection.JavaConverters._
import scala.compat.java8.OptionConverters._
import scala.concurrent.duration._
val client = ScalaApolloClient(new URL("https://api.example.com/graphql"))
// val client = ScalaApolloClient(new URL("https://api.example.com/graphql"), okHttpClient)
// val client = ScalaApolloClient(apolloClient)
val queryMemberships = ListProjectMembershipsQuery
.builder()
.ownerName("codacy")
.repositoryName("codacy-eslint")
.build()
val result = client.execute(queryMemberships)
val data = result.map { res =>
for {
data <- res.data().asScala
repositoryEntries <- data.repositoryEntries().asScala
collaborators <- repositoryEntries.collaborators().asScala
nodes <- collaborators.nodes().asScala.map(_.asScala)
} yield nodes.map(c => (c.databaseId().asScala, c.login(), Option(c.email()).filter(_.nonEmpty)))
}
How to add a new query?
src/main/graphql/com/github/api/v4
with the querycom.github.api.v4.type.CustomType
if all the types there already have CustomTypeAdaptercom.codacy.graphql.apollo.client.ApolloClient
(look for a addCustomTypeAdapter
)How to add a CustomTypeAdapter?
src/main/graphql/com/github/api/v4/schema.graphql
(e.g.: Date in a string format, long, …)com.codacy.graphql.adapter
for examples and possible implementations for existing API typesaddCustomTypeAdapter
when creating the com.codacy.graphql.apollo.client.ApolloClient
How to handle Inline Fragments
?
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.
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
Codacy is free for Open Source projects.