-
Notifications
You must be signed in to change notification settings - Fork 86
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
[Feature] Tools: Schema Merge #1632
base: main
Are you sure you want to change the base?
Conversation
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.
one comment, but code looks solid overall. might be worth adding a more robust test for the actual functionality, however.
let ast = parser.parse(); | ||
let doc = ast.document(); | ||
|
||
for def in doc.definitions() { |
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.
Dumb question- does apollo-parser automatically aggregate multiple definitions together? Meaning, if I have:
type User @key(fields:"id") {
id: ID!
name: String!
}
and
type User @key(fields:"id") {
id: ID!
username: String!
}
Would I get a combo of both, an error, or one of them?
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 quick test suggests you will get both of them.
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.
Amazing, thanks for testing!
impl Merge { | ||
pub fn run(&self) -> RoverResult<RoverOutput> { | ||
// find files by extension | ||
let schemas = self.find_files_by_extensions(self.options.schemas.clone(), &["graphql", "gql"])?; |
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 think some folks also use .graphqls
extension for schemas and .graphql
for operations. Technically folks could define their schemas using any extension they want so unsure if there is a need to capture all of them (that being said .graphqls
is somewhat common).
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.
good catch. might be worth allowing users to use a custom extension as a flag in that case
Maybe a basic question but this is just doing "dumb" schema merging, right? This doesn't do full Federation composition? Or maybe a better question, what is the intended user use case? For someone working one a single subgraph or client that has the type defs spread across multiple files and would be valid if they all just lived in on file? OR Trying to do a merging of multiple schema files into one valid subgraph file, while doing some type and directive composition? |
Thats correct, this just merges schema files. It's intentionally dumb - ie low-level file manipulation. But it reads and writes the schema files using apollo-rs parser/encoder.
Yes, the inputs should already be valid schema files - just split up into multiple files.
That could be something we add as an enhancement, maybe throw warnings about it but not prevent merging of the files. |
Ok(result) | ||
} | ||
|
||
fn merge_schemas_into_one(&self, schemas: Vec<PathBuf>) -> RoverResult<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.
not for this PR, but something to consider in the future is that we'd want to validate that all these files getting merged are semantically valid (with apollo-compiler). the compiler now has multi-file support, so you can just add them all to a compiler instance and validate.
This adds a
tools
command for manipulating schema files.It also adds a
tools merge
subcommand to merge multiple.graphql/.gql
files together into a single file. (implemented with apollo-rs 🎉 )It outputs the merged schema as rover command result.
Example: