Sangria middleware to log slow GraphQL queries

98 views
Skip to first unread message

ram...@spineor.com

unread,
Aug 23, 2017, 3:27:10 AM8/23/17
to sangria-graphql

Hi, I am trying to integrate Sangria middleware to log slow GraphQL queries in my application but getting the following compilation error:


type mismatch;

found : sangria.schema.Schema[models.UserRepo,Unit]

required: sangria.schema.Schema[Any,Unit]

Note: models.UserRepo <: Any, but class Schema is invariant in type Ctx.

You may wish to define Ctx as +Ctx instead. (SLS 4.5)

Error occurred in an application involving default arguments.


**code snippet**

val Query = ObjectType("Query", List[Field[UserRepo, Unit]]

(Field("store", StoreType, resolve = _ ⇒ ()) ))

val schema = Schema(Query, Some(MutationType))


val logResult = Executor.execute(SchemaDefinition.schema,

query.asInstanceOf[Document], middleware = SlowLog(newlogger,

threshold = 10 seconds) :: Nil)


Here is the reference link :

https://github.com/sangria-graphql/sangria-slowlog


Kindly help me to know what is a proper signature of Executor.execute(​​​????) and to typecast  query "(val query = "g.V().has('BaseModel','YearID','" + year + "').out('make').dedup()")"  to document type.


How to fixed above type mismatch issues


Thanks!

Peter Hunsberger

unread,
Aug 23, 2017, 11:58:26 PM8/23/17
to sangria-graphql
I think you need to change your Field type to Field[Any,Unit], (I've been forced to always use [Any, Any] to get everything to line up every where...), I don't see that you are passing in a UserRepo on the execute method?

It looks like you are targeting some DB that uses Gremlin with your query?  That will be done in a method that you need to point to as the target of resolve, in the Execute step you have a graphql query that you use as the document.

ram...@spineor.com

unread,
Aug 24, 2017, 2:55:45 AM8/24/17
to sangria-graphql
Thanks for your response & help @Peter

Now I am using this:
val SchemaDefinition.schema : Schema[UserRepo, Unit]= Schema(Query, Some(MutationType))
val query = "g.V().has('BaseVehicle','YearID','" + year + "').out('make').dedup()"
Executor.execute(SchemaDefinition.schema, query.asInstanceOf[Document], UserRepo.this, middleware = SlowLog(logger2, threshold = 10 seconds) :: Nil)

When I execute my query : -
{
  store {
    makes(year: "1999") {
      value
    }
  }
}

Getting response : -
{
  "data": null,
  "errors": [
    {
      "message": "Internal server error",
      "path": [
        "store",
        "makes"
      ],
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    }
  ]
}

And on IntelliJ console  showing : -
java.lang.ClassCastException: java.lang.String cannot be cast to sangria.ast.Document.

Please suggest me how to cast a String to Document or any other solution to fix this.

 Thanks !!

Oleg Ilyenko

unread,
Aug 24, 2017, 3:52:21 AM8/24/17
to sangria-graphql

Ramraj Yadav

unread,
Aug 28, 2017, 6:12:52 AM8/28/17
to Oleg Ilyenko, sangria-graphql
Thanks!

Now fixed that by using:

Executor.execute(SchemaDefinition.schema, queryAst, new UserRepo(ws),middleware = SlowLog(logger, threshold = 0 seconds) :: Nil, operationName = operation,  variables = variables getOrElse Json.obj(),  maxQueryDepth = Some(10))

--
You received this message because you are subscribed to a topic in the Google Groups "sangria-graphql" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sangria-graphql/_ZUa8cBjQrU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sangria-graphql+unsubscribe@googlegroups.com.
To post to this group, send email to sangria-graphql@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sangria-graphql/1b433442-87e9-4a8a-b19c-ddfe54e43d9e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages