From 74731edfb9b0a59d98f75983ea0b76218421f989 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Sun, 17 Jul 2022 17:33:27 +0530 Subject: [PATCH] initial commit --- .gitignore | 32 +++++++++++++++++++ .scalafmt.conf | 22 +++++++++++++ README.md | 8 +++++ build.sbt | 17 ++++++++++ project/Dependencies.scala | 10 ++++++ project/build.properties | 1 + .../com/tusharmath/compose/Endpoint.scala | 8 +++++ .../com/tusharmath/compose/GraphQL.scala | 15 +++++++++ .../scala/com/tusharmath/compose/Main.scala | 7 ++++ .../com/tusharmath/compose/GraphQLSpec.scala | 9 ++++++ 10 files changed, 129 insertions(+) create mode 100644 .gitignore create mode 100644 .scalafmt.conf create mode 100644 README.md create mode 100644 build.sbt create mode 100644 project/Dependencies.scala create mode 100644 project/build.properties create mode 100644 src/main/scala/com/tusharmath/compose/Endpoint.scala create mode 100644 src/main/scala/com/tusharmath/compose/GraphQL.scala create mode 100644 src/main/scala/com/tusharmath/compose/Main.scala create mode 100644 src/test/scala/com/tusharmath/compose/GraphQLSpec.scala diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e79245 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# macOS +.DS_Store + +# sbt specific +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ +project/local-plugins.sbt +.history +.ensime +.ensime_cache/ +.sbt-scripted/ +local.sbt + +# Bloop +.bsp + +# VS Code +.vscode/ + +# Metals +.bloop/ +.metals/ +metals.sbt + +# IDEA +.idea +.idea_modules +/.worksheet/ diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..2905128 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,22 @@ +align.multiline = true +align.preset = more +align.stripMargin = true +assumeStandardLibraryStripMargin = true +continuationIndent.defnSite = 2 +danglingParentheses.preset = true +docstrings = JavaDoc +docstrings.style = Asterisk +docstrings.wrap = yes +docstrings.wrapMaxColumn = 80 +includeCurlyBraceInSelectChains = false +lineEndings = preserve +maxColumn = 120 +newlines.afterInfix = keep +optIn.annotationNewlines = true +rewrite.imports.sort = original +rewrite.rules = [Imports, RedundantBraces, SortModifiers] +rewrite.rules = [RedundantParens] +runner.dialect = scala213 +spaces.inImportCurlyBraces = false +trailingCommas = "always" +version = "3.5.3" diff --git a/README.md b/README.md new file mode 100644 index 0000000..102c5ca --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## sbt project compiled with Scala 3 + +### Usage + +This is a normal sbt project. You can compile code with `sbt compile`, run it with `sbt run`, and `sbt console` will start a Scala 3 REPL. + +For more information on the sbt-dotty plugin, see the +[scala3-example-project](https://github.com/scala/scala3-example-project/blob/main/README.md). diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..28b95e6 --- /dev/null +++ b/build.sbt @@ -0,0 +1,17 @@ +import Dependencies._ + +val scala3Version = "2.13.8" + +lazy val root = project + .in(file(".")) + .settings( + name := "GraphQLCompose", + version := "0.1.0-SNAPSHOT", + scalaVersion := scala3Version, + libraryDependencies := Seq( + ZIOCore, + ZIOSchema, + ZIOSchemaDerivation, + ZIOTest % Test, + ), + ) diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 0000000..aff39b6 --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,10 @@ +object Dependencies { + import sbt._ + val zioVersion = "2.0.0" + val zioSchemaVersion = "0.2.0" + + val ZIOCore = "dev.zio" %% "zio" % zioVersion + val ZIOTest = "dev.zio" %% "zio-test" % zioVersion + val ZIOSchema = "dev.zio" %% "zio-schema" % zioSchemaVersion + val ZIOSchemaDerivation = "dev.zio" %% "zio-schema-derivation" % zioSchemaVersion +} diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..22af262 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.7.1 diff --git a/src/main/scala/com/tusharmath/compose/Endpoint.scala b/src/main/scala/com/tusharmath/compose/Endpoint.scala new file mode 100644 index 0000000..71863fb --- /dev/null +++ b/src/main/scala/com/tusharmath/compose/Endpoint.scala @@ -0,0 +1,8 @@ +package com.tusharmath.compose + +final case class Endpoint(host: String, port: Int, path: String, body: Array[Byte], protocol: Protocol) + +sealed trait Protocol +object Protocol { + case class Http(method: String) extends Protocol +} diff --git a/src/main/scala/com/tusharmath/compose/GraphQL.scala b/src/main/scala/com/tusharmath/compose/GraphQL.scala new file mode 100644 index 0000000..cf66475 --- /dev/null +++ b/src/main/scala/com/tusharmath/compose/GraphQL.scala @@ -0,0 +1,15 @@ +package com.tusharmath.compose + +import zio.schema.Schema + +sealed trait GraphQL[-A, +B] {} + +object GraphQL { + case class Constant[B](b: B, schema: Schema[B]) extends GraphQL[Any, B] + case class Identity[A](schema: Schema[A]) extends GraphQL[A, A] + case class Compose[A, B, C](g: GraphQL[B, C], f: GraphQL[A, B]) extends GraphQL[A, C] + case class Zip2[A, B, C](g: GraphQL[A, B], f: GraphQL[A, C]) extends GraphQL[A, (B, C)] + case class Load[A](endpoint: Endpoint, schema: Schema[A]) extends GraphQL[Any, A] + + def constant[A](a: A)(implicit schema: Schema[A]): GraphQL[Any, A] = Constant(a, schema) +} diff --git a/src/main/scala/com/tusharmath/compose/Main.scala b/src/main/scala/com/tusharmath/compose/Main.scala new file mode 100644 index 0000000..53fd3b3 --- /dev/null +++ b/src/main/scala/com/tusharmath/compose/Main.scala @@ -0,0 +1,7 @@ +package com.tusharmath.compose + +object Main extends App { + def hello(): Unit = { + println("Hello!") + } +} diff --git a/src/test/scala/com/tusharmath/compose/GraphQLSpec.scala b/src/test/scala/com/tusharmath/compose/GraphQLSpec.scala new file mode 100644 index 0000000..e874ec6 --- /dev/null +++ b/src/test/scala/com/tusharmath/compose/GraphQLSpec.scala @@ -0,0 +1,9 @@ +package com.tusharmath.compose + +import com.tusharmath.compose.GraphQLSpec.test +import zio.test.{assertTrue, ZIOSpecDefault} + +object GraphQLSpec extends ZIOSpecDefault: + override def spec = test("Some test") { + assertTrue(true) + }