diff --git a/src/core/config/from_document.rs b/src/core/config/from_document.rs index 50ee61153e..c6ebe4ae75 100644 --- a/src/core/config/from_document.rs +++ b/src/core/config/from_document.rs @@ -246,10 +246,10 @@ where .fuse(Cache::from_directives(directives.iter())) .fuse(to_fields(fields)) .fuse(Protected::from_directives(directives.iter())) - .map(|(resolver, cache, fields, protected)| { + .fuse(to_add_fields_from_directives(directives)) + .map(|(resolver, cache, fields, protected, added_fields)| { let doc = description.to_owned().map(|pos| pos.node); let implements = implements.iter().map(|pos| pos.node.to_string()).collect(); - let added_fields = to_add_fields_from_directives(directives); config::Type { fields, added_fields, @@ -410,19 +410,16 @@ fn to_enum(enum_type: EnumType, doc: Option) -> Valid { fn to_add_fields_from_directives( directives: &[Positioned], -) -> Vec { - directives - .iter() - .filter_map(|directive| { - if directive.node.name.node == config::AddField::directive_name() { - config::AddField::from_directive(&directive.node) - .to_result() - .ok() - } else { - None - } - }) - .collect::>() +) -> Valid, String> { + Valid::from_iter( + directives + .iter() + .filter(|v| v.node.name.node == config::AddField::directive_name()), + |directive| { + let val = config::AddField::from_directive(&directive.node).to_result(); + Valid::from(val) + }, + ) } trait HasName { diff --git a/tests/core/snapshots/test-invalid-add-field.md_error.snap b/tests/core/snapshots/test-invalid-add-field.md_error.snap new file mode 100644 index 0000000000..89c8031f06 --- /dev/null +++ b/tests/core/snapshots/test-invalid-add-field.md_error.snap @@ -0,0 +1,15 @@ +--- +source: tests/core/spec.rs +expression: errors +--- +[ + { + "message": "Parsing failed because of invalid type: string \"{{.value.user.username}}\", expected a sequence", + "trace": [ + "PostUser", + "@addField", + "path" + ], + "description": null + } +] diff --git a/tests/execution/test-invalid-add-field.md b/tests/execution/test-invalid-add-field.md new file mode 100644 index 0000000000..cba10bd145 --- /dev/null +++ b/tests/execution/test-invalid-add-field.md @@ -0,0 +1,31 @@ +--- +error: true +--- + +# Test invalid add fields + +```graphql @config +schema @server(port: 8000) @upstream(baseURL: "http://jsonplaceholder.typicode.com") { + query: Query +} + +type Query { + postuser: [PostUser] @http(path: "/posts") +} + +type PostUser @addField(name: "username", path: "{{.value.user.username}}") { + id: Int! @modify(name: "postId") + title: String! + userId: Int! + user: User @http(baseURL: "https://jsonplaceholder.typicode.com", path: "/users/{{.value.userId}}") +} + +type User { + id: Int! + name: String! + username: String! + email: String! + phone: String + website: String +} +```