Skip to content

fix: Indicate filename for operations files that error while loading #119

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

swcollard
Copy link

When we hit an error while loading operation files we are not currently including which file contained the error in the messaging. This change propagates the path alongside the operation so that if we hit one of the several errors in the operation parsing we can display which file it is associated with.

Updated unit tests and validated with a few examples

Multiple operations in single file error

➜  cargo build && ./target/debug/apollo-mcp-server \
     --directory ./graphql/TheSpaceDevs \
     --schema api.graphql \
     --operations operations/ExploreCelestialBodies.graphql operations/ExploreCelestialBodies2.graphql \
     --endpoint https://thespacedevs-production.up.railway.app/ \
     --http-port 5000 \
     --http-address 127.0.0.1

Error: Failed to create operation: operations/ExploreCelestialBodies2.graphql: Too many operations. Expected 1 but got 2

Caused by:
    operations/ExploreCelestialBodies2.graphql: Too many operations. Expected 1 but got 2

No operation name error

➜  cargo build && ./target/debug/apollo-mcp-server \
     --directory ./graphql/TheSpaceDevs \
     --schema api.graphql \
     --operations operations/ExploreCelestialBodies.graphql operations/ExploreCelestialBodies3.graphql \
     --endpoint https://thespacedevs-production.up.railway.app/ \
     --http-port 5000 \
     --http-address 127.0.0.1

2025-06-05T14:26:24.697796Z  INFO Apollo MCP Server v0.3.0 // (c) Apollo Graph, Inc. // Licensed as ELv2 (https://go.apollo.dev/elv2)
2025-06-05T14:26:24.721298Z  INFO Tool ExploreCelestialBodies loaded with a character count of 759. Estimated tokens: 189
Error: Failed to create operation: operations/ExploreCelestialBodies3.graphql: Operation is missing its required name: query($search: String, $limit: Int = 10, $offset: Int = 0) { bodies: celestialBodies(search: $search, limit: $limit, offset: $offset) { pageInfo { count next previous } results { id name diameter mass gravity lengthOfDay atmosphere type { id name } image { url thumbnail credit } description wikiUrl } } }

Caused by:
    operations/ExploreCelestialBodies3.graphql: Operation is missing its required name: query($search: String, $limit: Int = 10, $offset: Int = 0) { bodies: celestialBodies(search: $search, limit: $limit, offset: $offset) { pageInfo { count next previous } results { id name diameter mass gravity lengthOfDay atmosphere type { id name } image { url thumbnail credit } description wikiUrl } } }

@swcollard swcollard requested a review from a team as a code owner June 5, 2025 14:37
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Jun 5, 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)/index.mdx

Build ID: 26d7da08ef235ffe5d074a29

URL: https://www.apollographql.com/docs/deploy-preview/26d7da08ef235ffe5d074a29

#[error("Operation is missing its required name: {0}")]
MissingName(String),
#[error("{0}: Operation is missing its required name: {1}")]
MissingName(PathBuf, String),
Copy link
Contributor

Choose a reason for hiding this comment

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

sources could be files/manifest file/operation collection/uplink, I think this only makes sense for files and the other sources will end up printing : Operation is missing its required name: which is a bit weird. Maybe instead of having this be PathBuf we could make it a more generic String that can be set to anything like the file name, the operation collection operation name (different then the operation name), and then I guess the manifest file name or uplink?

Copy link
Author

Choose a reason for hiding this comment

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

Agree Jeffrey. That makes sense, I'll make the path non-optional and move it to a String so it gets populated by each method.

@swcollard swcollard force-pushed the swcollard/operation-error-file-name branch from fc9a885 to b027d26 Compare June 5, 2025 21:30
(
k.operation_id.clone(),
v.clone(),
"PersistedQuery".to_string(),
Copy link
Author

Choose a reason for hiding this comment

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

I couldn't find anything in the actual manifest that was more human readable to call out as the source of the operation. Repeating the ID didn't feel quite right either so I just put "PersistedQuery" as a placeholder.

There is also a separate conversation of whether it makes sense to update this RawOperation interface to include the path, but I didn't see another way to pass the Path down to where the operations are parsed and errors are thrown.

Copy link
Contributor

Choose a reason for hiding this comment

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

It adds no value to the UpdateManifest event to include the hard-coded "PersistedQuery" string. I'd move this to the point where you convert UpdateManifest to a RawOperation, and insert the hard-coded string there, if needed.

(
k.operation_id.clone(),
v.clone(),
"PersistedQuery".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.

It adds no value to the UpdateManifest event to include the hard-coded "PersistedQuery" string. I'd move this to the point where you convert UpdateManifest to a RawOperation, and insert the hard-coded string there, if needed.

@@ -168,6 +191,7 @@ pub struct RawOperation {
persisted_query_id: Option<String>,
headers: Option<HeaderMap<HeaderValue>>,
variables: Option<HashMap<String, Value>>,
source_path: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

A source_path doesn't make sense for cases other than local operation files or manifest files. It should be optional. In general, when designing Rust types, you should try to make it impossible to create invalid data. Having an empty source path is invalid - either it should have a path, or specify that there is no path for this operation, which is the case Option is made for.

@apollo-librarian
Copy link

apollo-librarian bot commented Jun 9, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 4 changed, 0 removed
* (developer-tools)/apollo-mcp-server/(latest)/command-reference.mdx
* (developer-tools)/apollo-mcp-server/(latest)/index.mdx
* (developer-tools)/apollo-mcp-server/(latest)/licensing.mdx
* (developer-tools)/apollo-mcp-server/(latest)/guides/index.mdx

Build ID: 0a350881bcb441a8446f5f08

URL: https://www.apollographql.com/docs/deploy-preview/0a350881bcb441a8446f5f08

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.

5 participants