Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4: Add code generator #15

Merged
merged 21 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rocks.muki.graphql

import rocks.muki.graphql.releasenotes.MarkdownReleaseNotes
import rocks.muki.graphql.schema.SchemaLoader
import sangria.schema._
import sbt._
Expand Down
65 changes: 45 additions & 20 deletions test-project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
name := "graphql-test-project"

version := "0.4"
lazy val root = project.in(file("."))
.aggregate(server, client)

enablePlugins(GraphQLSchemaPlugin, GraphQLQueryPlugin)
lazy val server = project.in(file("server"))
.enablePlugins(GraphQLSchemaPlugin, GraphQLQueryPlugin)
.configs(IntegrationTest)
.settings(commonSettings, Defaults.itSettings)
.settings(
graphqlSchemaSnippet := "example.StarWarsSchema.schema",
// integration settings
graphqlQueryDirectory in IntegrationTest := (sourceDirectory in IntegrationTest).value / "graphql"
)
.settings(
addCommandAlias("validateSangriaExample", "graphqlValidateSchema build sangria-example")
)

libraryDependencies ++= Seq(
"org.sangria-graphql" %% "sangria" % "1.3.0",
"org.sangria-graphql" %% "sangria-circe" % "1.1.0"
)

graphqlSchemaSnippet := "example.StarWarsSchema.schema"
lazy val client = project.in(file("client"))
.enablePlugins(GraphQLCodegenPlugin, GraphQLQueryPlugin)
.settings(commonSettings)
.settings(
graphqlCodegenSchema := graphqlRenderSchema.toTask("starwars").value,
resourceDirectories in graphqlCodegen := List(
(sourceDirectory in Compile).value / "graphql",
),
graphqlCodegenPackage := "rocks.muki.graphql",
name in graphqlCodegen := "Api",
// includeFilter in graphqlCodegen := "product.graphql"
)

graphqlSchemas += GraphQLSchema(
"sangria-example",
"staging schema at http://try.sangria-graphql.org/graphql",
Def.task(
GraphQLSchemaLoader
.fromIntrospection("http://try.sangria-graphql.org/graphql", streams.value.log)
.withHeaders("User-Agent" -> "sbt-graphql/${version.value}")
.loadSchema()
).taskValue
lazy val commonSettings = Seq(
version := "0.4",
scalaVersion := "2.12.4",
organization := "rocks.muki",
libraryDependencies ++= Seq(
"org.sangria-graphql" %% "sangria" % "1.3.2",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to expose the sangria version used by the plugin for projects that want to keep them in sync?

"org.sangria-graphql" %% "sangria-circe" % "1.1.0"
),
// define schemas available in all builds
graphqlSchemas += GraphQLSchema(
"starwars",
"starwars schema at http://try.sangria-graphql.org/graphql",
Def.task(
GraphQLSchemaLoader
.fromIntrospection("http://try.sangria-graphql.org/graphql", streams.value.log)
.withHeaders("User-Agent" -> s"sbt-graphql/${version.value}")
.loadSchema()
).taskValue
)
)

addCommandAlias("validateSangriaExample", "graphqlValidateSchema build sangria-example")
8 changes: 8 additions & 0 deletions test-project/server/src/it/graphql/heroAndFriends.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query HeroAndFriends {
hero {
name
friends {
name
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object ProductSchema {
Field("width", IntType, resolve = _.value.width),
Field("height", IntType, resolve = _.value.height),
Field("url", OptionType(StringType),
description = Some("Picture CDN URL"),
resolve = _.value.url)))
description = Some("Picture CDN URL"),
resolve = _.value.url)))

val IdentifiableType = InterfaceType(
"Identifiable",
Expand Down Expand Up @@ -69,4 +69,3 @@ class ProductRepo {

def products: List[Product] = Products
}