@@ -27,25 +27,57 @@ fun BufferedSource.toSchema(filePath: String? = null): Schema = parseAsGQLDocume
27
27
* See [parseAsGQLDocument] and [validateAsExecutable] for more granular error reporting
28
28
*/
29
29
@ApolloExperimental
30
- fun BufferedSource.toExecutableDefinitions (schema : Schema , filePath : String? = null, fieldsOnDisjointTypesMustMerge : Boolean = true): List <GQLDefinition > = parseAsGQLDocument(filePath)
30
+ fun BufferedSource.toExecutableDefinitions (
31
+ schema : Schema ,
32
+ filePath : String? = null,
33
+ fieldsOnDisjointTypesMustMerge : Boolean = true,
34
+ ): List <GQLDefinition > = parseAsGQLDocument(filePath)
31
35
.getOrThrow()
32
36
.validateAsExecutable(schema, fieldsOnDisjointTypesMustMerge)
33
37
.getOrThrow()
34
38
35
- private fun <T : Any > BufferedSource.parseInternal (filePath : String? , withSourceLocation : Boolean , block : Parser .() -> T ): GQLResult <T > {
39
+ private fun <T : Any > BufferedSource.parseInternal (filePath : String? , withSourceLocation : Boolean , block : Parser .() -> T ): GQLResult <T > {
36
40
return try {
37
41
GQLResult (Parser (this .use { it.readUtf8() }, withSourceLocation, filePath).block(), emptyList())
38
42
} catch (e: ParserException ) {
39
- GQLResult (null , listOf (Issue .ParsingError (e.message, SourceLocation (e.token.line, e.token.column, - 1 , - 1 , filePath))))
43
+ GQLResult (
44
+ null ,
45
+ listOf (
46
+ Issue .ParsingError (
47
+ e.message,
48
+ SourceLocation (
49
+ start = e.token.start,
50
+ end = e.token.end,
51
+ line = e.token.line,
52
+ column = e.token.column,
53
+ filePath = filePath
54
+ )
55
+ )
56
+ )
57
+ )
40
58
} catch (e: LexerException ) {
41
- GQLResult (null , listOf (Issue .ParsingError (e.message, SourceLocation (e.line, e.column, - 1 , - 1 , filePath))))
59
+ GQLResult (
60
+ null ,
61
+ listOf (
62
+ Issue .ParsingError (
63
+ e.message,
64
+ SourceLocation (
65
+ start = e.pos,
66
+ end = e.pos + 1 ,
67
+ line = e.line,
68
+ column = e.column,
69
+ filePath = filePath
70
+ )
71
+ )
72
+ )
73
+ )
42
74
}
43
75
}
44
76
45
77
class ParserOptions (
46
78
val useAntlr : Boolean = false ,
47
79
val allowEmptyDocuments : Boolean = true ,
48
- val withSourceLocation : Boolean = true
80
+ val withSourceLocation : Boolean = true ,
49
81
) {
50
82
companion object {
51
83
val Default = ParserOptions ()
@@ -96,7 +128,7 @@ fun BufferedSource.parseAsGQLValue(filePath: String? = null, options: ParserOpti
96
128
* Closes [BufferedSource]
97
129
*/
98
130
@ApolloExperimental
99
- fun BufferedSource.parseAsGQLType (filePath : String? = null, options : ParserOptions = ParserOptions .Default ): GQLResult <GQLType > {
131
+ fun BufferedSource.parseAsGQLType (filePath : String? = null, options : ParserOptions = ParserOptions .Default ): GQLResult <GQLType > {
100
132
return if (options.useAntlr) {
101
133
parseTypeWithAntlr(this , filePath)
102
134
} else {
@@ -110,7 +142,10 @@ fun BufferedSource.parseAsGQLType(filePath: String? = null, options: ParserOptio
110
142
* Closes [BufferedSource]
111
143
*/
112
144
@ApolloExperimental
113
- fun BufferedSource.parseAsGQLSelections (filePath : String? = null, options : ParserOptions = ParserOptions .Default ): GQLResult <List <GQLSelection >> {
145
+ fun BufferedSource.parseAsGQLSelections (
146
+ filePath : String? = null,
147
+ options : ParserOptions = ParserOptions .Default ,
148
+ ): GQLResult <List <GQLSelection >> {
114
149
return if (options.useAntlr) {
115
150
parseSelectionsWithAntlr(this , filePath)
116
151
} else {
@@ -164,7 +199,7 @@ fun GQLDocument.validateAsExecutable(schema: Schema, fieldsOnDisjointTypesMustMe
164
199
fun GQLFragmentDefinition.inferVariables (
165
200
schema : Schema ,
166
201
fragments : Map <String , GQLFragmentDefinition >,
167
- fieldsOnDisjointTypesMustMerge : Boolean
202
+ fieldsOnDisjointTypesMustMerge : Boolean ,
168
203
) = ExecutableValidationScope (schema, fragments, fieldsOnDisjointTypesMustMerge).inferFragmentVariables(this )
169
204
170
205
0 commit comments