-
-
Notifications
You must be signed in to change notification settings - Fork 821
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
mergeTypeDefs
does not preserve repeated directives
#4767
Comments
Thanks for creating this issue! If anyone is interested, PRs are welcome! |
Investigating this now, and hoping you can validate my thinking. Taking the test "should append and extend directives" from const merged = mergeTypeDefs([
`directive @id(primitiveArg: String, arrayArg: [String]) on FIELD_DEFINITION`,
`type MyType { id: Int }`,
`type MyType { id: Int @id }`,
`type MyType { id: Int @id(primitiveArg: "1") }`,
`type MyType { id: Int @id(primitiveArg: "1", arrayArg: ["1"]) }`,
`type MyType { id: Int @id(arrayArg: ["2"]) }`,
`type Query { f1: MyType }`,
]); This results in output: type MyType {
id: Int @id(primitiveArg: "1", arrayArg: ["1", "2"])
} I think this makes sense given that they are all object definitions. This gets tricky when it comes to object extensions, say if we just make one of the definitions above an extension: const merged = mergeTypeDefs([
`directive @id(primitiveArg: String, arrayArg: [String]) on FIELD_DEFINITION`,
`type MyType { id: Int }`,
`type MyType { id: Int @id }`,
`type MyType { id: Int @id(primitiveArg: "1") }`,
`type MyType { id: Int @id(primitiveArg: "1", arrayArg: ["1"]) }`,
`extend type MyType { id: Int @id(arrayArg: ["2"]) }`,
`type Query { f1: MyType }`,
]); What should the output be here? In my opinion, this should result in the following output: type MyType {
id: Int @id(primitiveArg: "1", arrayArg: ["1"]) @id(arrayArg: ["2"])
} Essentially, evaluating the object type definitions first, merging the arguments, and then evaluating the object extensions, adding them as separate directives. I would appreciate your thoughts! |
I faced with the same problem. @darrellwarde I think we shouldn't do deep merge arguments. And I guess current behaviour treats that every directive isn't @ardatan, what do you think? I can take it to do a PR |
@ardatan @darrellwarde I've made a PR for this issue. Could you please review it #5216 |
Thanks for the PR! Merged it! |
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
When merging type definitions using
mergeTypeDefs
, multiple of the same directive on a type are not preserved - only the last takes precedence.To Reproduce
Steps to reproduce the behavior:
Run the following code:
The following type definitions are printed in the console:
Expected behavior
I would expect the output to be:
Environment:
@graphql-tools/merge
: 8.3.6Additional context
I have another observation around the argument
convertExtensions
- it sounds to me like if set tofalse
, this would preserve extensions in the type definitions. However, if running the following code (same as above with added option):The output is identical to above, when I would expect it to be:
I realise this is a different issue, but figured it was worth mentioning here!
The text was updated successfully, but these errors were encountered: