Created
December 3, 2015 16:29
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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