Reputation: 21
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!
Upvotes: 2
Views: 418
Reputation: 26586
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
)
Upvotes: 2