Skip to content

vgrec/bazel-graphql-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example usage of Bazel + Apollo GraphQL

To build the POC project, run:

bazel build //src/main/java/com/example

How the Gradle Apollo plugin works

If we check the sources of the Apollo Gradle plugin, we can see that the plugin functions as a facade for the apollo-compiler library. The apollo-compiler library is responsible for the actual code generation, and is separate from the implementation of the gradle plugin.

To generate code directly using the apollo-compiler, one can use:

import java.io.File

val outputDir = File("apollo")
val queryFile = File("queries.graphql")
val schemaFile = File("schema.graphqls")
val testDir = File("apolloTest")
val packageName = "com.example"

val options = Options(
    setOf(queryFile),
    schemaFile,
    outputDir,
    testDir,
    packageName
)

ApolloCompiler.write(options)

The generated sources will be placed in a directory defined by outputDir in a package defined by packageName.

Building a Bazel rule that triggers the code generation

With the above in place we can now create a Bazel rule that takes as input the schema and .graphql files and produces as output the generated source code. For convenience, the generated source code is zipped into a source jar, and this source jar becomes the target's output which other rules can depend on.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published