-
Notifications
You must be signed in to change notification settings - Fork 38
Minify introspect return value #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 1 changed, 0 removed
Build ID: 872015a8b89f2bc681480b37 URL: https://www.apollographql.com/docs/deploy-preview/872015a8b89f2bc681480b37 |
807d9ec
to
1f899a1
Compare
Do you have any estimate on how much this reduces the instrospect return value by? |
I've updated the PR description with some examples. |
1f899a1
to
0b38bcf
Compare
} | ||
|
||
impl MinifyExt for ExtendedType { | ||
fn minify(&self) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't understand the complex logic here... 😵
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately apollo-compiler
ergonomics generally result in a lot of code duplcation since the various types don't have traits in common. But this is really pretty simple - instead of using the ExtendedType.serialize()
method, which outputs the full GraphQL SDL, this alternative ExtendedType.minify()
method returns the smaller form for each type. So for each variant, it's building up the small string, which includes descriptions, field names, and arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaleSeo - I refactored the minify.rs
file to (hopefully) make it simpler to read and maintain.
ed604d7
to
8776475
Compare
# Conflicts: # crates/apollo-mcp-server/src/main.rs # crates/apollo-mcp-server/src/server.rs # crates/apollo-mcp-server/src/server/states.rs # crates/apollo-mcp-server/src/server/states/starting.rs
# Conflicts: # crates/apollo-mcp-server/src/introspection/tools/search.rs # crates/apollo-mcp-server/src/runtime/introspection.rs # crates/apollo-mcp-server/src/server/states/starting.rs
minify: bool, | ||
) -> String { | ||
if minify { | ||
"Get GraphQL type information - T=type,I=input,E=enum,U=union,F=interface;s=String,i=Int,f=Float,b=Boolean,d=ID;!=required,[]=list,<>=implements;".to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how the LLM knows how to un-minify to execute actual queries? Or does it not need that information because the type and field names are unchanged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly! This tiny bit of text is all the model needs to undo the minification. A big caveat here is that I haven't done extensive testing of this across different models, and only really tested with Claude Sonnet 4. Smaller models may struggle with it. I consider this feature to be experimental for that reason. There are other ways more detailed decoding information could be given to a model, such as through resources or system prompts. Or if the spec for the minified format were publicly documented, eventually models would have it as part of their training.
Add options to minify the type information returned by the
introspect
andsearch
tools. This emulates the GSL format defined here in Rust. This removes extraneous whitespace and braces, and shortens built-in type names and keywords. It also currently removes directives, though these may be considered useful to the LLM in some cases.To enable minification, turn on the
minify
option in the config file, for example:For the top level Query type in the weather example schema, the original SDL was:
Minified, this becomes:
This reduces the size from 272 -> 190 bytes, about a 30% reduction.
For a more real-world example, the
Repository
type in the GitHub schema went from 35322 -> 24418 bytes, about a 31% reduction.