Releases: muuki88/sbt-graphql
v0.16.0
Added codeGen
directive #93
Added a codeGen
directive that is erased during source code generation and
can be used to customize the generated code.
Example - skip code generation
To skip the code generation and provide your own type.
query CodeGenHeroNameQuery {
hero @codeGen(useType: "Hero") {
name
}
}
You can also use the fully qualified class name to avoid clashes
query CodeGenHeroNameQuery {
hero @codeGen(useType: "com.example.model.Hero") {
name
}
}
v0.15.0
v0.13.0 Remove jawn dependency
0.10.1 release
Version 0.10.0 - Magic Imports
Magic #imports
This is a feature tries to replicate the apollographql/graphql-tag loader.js
feature, which enables including (or actually inlining) partials into a graphql query with magic comments.
Explained
The syntax is straightforward
#import path/to/included.fragment.graphql
The fragment files should be named liked this
<name>.fragment.graphql
There is a excludeFilter in graphqlCodegen
, which removes them from code generation so they are just used for inlining
and interface generation.
The resolving of paths works like this
- The path is resolved by checking all
sourceDirectories in graphqlCodegen
for the given path - No relative paths like
./foo.fragment.graphql
are supported - Imports are resolved recursively. This means you can
#import
fragments in a fragment.
Example
I have a file CharacterInfo.fragment.graphql
which contains only a single fragment
fragment CharacterInfo on Character {
name
}
And the actual graphql query file
query HeroFragmentQuery {
hero {
...CharacterInfo
}
human(id: "Lea") {
homePlanet
...CharacterInfo
}
}
#import fragments/CharacterInfo.fragment.graphql
Version 0.9.1
Add additional imports to generated Interfaces.scala
Version 0.9.0
Interfaces & types
Pull Request: #45
The ApolloSourceGenerator
now generates an additional file Interfaces.scala
with the following shape:
object types {
// contains all defined types like enums and aliases
}
// all used fragments and interfaces are generated as traits here
We generate the types, aliases and interfaces by
- Merging all graphql documents into a single one. Sangria takes care of fragment deduplication. The behaviour when a fragment has the same name but different contents is at the moment unspecified.
- From the "master document" we generate all interfaces, types and aliases that are actually used
- We import
types._
in all generated code. The interfaces are already in the package scope. so no additional import is required
Use case
Share common business logic around a fragment that shouldn't be a directive
You can now do this by defining a fragment
and include it in every query that
requires to apply this logic. sbt-graphql
will generate the common trait?
,
all generated case classes will extend this fragment trait
.
Limitations
You need to copy the fragments into every graphql
query that should use it.
If you have a lot of queries that reuse the fragment and you want to apply changes,
this is cumbersome.
You cannot nest fragments. The code generation isn't capable of naming the nested data structure. This means that you need create fragments for every nesting.
Invalid
query HeroNestedFragmentQuery {
hero {
...CharacterInfo
}
human(id: "Lea") {
...CharacterInfo
}
}
# This will generate code that may compile, but is not usable
fragment CharacterInfo on Character {
name
friends {
name
}
}
correct
query HeroNestedFragmentQuery {
hero {
...CharacterInfo
}
human(id: "Lea") {
...CharacterInfo
}
}
# create a fragment for the nested query
fragment CharacterFriends on Character {
name
}
fragment CharacterInfo on Character {
name
friends {
...CharacterFriends
}
}
Version 0.8.1
Version 0.8.0
JSON data decoder
#40 adds a decoder for the top level Data
type. Before the circe decoder chain was incomplete.
document val in GraphQLQuery
trait
#37 adds a document
field to the GraphQLQuery
trait for easier access to the raw document.
Remove redundant import
#39 fixes scalac linting error
User defined imports
#36 allows custom imports in every generated code
graphqlCodegenImports ++= Seq(
"my.package._",
"my.package.foo"
)
Version 0.7.0
Upgraded circe to 0.9.3