Skip to content

Commit 944ff91

Browse files
author
Håkan Rosenhorn
committed
Basic reflection invocation of resolve method
1 parent 42d494d commit 944ff91

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package se.uprise.graphql.execution
2+
3+
import se.uprise.graphql.error.GraphQLError
4+
import se.uprise.graphql.types.{GraphQLScalarType, GraphQLNonNull}
5+
import se.uprise.parser.GraphQlParser.{VariableContext, ValueContext, ValueOrVariableContext}
6+
7+
object CoerceValueAST {
8+
9+
// def apply(valueAST: ValueOrVariableContext, variables: Map[String, Any]) = {
10+
// valueAST.value() match {
11+
// case entry: ValueContext => this(entry, variables)
12+
// case _ =>
13+
// valueAST.variable() match {
14+
// case entry: VariableContext => this(entry, variables)
15+
// case _ => throw new GraphQLError("Tried to CoerceValueAST on unknown value", List(valueAST))
16+
// }
17+
// }
18+
// }
19+
20+
// def apply(valueAST: ValueContext, variables: Map[String, Any]) = {
21+
//
22+
// }
23+
//
24+
// def apply(valueAST: VariableContext, variables: Map[String, Any]) = {
25+
//
26+
// }
27+
28+
// FIXME: Better type on variables
29+
def apply(valueAST: GraphQLScalarType, variables: Map[String, Any]) = {
30+
31+
}
32+
//def apply(valueAST: GraphQLNonNull)
33+
}

src/main/scala/se/uprise/graphql/execution/Executor.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ object Executor {
8989
fields: Map[String, List[FieldContext]]): Any = {
9090

9191
val finalResults = fields.keys.foldLeft(Map[String, Any]())((results: Map[String, Any], responseName) => {
92-
println("TJOHEJ")
93-
9492
val fieldASTs = fields(responseName)
9593
val result = resolveField(exeContext, parentType, source, fieldASTs)
9694
// fields ++ Map(name -> merged)
@@ -120,15 +118,16 @@ object Executor {
120118
val fieldDef = getFieldDef(exeContext.schema, parentType, fieldAST)
121119
//val args: List[universe.Type] = resolveFn.typeSignature.typeArgs
122120

121+
val parentTypeMirror = universe.runtimeMirror(getClass.getClassLoader).reflect(parentType)
123122

124123
val args = extractor.getArgumentValues(
125124
fieldDef.args,
126125
fieldAST.arguments(),
127126
exeContext.variables)
128127

129-
// Some dynamic reflection invocation on the resolve method symbol
130-
//parentType.
131-
128+
//val resolveFn = fieldDef.resolve
129+
val result = parentTypeMirror.reflectMethod(fieldDef.resolve)()
130+
result
132131
}
133132

134133
/**
@@ -178,7 +177,6 @@ object Executor {
178177
fields: Map[String, List[FieldContext]] = Map.empty,
179178
visitedFragmentNames: Map[String, Boolean] = Map.empty): Map[String, List[FieldContext]] = {
180179

181-
182180
selectionSet.selection().foldLeft(fields)((result, selection) =>
183181

184182
// Check for field

src/main/scala/se/uprise/graphql/execution/ValueExtractor.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package se.uprise.graphql.execution
22

33
import se.uprise.graphql.types.{GraphQLFieldArgument, GraphQLInputType, GraphQLSchema}
4-
import se.uprise.parser.GraphQlParser.{VariableDefinitionContext, ArgumentsContext}
4+
import se.uprise.parser.GraphQlParser.{ValueOrVariableContext, VariableDefinitionContext, ArgumentsContext}
55

66
import scala.reflect.runtime._
77
import scala.collection.JavaConversions._
@@ -13,24 +13,26 @@ object ValueExtractor {
1313
* definitions and list of argument AST nodes.
1414
*/
1515
// FIXME: Better Type for variables (guessing some decendant of InputType)
16-
def getArgumentValues(argDefs: List[GraphQLFieldArgument[_ <: GraphQLInputType]],
16+
def getArgumentValues(argDefs: List[GraphQLFieldArgument[_ <: GraphQLInputType]] = List.empty,
1717
argASTs: ArgumentsContext,
18-
variables: Map[String, Any]) = {
19-
20-
21-
//val finalResults = fields.keys.foldLeft(Map[String, Any]())((results: Map[String, Any], responseName) => {
22-
23-
// FIXME: Can we get null here?
24-
val argASTMap = argASTs.argument().toList.map({ entry =>
25-
val valueOrVariable = entry.valueOrVariable()
26-
entry.NAME().getText -> valueOrVariable
27-
}).toMap
28-
29-
argDefs.foldLeft(Map[String, Any]())((results: Map[String, Any], argDef: GraphQLFieldArgument[_ <: GraphQLInputType]) => {
18+
variables: Map[String, Any]): Map[String, GraphQLInputType] = {
19+
20+
// Avoid null pointer
21+
val argASTMap = Option(argASTs) match {
22+
case Some(value) => value.argument().toList.map({ entry =>
23+
val valueOrVariable = entry.valueOrVariable()
24+
entry.NAME().getText -> valueOrVariable
25+
}).toMap
26+
case None => Map[String, ValueOrVariableContext]()
27+
}
28+
29+
argDefs.foldLeft(Map[String, GraphQLInputType]())((results: Map[String, GraphQLInputType], argDef: GraphQLFieldArgument[_ <: GraphQLInputType]) => {
3030
val name = argDef.name
3131
val valueAST = argASTMap(name)
3232

33-
//results ++ Map(name -> coerceValueAST(argDef.), valueAST, variables))
33+
throw new Exception("FIXME: Implement")
34+
//results ++ Map(name -> CoerceValueAST(valueAST, variables))
35+
results// ++ Map(name -> null)
3436
})
3537

3638

src/test/scala/se/uprise/graphql/BasicTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import se.uprise.graphql.starwars.StarWars
66
class BasicTest extends FunSuite {
77
test("SchemaTest") {
88
// FIXME: Implement a basic test
9-
val foo = """query HeroNameQuery { human }"""
9+
val foo = """query HeroNameQuery { hero }"""
1010
val slask: GraphQLResult = GraphQL(StarWars.schema, foo, None, Map.empty, "")
1111
slask
1212

src/test/scala/se/uprise/graphql/starwars/StarWars.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class Query extends GraphQLObjectType {
9898
override def getFields(entry: GraphQLObjectType): Map[String, GraphQLFieldDefinition] = {
9999
val fields = this.getClassFields(this)
100100

101+
101102
Map(
102103
"hero" -> new GraphQLFieldDefinition("hero", "desc", List.empty, fields("hero"), ""),
103104
"human" -> new GraphQLFieldDefinition(

0 commit comments

Comments
 (0)