Repository navigation
Use grackle's parser in the gql macro - #864
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
There was a problem hiding this comment.
🟡 Changes recommended
Splice validation, operation scoping, nested type compatibility, and parser depth limits can produce invalid acceptance or rejection.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Uses Grackle to validate gql documents and variable definitions at compile time.
Changes:
- Replaces custom parsing with Grackle AST helpers.
- Adds parser and interpolation tests.
- Removes
stripMargin, adds Grackle dependency, and bumps the base version.
File summaries
| File | Description |
|---|---|
README.md |
Documents compile-time parsing and removed stripMargin. |
Demo.scala |
Updates multiline GraphQL documents. |
GraphQLInterpolatorSuite.scala |
Expands macro tests. |
GraphQLDocumentsSuite.scala |
Tests new AST helpers. |
GraphQLInterpolator.scala |
Integrates Grackle parsing. |
GraphQLDocuments.scala |
Adds document and type helpers. |
build.sbt |
Adds Grackle and bumps version. |
Review details
- Files reviewed: 6/7 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| val doc: Ast.Document = | ||
| parseOrAbort( | ||
| GraphQLDocuments.placeholderDocument(parts), | ||
| Position.ofMacroExpansion, | ||
| msg => s"gql: $msg" | ||
| ) |
| def headerVariables(doc: Ast.Document): Map[String, Ast.Type] = | ||
| doc | ||
| .collect { case op: Ast.OperationDefinition.Operation => op } | ||
| .flatMap(_.variables) | ||
| .map(v => v.name.value -> v.tpe) | ||
| .toMap |
| def usableAs(declared: Ast.Type, required: Ast.Type): Boolean = { | ||
| def stripNonNull(tpe: Ast.Type): Ast.Type = tpe match { | ||
| case Ast.Type.NonNull(of) => of.merge | ||
| case other => other | ||
| } | ||
|
|
||
| stripNonNull(declared) == stripNonNull(required) && | ||
| (!required.isInstanceOf[Ast.Type.NonNull] || declared.isInstanceOf[Ast.Type.NonNull]) | ||
| } |
| private val parser: GraphQLParser = | ||
| GraphQLParser(GraphQLParser.defaultConfig.copy(terseError = false)) |
| def parseOrAbort(text: String, pos: Position, describe: String => String): Ast.Document = | ||
| parser.parseText(text) match { | ||
| case Result.Success(doc) => doc | ||
| case Result.Warning(_, doc) => doc |
There was a problem hiding this comment.
Should these be reported as compile warnings?
There was a problem hiding this comment.
Good catch. Addressed in new commit. grackle's compiler never seems to emit warnings today, but we future-proof.
|
All of copilot's concerns are valid and addressed in new commit. |
Instead of parsing ourselves in the gql macro, we now use grackle.
We are pulling grackle-core as a dependency for the moment. Hopefully 🤞 , typelevel/grackle#947 gets accepted and we can scale down to a parser-only dependency.