Skip to content

Conversation

pubmodmatt
Copy link

@pubmodmatt pubmodmatt commented Jul 8, 2025

Add options to minify the type information returned by the introspect and search 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:

introspection:
  introspect:
    enabled: true
    minify: true
  search:
    enabled: true
    minify: true

For the top level Query type in the weather example schema, the original SDL was:

type Query {
  """Get the weather forecast for a coordinate"""
  forecast(coordinate: InputCoordinate!): Forecast
  """Get the weather alerts for a state"""
  alerts(
    """The two-letter state abbreviation (e.g., 'CO' for Colorado)"""
    state: String!,
  ): [Alert]
}

Minified, this becomes:

T:Query:"Gettheweatherforecastforacoordinate"forecast(InputCoordinate!):Forecast,"Gettheweatheralertsforastate"alerts("Thetwo-letterstateabbreviation(e.g.,'CO'forColorado)"state:s!):[Alert]

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.

@pubmodmatt pubmodmatt self-assigned this Jul 8, 2025
@apollo-librarian
Copy link

apollo-librarian bot commented Jul 8, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/apollo-mcp-server/(latest)/quickstart.mdx

Build ID: 872015a8b89f2bc681480b37

URL: https://www.apollographql.com/docs/deploy-preview/872015a8b89f2bc681480b37

@pubmodmatt pubmodmatt force-pushed the pubmodmatt/minify branch from 807d9ec to 1f899a1 Compare July 8, 2025 15:35
@alocay
Copy link
Contributor

alocay commented Jul 8, 2025

Do you have any estimate on how much this reduces the instrospect return value by?

@pubmodmatt
Copy link
Author

pubmodmatt commented Jul 8, 2025

Do you have any estimate on how much this reduces the instrospect return value by?

I've updated the PR description with some examples.

@pubmodmatt pubmodmatt force-pushed the pubmodmatt/minify branch from 1f899a1 to 0b38bcf Compare July 8, 2025 18:55
}

impl MinifyExt for ExtendedType {
fn minify(&self) -> String {
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Author

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.

@pubmodmatt pubmodmatt force-pushed the pubmodmatt/minify branch from ed604d7 to 8776475 Compare July 9, 2025 16:39
@pubmodmatt pubmodmatt marked this pull request as ready for review July 9, 2025 20:24
@pubmodmatt pubmodmatt requested review from a team as code owners July 9, 2025 20:24
Matthew Hawkins added 5 commits July 9, 2025 17:32
# 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
Matthew Hawkins added 6 commits July 16, 2025 09:12
# 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
@pubmodmatt pubmodmatt enabled auto-merge (squash) July 16, 2025 20:04
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()
Copy link
Contributor

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?

Copy link
Author

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.

@pubmodmatt pubmodmatt merged commit 3c10c1e into main Jul 18, 2025
7 checks passed
@DaleSeo DaleSeo deleted the pubmodmatt/minify branch August 25, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants