-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: main
Are you sure you want to change the base?
Conversation
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 1 changed, 0 removed
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), |
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.
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?
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.
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.
fc9a885
to
b027d26
Compare
( | ||
k.operation_id.clone(), | ||
v.clone(), | ||
"PersistedQuery".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.
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.
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.
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(), |
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.
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, |
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.
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.
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 4 changed, 0 removed
Build ID: 0a350881bcb441a8446f5f08 URL: https://www.apollographql.com/docs/deploy-preview/0a350881bcb441a8446f5f08 |
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