File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -33,10 +33,18 @@ pub(crate) fn validate_field(
3333
3434 super :: argument:: validate_arguments ( diagnostics, & field. arguments ) ;
3535
36- // Return early if we don't know the type--this can happen if we are nested deeply
37- // inside a selection set that has a wrong field, or if we are validating a standalone
38- // operation without a schema.
36+ // If we don't know the type (no schema, or invalid parent), we cannot perform
37+ // type-aware checks for this field. However, for standalone executable validation
38+ // we still want to traverse into the nested selection set so that validations
39+ // that do not require a schema (like missing fragment detection) can run.
3940 let Some ( ( schema, against_type) ) = against_type else {
41+ super :: selection:: validate_selection_set (
42+ diagnostics,
43+ document,
44+ None ,
45+ & field. selection_set ,
46+ context,
47+ ) ;
4048 return ;
4149 } ;
4250
Original file line number Diff line number Diff line change @@ -352,3 +352,33 @@ type TestObject {
352352 }"# ] ] ;
353353 expected. assert_eq ( & actual) ;
354354}
355+
356+ #[ test]
357+ fn missing_fragment_in_standalone_validation ( ) {
358+ let input = r#"
359+ query {
360+ company {
361+ user {
362+ ...UserFragment
363+ }
364+
365+ ...CompanyFragment
366+ }
367+ }
368+
369+ fragment UserFragment on User {
370+ id
371+ name
372+ }
373+ "# ;
374+
375+ let doc = ast:: Document :: parse ( input, "query.graphql" ) . unwrap ( ) ;
376+ let diagnostics = doc
377+ . validate_standalone_executable ( )
378+ . expect_err ( "should report missing fragment error" ) ;
379+ let errors = diagnostics. to_string ( ) ;
380+ assert ! (
381+ errors. contains( "cannot find fragment `CompanyFragment` in this document" ) ,
382+ "{errors}"
383+ ) ;
384+ }
You can’t perform that action at this time.
0 commit comments