-
Notifications
You must be signed in to change notification settings - Fork 45
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
Current design of returning fragment definitions by name prevents duplicate detection #545
Comments
We do check for fragment duplicates here1. We don't, however, do it specifically for fragments, it's all just kind of done in one go. We should probably split that up between executable validation and type system validation, so executable validation can be run in isolation. Here is an example with a duplicate fragment: type Query {
pet: Pet
}
interface Pet {
name: String!
}
type Dog implements Pet {
name: String!
barkVolume: Int
}
query UseAllFragments {
pet {
... dogFragment
}
}
fragment dogFragment on Dog {
... on Dog {
barkVolume
}
}
fragment dogFragment on Dog {
... on Dog {
barkVolume
}
} and here is what the diagnostic looks like: Footnotes |
Alternatively, I think it would be most useful if there was some access to To that end, simply making the source AST accessible from outside the compiler would be sufficient for addressing the bulk of use cases that I'm referring to. |
Depending on "how raw" you want definitions, I think the AST may be more appropriate for some tasks. It can be accessed like this: use apollo_compiler::database::AstDatabase;
// make a `compiler` and `file_id`
let ast = compiler.db.ast(file_id);
for def in ast.document().definitions() {
// …
} |
I will close this issue, as we've redesigned the compiler with the |
To expand a bit more on this, the 1.0 API is centered on high-level document For use cases not satisfied by this, the lower-level AST is also provided. There, every collection is a |
Description
There are currently a number of validations applied to fragment definitions but the current implementation does not detect that each fragment for each name must be unique1. It's not possible to add this validation to
validate_fragment_definitions
2 because fragment queries all normalize definitions by name.I propose modifying
all_fragments
to return a flatArc<Vec<FragmentDefinition>
and rename the current implementation toall_fragments_by_name
. The same should apply to thefragments(file_id)
version of the methods.Footnotes
"https://spec.graphql.org/draft/#sec-Fragment-Name-Uniqueness.Formal-Specification" ↩
"https://github.com/apollographql/apollo-rs/blob/main/crates/apollo-compiler/src/validation/fragment.rs#L218" ↩
The text was updated successfully, but these errors were encountered: