2

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(​​​????)

Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

2

I think the main issue is that you've defined the schema in terms of UserRepo, but you haven't provided it at the execution time. I guess adding a userContext argument should fix the issue:

Executor.execute(SchemaDefinition.schema, query,
  userContext = new UserRepo,
  middleware = SlowLog(newlogger, threshold = 10 seconds) :: Nil)

I also made this test to check the types (these types are similar to your scenario), but it compiles just fine:

val schema: Schema[Repo, Unit] = ???
val md: Middleware[Any] = ???

Executor.execute(schema, query, new Repo, middleware = md :: Nil)

If it still does not compile, I would suggest you to provide complete self-contains example that reproduces the issue. (for instance, in your example you don't show the type of MutationType)

tenshi
  • 26,268
  • 8
  • 76
  • 90
  • Now I am using this: Executor.execute(SchemaDefinition.schema, query.asInstanceOf[Document], UserRepo.this, middleware = SlowLog(logger2, threshold = 10 seconds) :: Nil) – user8504370 Aug 24 '17 at 06:01
  • And when I run a query: { store { makes(year: "1999") { value } } } , On my terminal getting this prblem: Java.lang.ClassCastException: java.lang.String cannot be cast to sangria.ast.Document, My query format is : val query = "g.V().has('BaseVehicle','YearID','" + year + "').out('make').dedup()" – user8504370 Aug 24 '17 at 06:02
  • And response is : { "data": null, "errors": [ { "message": "Internal server error", "path": [ "store", "makes" ], "locations": [ { "line": 3, "column": 5 } ] } ] } , Please suggest me how to cast a String to Document or any other solution to fix this, Thanks !! – user8504370 Aug 24 '17 at 06:12
  • Or What is the format of query which is to pass in Executer.execute(,query,..) – user8504370 Aug 24 '17 at 07:30
  • I would suggest you to check out the [getting started tutorial](http://sangria-graphql.org/getting-started/) and documentation about [query parsing](http://sangria-graphql.org/learn/#query-parser-and-renderer) – tenshi Aug 24 '17 at 07:49