Skip to content

Commit

Permalink
Merge pull request #2 from macalinao/add_extensions
Browse files Browse the repository at this point in the history
Fix 'addExtentions' typo
  • Loading branch information
OlegIlyenko authored Jan 11, 2018
2 parents f1ed259 + 2c19a3e commit 3448460
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ After middleware is added, you will see following JSON in the response:
}
```

All `SlowLog` methods accept `addExtentions` argument which allows you to include these extensions along the way.
All `SlowLog` methods accept `addExtensions` argument which allows you to include these extensions along the way.

With a small tweaking, you can also include "Profile" button in GraphiQL. On the server you just need to conditionally include
`SlowLog.extension` middleware to make it work. [Here is an example](https://youtu.be/OMa3SXC2mjA) of how this integration might look like.
Expand Down
18 changes: 9 additions & 9 deletions src/main/scala/sangria/slowlog/SlowLog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import sangria.schema.Context
import scala.collection.concurrent.TrieMap
import scala.concurrent.duration._

class SlowLog(logFn: Option[(Document, Option[String], Long) Unit], threshold: FiniteDuration, addExtentions: Boolean)(implicit renderer: MetricRenderer)
class SlowLog(logFn: Option[(Document, Option[String], Long) Unit], threshold: FiniteDuration, addExtensions: Boolean)(implicit renderer: MetricRenderer)
extends Middleware[Any] with MiddlewareAfterField[Any] with MiddlewareErrorField[Any] with MiddlewareExtension[Any] {
type QueryVal = QueryMetrics
type FieldVal = Long

private val thresholdNanos = threshold.toNanos

def beforeQuery(context: MiddlewareQueryContext[Any, _, _]) =
QueryMetrics(TrieMap.empty, TrieMap.empty, System.nanoTime(), addExtentions)
QueryMetrics(TrieMap.empty, TrieMap.empty, System.nanoTime(), addExtensions)

def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Any, _, _]) = ()

Expand All @@ -40,7 +40,7 @@ class SlowLog(logFn: Option[(Document, Option[String], Long) ⇒ Unit], threshol
if (durationNanos > thresholdNanos)
logFn.foreach(fn fn(updatedQuery, context.operationName, durationNanos))

if (addExtentions)
if (addExtensions)
Vector(queryVal.extension(
updatedQuery,
durationNanos,
Expand Down Expand Up @@ -79,14 +79,14 @@ object SlowLog {
private def renderLog(query: Document, operationName: Option[String], durationNanos: Long, separateOp: Boolean)(implicit renderer: MetricRenderer): String =
renderer.renderLogMessage(durationNanos, renderQueryForLog(query, operationName, separateOp))

def apply(logger: Logger, threshold: FiniteDuration, addExtentions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) logger.warn(renderLog(query, op, duration, separateOp))), threshold, addExtentions)
def apply(logger: Logger, threshold: FiniteDuration, addExtensions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) logger.warn(renderLog(query, op, duration, separateOp))), threshold, addExtensions)

def log(logFn: (Long, String) Unit, threshold: FiniteDuration, addExtentions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) logFn(duration, renderQueryForLog(query, op, separateOp))), threshold, addExtentions)
def log(logFn: (Long, String) Unit, threshold: FiniteDuration, addExtensions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) logFn(duration, renderQueryForLog(query, op, separateOp))), threshold, addExtensions)

def print(threshold: FiniteDuration = 0 seconds, addExtentions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) println(renderLog(query, op, duration,separateOp))), threshold, addExtentions)
def print(threshold: FiniteDuration = 0 seconds, addExtensions: Boolean = false, separateOp: Boolean = true)(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(Some((query, op, duration) println(renderLog(query, op, duration,separateOp))), threshold, addExtensions)

def extension(implicit renderer: MetricRenderer): SlowLog =
new SlowLog(None, 0 seconds, true)
Expand Down

0 comments on commit 3448460

Please sign in to comment.