Skip to content

Commit b956624

Browse files
committed
Refactored front-end and fixed uber jar creation
1 parent b4dbe22 commit b956624

File tree

20 files changed

+195
-160
lines changed

20 files changed

+195
-160
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ Seed project for Play framework + ScalaJS using Apollo client and Sangria.
1010
- Node installed on the dev box
1111
- SBT installed on the dev box
1212

13+
## Commands
14+
15+
- run: runs the server and live reloads the changes
16+
- web_client/Compile/managedSources: generates schema.graphql and query/mutation objects for the client
17+
- assembly: generates the uber jar
18+
1319
## Problems
1420

1521
- WebpackDevServer is not used at the moment
1622
- Some scalajs is not picked up by Intellij as valid (i.e. the components defined with macros).
1723
- When a new dependency is added to the npmDependencies the bundle.js is not rebuilt.
18-
- When a graphql query is changed if the browser is refreshed the new query does not get picked up
1924
- The build is slow because some files are not cached
25+
- Add test framework
26+
- Refetching the queries instead of changing the apollo cache.
2027

2128
## Credits
2229

project/Packaging.scala

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import com.typesafe.sbt.packager.Keys._
22
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.{Docker, dockerExposedPorts, dockerExposedVolumes}
3-
import com.typesafe.sbt.packager.jdkpackager.JDKPackagerPlugin.autoImport.{JDKPackager, jdkAppIcon, jdkPackagerBasename}
43
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.{Universal, useNativeZip}
54
import sbt.Keys._
65
import sbt._
76

87
object Packaging {
9-
private[this] lazy val iconGlob = sys.props("os.name").toLowerCase match {
10-
case os if os.contains("mac") => "*.icns"
11-
case os if os.contains("win") => "*.ico"
12-
case _ => "*.png"
13-
}
14-
158
private[this] def isConf(x: (File, String)) = x._1.getAbsolutePath.contains("conf/")
169

1710
val settings = useNativeZip ++ Seq(
@@ -22,7 +15,7 @@ object Packaging {
2215
mappings in Universal := (mappings in Universal).value.filterNot(isConf),
2316

2417
// Docker
25-
dockerExposedPorts := Seq(9000),
18+
dockerExposedPorts := Seq(Shared.projectPort),
2619
dockerLabels ++= Map("project" -> Shared.projectId),
2720
dockerUpdateLatest := true,
2821
defaultLinuxInstallLocation in Docker := s"/opt/${Shared.projectId}",
@@ -31,13 +24,6 @@ object Packaging {
3124
version in Docker := version.value,
3225
dockerUsername := Some(Shared.projectId),
3326

34-
// JDK Packager
35-
jdkAppIcon := (sourceDirectory.value ** iconGlob).getPaths.headOption.map(file),
36-
jdkPackagerBasename := Shared.projectName,
37-
name in JDKPackager := Shared.projectName,
38-
3927
javaOptions in Universal ++= Seq("-J-Xmx2g", "-J-Xms256m", s"-Dproject=${Shared.projectId}")
4028
)
41-
42-
}
43-
29+
}

project/ProjectVersionManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ object ProjectVersionManager {
66
val content =s"""
77
|package util
88
|
9-
|object Version {
9+
|object Version {
1010
| val projectId = "$projectId"
1111
| val projectName = "$projectName"
1212
| val projectPort = $projectPort
1313
|
14-
| val version = "${version.value}"
14+
| val version = "${version.value}"
1515
|}
1616
|""".stripMargin.trim
1717

project/Server.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,14 @@ object Server {
4848
// Sbt-Web
4949
JsEngineKeys.engineType := JsEngineKeys.EngineType.Node,
5050
pipelineStages in Assets := Seq(scalaJSPipeline),
51-
// pipelineStages in Assets ++= Seq(digest),
52-
// includeFilter in digest := "*.js",
53-
5451

5552
// Fat-Jar Assembly
5653
assemblyJarName in assembly := Shared.projectId + ".jar",
5754
assemblyMergeStrategy in assembly := {
5855
case "play/reference-overrides.conf" => MergeStrategy.concat
5956
case x => (assemblyMergeStrategy in assembly).value(x)
6057
},
58+
mainClass in assembly := Some("Bootstrap"),
6159
fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value),
6260
)
6361

project/Shared.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ object Shared {
5151
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.first
5252
case PathList("sqlj", _ @ _*) => MergeStrategy.first
5353
case PathList("play", "reference-overrides.conf") => MergeStrategy.first
54+
case PathList("util", "Version$.class") => MergeStrategy.first
5455
case "module-info.class" => MergeStrategy.discard
5556
case "messages" => MergeStrategy.concat
5657
case "pom.xml" => MergeStrategy.discard
5758
case "JS_DEPENDENCIES" => MergeStrategy.discard
59+
case "NPM_DEPENDENCIES" => MergeStrategy.discard
5860
case "pom.properties" => MergeStrategy.discard
5961
case "application.conf" => MergeStrategy.concat
6062
case x => (assemblyMergeStrategy in assembly).value(x)

project/WebClient.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ object WebClient {
3434
"react-dom" -> reactVer,
3535
"react-proxy" -> "1.1.8",
3636
"apollo-boost" -> "0.1.16",
37+
"apollo-cache-inmemory" -> "1.4.3",
3738
"react-apollo" -> "2.2.2",
3839
"graphql-tag" -> "2.10.0",
3940
"graphql" -> "14.0.2",
@@ -47,7 +48,7 @@ object WebClient {
4748
"copy-webpack-plugin" -> "4.5.4",
4849
"clean-webpack-plugin" -> "1.0.0",
4950
"webpack-merge" -> "4.1.4",
50-
"apollo" -> "2.5.1"
51+
"apollo" -> "2.5.3"
5152
),
5253

5354
webpack / version := "4.21.0",
@@ -67,7 +68,7 @@ object WebClient {
6768

6869
lazy val web_client = (project in file("web_client"))
6970
.settings(clientSettings: _*)
70-
.settings(addCommandAlias("dev", ";fastOptJS::startWebpackDevServer;~fastOptJS"): _*)
71+
// .settings(addCommandAlias("dev", ";fastOptJS::startWebpackDevServer;~fastOptJS"): _*)
7172
.enablePlugins(ScalaJSPlugin, ScalaJSWeb, ScalaJSBundlerPlugin)
7273
.dependsOn(Shared.sharedJs, Schema.schema)
7374
}

schema/src/main/scala/something/GraphQLSchema.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object GraphQLSchema {
3030

3131
val Id = Argument("id", StringType)
3232

33-
val QueryType = ObjectType("Query", fields[RequestContext, Unit](
33+
val QueryType = ObjectType("Query", fields[RequestContext, Any](
3434
Field("product", OptionType(ProductType),
3535
description = Some("Returns a product with specific `id`."),
3636
arguments = Id :: Nil,
@@ -44,8 +44,8 @@ object GraphQLSchema {
4444
val DescriptionArg = Argument("description", StringType)
4545

4646
val MutationType = ObjectType("Mutation",
47-
fields[RequestContext, Unit](
48-
Field("addProduct", OptionType(IntType),
47+
fields[RequestContext, Any](
48+
Field("addProduct", ProductType,
4949
arguments = NameArg :: DescriptionArg :: Nil,
5050
resolve = req => req.ctx.productRepo.addProduct(req.arg(NameArg), req.arg(DescriptionArg))
5151
)

schema/src/main/scala/something/ProductRepoLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ trait ProductRepoLike {
88

99
def products: List[RetailProduct]
1010

11-
def addProduct(name: String, description: String): Int
11+
def addProduct(name: String, description: String): RetailProduct
1212

1313
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package controllers
22

33
import javax.inject._
4-
import play.api._
4+
import play.Environment
55
import play.api.mvc._
66

77
/**
88
* This controller creates an `Action` to handle HTTP requests to the
99
* application's home page.
1010
*/
1111
@Singleton
12-
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
12+
class HomeController @Inject()(cc: ControllerComponents, env: Environment) extends AbstractController(cc) {
1313

1414
/**
1515
* Create an Action to render an HTML page.
@@ -19,6 +19,6 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
1919
* a path of `/`.
2020
*/
2121
def index() = Action { implicit request: Request[AnyContent] =>
22-
Ok(views.html.index())
22+
Ok(views.html.index(env.isDev))
2323
}
2424
}

server/app/repositories/ProductRepo.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class ProductRepo extends ProductRepoLike {
1313

1414
def products: List[Product] = productList.toList
1515

16-
def addProduct(name: String, description: String): Int = {
16+
def addProduct(name: String, description: String): Product = {
1717
val newId = productList.size + 1
1818
productList = productList :+ Product(newId.toString, name, description)
19-
newId
19+
Product(newId.toString, name, description)
2020
}
2121
}
2222

0 commit comments

Comments
 (0)