A scala code generator for the @graphql-codegen toolchain.
Development of code generators seems to have shifted from the base apollo tools to this plugin. @graphql-codgen uses the concept of plugins to allow you to layer on different codegen tasks to achieve the desired output.
This codegen is currently focused on generating code for scala.js frontends.
npm i -D @aappddeevv/graphql-codegen-scala
You should use the other @graphql-codgen plugins to achieve the desired output package:
# yml configuration schema: "schema.json" //generated separately from server documents: "awesome_sub_project/src/main/graphql/*.graphql generates: awesome_sub_project/target/scala-2.13/src_managed/main/cli_codegen/graphql.scala plugins: - graphql-codgen-scala - add: "// DO NOT EDIT" - add: "package awesome" config: gqlImport: "apollo_boost._#gql hooks: afterOneFileWrite: - scalafmt
You only need the scalafmt hook if you want to read clean sources.
Skipping gqlImport means that the documents are not inlined into
the operation objects.
apollo_boost is scala.js published package
that has a
gql function that takes a string and produces a
DocumentNode via the graphql packages written in
apollo_boost scala.js facade.
You do not have to hardcode the output path, you could pass output information from sbt into the "run" script.
You will want to generate your sources directly into
the src_generated directory of your project and then
ensure that the contents are watched. You can have this codegen
automatically triggered by using the
plugin and simply configuring it to run when the sources
sbt-cli-codgen plugin into project/plugins.sbt, then:
// build.sbt mycommand = (files: Seq[String]) => (Seq("npx", "graphql-codegen"), Seq("graphql.scala")) lazy val proja = project.in(file("proja")) .enablePlugins(CLICodgenPlugin) .settings( codegenCommand := mycommand, codegenInputSources := Seq(sourceDirectory.value.toGlob / "proja/src/main/graphql/*.graphql") )
The above config assumes a few sbt-cli-codegen defaults.
mycommand formulates the
command to be run and the output file. If you need to insert content from sbt into
the yaml config file, you could perform a side-effect inside the function.