I am working on a small POC where I am trying to use GraphQL from Bazel. To do that, I created a wrapper around
apollo-compiler which given a graphql file and a schema would generate the corresponding source files.
I am the following issue:
the generated files are saved in bazel-bin/src/main/java/com/example/apollo, however, when I try to reference any of those classes in my program, they are not visible, i.e: not only are they not visible in the IDE, but even if I reference them by the fully qualified package name and try to build from command line, the compilation would still fail.
So basically my question is, how do I make the generated sources to be included in the project?
Here the compiler rule definition:
def _compiler(ctx):
out = ctx.actions.declare_directory("apollo")
inputs = ctx.files.srcs
args = ctx.actions.args()
args.add(out.path)
args.add_all(ctx.files.srcs)
ctx.actions.run(
executable = ctx.executable.code_generator,
arguments = [args],
inputs = inputs,
outputs = [out],
)
return [DefaultInfo(files = depset([out]))]
compiler = rule(
attrs = {
"code_generator": attr.label(
cfg = "exec",
default = ":code_generator",
executable = True,
),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
allow_empty = False,
),
},
implementation = _compiler,
output_to_genfiles = True,
)
BUILD file
load("@rules_java//java:defs.bzl", "java_binary")
java_binary(
name = "code_generator",
srcs = [
"Compiler.java",
],
main_class = "com.example.compiler.Compiler",
deps = [
"@maven//:com_apollographql_apollo3_apollo_compiler",
],
)
Would appreciate any input.