Skip to content

Commit fcd5727

Browse files
authored
Update sangria to 2.0.0-RC1 and misc updates / fixes (#87)
* Update sangria to 2.0.0-RC1 and misc updates / fixes * Fixed the doubled escape sign $ while generating the source
1 parent 7162a01 commit fcd5727

File tree

19 files changed

+186
-92
lines changed

19 files changed

+186
-92
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: scala
22
matrix:
33
include:
44
- jdk: openjdk8
5-
scala: 2.12.7
5+
scala: 2.12.11
66
env: COMMAND=validate
77

88
script:

build.sbt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ organization := "rocks.muki"
33
sbtPlugin := true
44
enablePlugins(SbtPlugin)
55

6-
val circeVersion = "0.11.1"
7-
val catsVersion = "1.5.0"
6+
val circeVersion = "0.13.0"
7+
val catsVersion = "2.1.1"
88
libraryDependencies ++= Seq(
9-
"org.sangria-graphql" %% "sangria" % "1.4.2",
9+
"org.sangria-graphql" %% "sangria" % "2.0.0-RC1",
1010
"io.circe" %% "circe-core" % circeVersion,
1111
"io.circe" %% "circe-jackson28" % circeVersion,
1212
"org.typelevel" %% "cats-core" % catsVersion,
1313
"org.typelevel" %% "cats-testkit" % catsVersion % Test,
14-
"org.scalaj" %% "scalaj-http" % "2.3.0",
15-
"org.scalameta" %% "scalameta" % "4.0.0",
16-
"org.scalatest" %% "scalatest" % "3.0.5" % Test
14+
"org.scalaj" %% "scalaj-http" % "2.4.2",
15+
"org.scalameta" %% "scalameta" % "4.3.9",
16+
"org.scalatest" %% "scalatest" % "3.1.1" % Test,
17+
"org.typelevel" %% "cats-testkit-scalatest" % "1.0.1" % Test
1718
)
1819

1920
// scripted test settings

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.6
1+
sbt.version=1.3.10

src/main/scala/rocks/muki/graphql/codegen/ApolloSourceGenerator.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,22 @@ case class ApolloSourceGenerator(
8383
val data =
8484
operation.selection.fields.flatMap(selectionStats(_, List.empty))
8585

86-
// render the document into the query object.
87-
// replacing single $ with $$ for escaping
88-
val escapedDocumentString =
89-
operation.original.renderPretty.replaceAll("\\$", "\\$\\$")
86+
// render the operation into the query object.
87+
val operationString =
88+
operation.original.renderPretty
9089

9190
// add the fragments to the query as well
92-
val escapedFragmentString = Option(document.original.fragments)
91+
val fragmentsString = Option(document.original.fragments)
9392
.filter(_.nonEmpty)
9493
.map { fragments =>
9594
fragments.values
96-
.map(_.renderPretty.replaceAll("\\$", "\\$\\$"))
95+
.map(_.renderPretty)
9796
.mkString("\n\n", "\n", "")
9897
}
9998
.getOrElse("")
10099

101-
val documentString = escapedDocumentString + escapedFragmentString
100+
// render the document into the query object
101+
val documentString = operationString + fragmentsString
102102
val graphqlDocument = Term.Interpolate(
103103
Term.Name("graphql"),
104104
Lit.String(documentString) :: Nil,

src/main/scala/rocks/muki/graphql/package.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package object graphql {
2828
val gqlSchema = graphqlSchemas.value
2929
val labels = gqlSchema.schemas.map(_.label)
3030
// create a dependent parser. A label can only be selected once
31-
schemaLabelParser(labels).map(label => schemaOrError(label, gqlSchema))
31+
schemaLabelParser(labels).flatMap(label => schemaOrError(label, gqlSchema))
3232
}
3333

3434
/**
@@ -41,8 +41,8 @@ package object graphql {
4141
// create a depended parser. A label can only be selected once
4242
schemaLabelParser(labels).flatMap {
4343
case selectedLabel if labels.contains(selectedLabel) =>
44-
success(schemaOrError(selectedLabel, gqlSchemas)) ~ schemaLabelParser(labels.filterNot(_ == selectedLabel))
45-
.map(label => schemaOrError(label, gqlSchemas))
44+
schemaOrError(selectedLabel, gqlSchemas) ~ schemaLabelParser(labels.filterNot(_ == selectedLabel))
45+
.flatMap(label => schemaOrError(label, gqlSchemas))
4646
case selectedLabel =>
4747
failure(s"$selectedLabel is not available. Use: [${labels.mkString(" | ")}]")
4848
}
@@ -57,7 +57,9 @@ package object graphql {
5757
token(Space.? ~> schemaParser)
5858
}
5959

60-
private def schemaOrError(label: String, graphQLSchema: GraphQLSchemas): GraphQLSchema =
61-
graphQLSchema.schemaByLabel.getOrElse(label, sys.error(s"The schema '$label' is not defined in graphqlSchemas"))
62-
60+
private def schemaOrError(label: String, graphQLSchema: GraphQLSchemas): Parser[GraphQLSchema] =
61+
graphQLSchema.schemaByLabel
62+
.get(label)
63+
.map(success(_))
64+
.getOrElse(failure(s"The schema '$label' is not defined in graphqlSchemas"))
6365
}

src/sbt-test/codegen/generate-schema-and-code/build.sbt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ scalaVersion in ThisBuild := "2.12.4"
66
val server = project
77
.enablePlugins(GraphQLSchemaPlugin)
88
.settings(
9-
libraryDependencies += "org.sangria-graphql" %% "sangria" % "1.4.2",
9+
libraryDependencies += "org.sangria-graphql" %% "sangria" % "2.0.0-RC1",
1010
graphqlSchemaSnippet :=
1111
"com.example.starwars.TestSchema.StarWarsSchema"
1212
)
@@ -21,9 +21,12 @@ val client = project
2121
)
2222

2323
TaskKey[Unit]("check") := {
24-
val files = (graphqlCodegen in client).value
24+
val files = (graphqlCodegen in client).value
2525

26-
assert(files.length == 1, s"Sangria code should only generated one file, but got ${files.length}.\n${files.mkString("\n")}")
26+
assert(
27+
files.length == 1,
28+
s"Sangria code should only generated one file, but got ${files.length}.\n${files.mkString("\n")}"
29+
)
2730

2831
val file = files.head
2932
assert(file.exists, s"$file could not be found")

src/sbt-test/schema/schema-snippet/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ enablePlugins(GraphQLSchemaPlugin, GraphQLQueryPlugin)
55
graphqlSchemaSnippet := "example.ProductSchema.schema"
66

77
libraryDependencies ++= Seq(
8-
"org.sangria-graphql" %% "sangria" % "1.4.2",
9-
"org.sangria-graphql" %% "sangria-circe" % "1.1.0"
8+
"org.sangria-graphql" %% "sangria" % "2.0.0-RC1",
9+
"org.sangria-graphql" %% "sangria-circe" % "1.3.0"
1010
)

src/sbt-test/validation/query/build.sbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ enablePlugins(GraphQLSchemaPlugin, GraphQLQueryPlugin)
55
graphqlSchemaSnippet := "example.ProductSchema.schema"
66

77
libraryDependencies ++= Seq(
8-
"org.sangria-graphql" %% "sangria" % "1.4.2",
9-
"org.sangria-graphql" %% "sangria-circe" % "1.1.0"
10-
)
8+
"org.sangria-graphql" %% "sangria" % "2.0.0-RC1",
9+
"org.sangria-graphql" %% "sangria-circe" % "1.3.0"
10+
)
11+

src/sbt-test/validation/schema/build.sbt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ enablePlugins(GraphQLSchemaPlugin, GraphQLQueryPlugin)
55
graphqlSchemaSnippet := "example.ProductSchema.schema"
66

77
libraryDependencies ++= Seq(
8-
"org.sangria-graphql" %% "sangria" % "1.4.2",
9-
"org.sangria-graphql" %% "sangria-circe" % "1.1.0"
8+
"org.sangria-graphql" %% "sangria" % "2.0.0-RC1",
9+
"org.sangria-graphql" %% "sangria-circe" % "1.3.0"
1010
)
1111

1212
graphqlSchemas += GraphQLSchema(
1313
"product-schema",
1414
"fixed schema at schemas/product.graphql",
15-
Def.task(
16-
GraphQLSchemaLoader
17-
.fromFile(baseDirectory.value / "schemas" / "product.graphql")
18-
.loadSchema()
19-
).taskValue
15+
Def
16+
.task(
17+
GraphQLSchemaLoader
18+
.fromFile(baseDirectory.value / "schemas" / "product.graphql")
19+
.loadSchema()
20+
)
21+
.taskValue
2022
)
2123

2224
graphqlSchemas += GraphQLSchema(
2325
"product-schema-broken",
2426
"fixed schema at schemas/product-broken.graphql",
25-
Def.task(
26-
GraphQLSchemaLoader
27-
.fromFile(baseDirectory.value / "schemas" / "product-broken.graphql")
28-
.loadSchema()
29-
).taskValue
30-
)
27+
Def
28+
.task(
29+
GraphQLSchemaLoader
30+
.fromFile(baseDirectory.value / "schemas" / "product-broken.graphql")
31+
.loadSchema()
32+
)
33+
.taskValue
34+
)
35+

src/sbt-test/validation/schema/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# validation should fail with the broken.graphql file
22
> graphqlValidateSchema build product-schema
3-
-> graphqlValidateSchema build product-schema-broken
3+
-> graphqlValidateSchema build product-schema-broken

0 commit comments

Comments
 (0)