Skip to content

Instantly share code, notes, and snippets.

@OlegIlyenko
Created December 3, 2015 16:29
Show Gist options
  • Save OlegIlyenko/863fe40b97e45ac30fb9 to your computer and use it in GitHub Desktop.
Save OlegIlyenko/863fe40b97e45ac30fb9 to your computer and use it in GitHub Desktop.
An example of GraphQL execution with Sangria which uses GraphQL input object notation for variables and execution results (no JSON is involved at any point)
import sangria.marshalling.queryAst._
import sangria.macros._
import sangria.ast
val query =
graphql"""
query MyQuery($$humanId: String!, $$episode: Episode!) {
hero(episode: $$episode) {
id, name, appearsIn
}
human(id: $$humanId) {
name
friends {
id
name
}
}
}
"""
val variables =
graphqlInput"""
{
humanId: "1003"
episode: NEWHOPE
}
"""
val result: Future[ast.Value] =
Executor.execute(StarWarsSchema, query,
userContext = new CharacterRepo,
deferredResolver = new FriendsResolver,
variables = variables)
val rendered: String =
QueryRenderer.render(result.await, QueryRenderer.PrettyInput)
println(rendered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment