8000 Use grackle's parser in the gql macro by rpiaggio · Pull Request #864 · gemini-hlsw/clue · GitHub
[go: up one dir, main page]

Skip to content

Use grackle's parser in the gql macro - #864

Merged
rpiaggio merged 3 commits into
mainfrom
gql-with-parser
Sep 18, 2026
Merged

rpiaggio merged 3 commits into
mainfrom
gql-with-parser

Conversation

@rpiaggio
Copy link
Copy Markdown
Collaborator

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.

@mergify
mergify Bot commented Sep 12, 2026
Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +136 to +141
val doc: Ast.Document =
parseOrAbort(
GraphQLDocuments.placeholderDocument(parts),
Position.ofMacroExpansion,
msg => s"gql: $msg"
)
Comment on lines +40 to +45
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
Comment on lines +52 to +60
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])
}
Comment on lines +67 to +68
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be reported as compile warnings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Addressed in new commit. grackle's compiler never seems to emit warnings today, but we future-proof.

@rpiaggio
Copy link
Copy Markdown
Collaborator Author

All of copilot's concerns are valid and addressed in new commit.

@rpiaggio
rpiaggio merged commit fc88295 into main Sep 18, 2026
13 checks passed
@rpiaggio
rpiaggio deleted the gql-with-parser branch September 18, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0