forked from pgutkowski/KGraphQL
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from aPureBase/new-parser
New parser
- Loading branch information
Showing
140 changed files
with
5,951 additions
and
2,390 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,4 @@ open class FunctionExecutionBenchmark { | |
setup() | ||
println(benchmarkFunctionExecution()) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
14 changes: 13 additions & 1 deletion
14
src/main/kotlin/com/apurebase/kgraphql/ExecutionException.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
package com.apurebase.kgraphql | ||
|
||
import com.apurebase.kgraphql.schema.execution.Execution | ||
import com.apurebase.kgraphql.schema.model.ast.ASTNode | ||
|
||
class ExecutionException(message: String, cause: Throwable? = null) : Exception(message, cause) | ||
class ExecutionException( | ||
message: String, | ||
node: ASTNode? = null, | ||
cause: Throwable? = null | ||
) : GraphQLError( | ||
message, | ||
nodes = node?.let(::listOf), | ||
originalError = cause | ||
) { | ||
constructor(message: String, node: Execution, cause: Throwable? = null): this(message, node.selectionNode, cause) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.apurebase.kgraphql | ||
|
||
import com.apurebase.kgraphql.schema.model.ast.ASTNode | ||
import com.apurebase.kgraphql.schema.model.ast.Location.Companion.getLocation | ||
import com.apurebase.kgraphql.schema.model.ast.Source | ||
|
||
open class GraphQLError( | ||
|
||
/** | ||
* A message describing the Error for debugging purposes. | ||
*/ | ||
message: String, | ||
|
||
/** | ||
* An array of GraphQL AST Nodes corresponding to this error. | ||
*/ | ||
val nodes: List<ASTNode>? = null, | ||
|
||
/** | ||
* The source GraphQL document for the first location of this error. | ||
* | ||
* Note that if this Error represents more than one node, the source may not | ||
* represent nodes after the first node. | ||
*/ | ||
val source: Source? = null, | ||
|
||
/** | ||
* An array of character offsets within the source GraphQL document | ||
* which correspond to this error. | ||
*/ | ||
val positions: List<Int>? = null, | ||
|
||
/** | ||
* The original error thrown from a field resolver during execution. | ||
*/ | ||
val originalError: Throwable? = null | ||
) : Exception(message) { | ||
|
||
constructor(message: String, node: ASTNode?) : this(message, nodes = node?.let(::listOf)) | ||
|
||
/** | ||
* An array of { line, column } locations within the source GraphQL document | ||
* that correspond to this error. | ||
* | ||
* Errors during validation often contain multiple locations, for example to | ||
* point out two things with the same name. Errors during execution include a | ||
* single location, the field that produced the error. | ||
*/ | ||
val locations: List<Source.LocationSource>? by lazy { | ||
if (positions != null && source != null) { | ||
positions.map { pos -> getLocation(source, pos) } | ||
} else nodes?.mapNotNull { node -> | ||
node.loc?.let { getLocation(it.source, it.start) } | ||
} | ||
} | ||
|
||
fun prettyPrint(): String { | ||
var output = message ?: "" | ||
|
||
if (nodes != null) { | ||
for (node in nodes) { | ||
if (node.loc != null) { | ||
output += "\n\n" + node.loc!!.printLocation() | ||
} | ||
} | ||
} else if (source != null && locations != null) { | ||
for (location in locations!!) { | ||
output += "\n\n" + source.print(location) | ||
} | ||
} | ||
|
||
return output | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package com.apurebase.kgraphql | ||
|
||
import com.apurebase.kgraphql.schema.model.ast.ASTNode | ||
|
||
class ValidationException(message: String, cause: Throwable? = null) : RequestException(message, cause) | ||
class ValidationException(message: String, nodes: List<ASTNode>? = null): GraphQLError(message, nodes = nodes) |
11 changes: 0 additions & 11 deletions
11
src/main/kotlin/com/apurebase/kgraphql/request/Arguments.kt
This file was deleted.
Oops, something went wrong.
20 changes: 11 additions & 9 deletions
20
src/main/kotlin/com/apurebase/kgraphql/request/CachingDocumentParser.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
package com.apurebase.kgraphql.request | ||
|
||
import com.apurebase.kgraphql.schema.model.ast.DocumentNode | ||
import com.github.benmanes.caffeine.cache.Caffeine | ||
|
||
|
||
class CachingDocumentParser(cacheMaximumSize : Long = 1000L) : DocumentParser() { | ||
class CachingDocumentParser(cacheMaximumSize : Long = 1000L) { | ||
|
||
sealed class Result { | ||
class Success(val operations :List<Operation>) : Result() | ||
class Success(val document: DocumentNode) : Result() | ||
class Exception(val exception: kotlin.Exception) : Result() | ||
} | ||
|
||
val cache = Caffeine.newBuilder().maximumSize(cacheMaximumSize).build<String, Result>() | ||
|
||
override fun parseDocument(input: String): List<Operation> { | ||
val result = cache.get(input, { | ||
fun parseDocument(input: String): DocumentNode { | ||
val result = cache.get(input) { | ||
val parser = Parser(input) | ||
try { | ||
Result.Success(super.parseDocument(input)) | ||
Result.Success(parser.parseDocument()) | ||
} catch ( e : Exception){ | ||
Result.Exception(e) | ||
} | ||
}) | ||
} | ||
|
||
when (result) { | ||
is Result.Success -> return result.operations | ||
is Result.Success -> return result.document | ||
is Result.Exception -> throw result.exception | ||
else -> { | ||
cache.invalidateAll() | ||
throw IllegalStateException("Internal error of CachingDocumentParser") | ||
} | ||
} | ||
} | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
src/main/kotlin/com/apurebase/kgraphql/request/Document.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.