npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aappddeevv/graphql-codegen-scala

v0.1.4

Published

Generate scala/scala.js files from graphql schema and operations. Initial focus is on the client.

Downloads

13

Readme

graphql-codegen-scala

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 @graphql-codegen/cli @graphql-codegen/add
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:
      - @aappddeevv/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 graphql DocumentNode via the graphql packages written in javascript and facaded by the 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.

sbt

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 sbt-cli-codgen plugin and simply configuring it to run when the sources change.

Install the 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(
     // optional: watch the codegen config file itself
     watchSources += baseDirectory.value / "codegen.yml",
     codegenCommand := mycommand,
     // In this case, you could also add the schema.json file since the codegen config is independent
     // of the scala config.
     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.

You can use sbt to trigger a re-run or use the watch flag on @graphql-codegen.

Evolution

The codegen plugin does not handle all graphql constructs and is in a state of flux while it adds more graphql capabilities.