GraphQL Schema中如何将联合类型声明拆分为多行?
Absolutely! You absolutely can split each type in your union declaration onto its own line—this is actually a recommended practice for keeping your schema readable and easy to maintain, especially as you plan to add more types later.
GraphQL’s syntax doesn’t enforce all union members to be on a single line. Here’s how you can rewrite your SectionUnion for better readability:
union SectionUnion = SectionForm | Section2 | Section3 | Section4 | Section5
Or if you prefer placing the pipe (|) at the start of each line (a style some teams favor for consistency), that works perfectly too:
union SectionUnion = SectionForm | Section2 | Section3 | Section4 | Section5
Either format will be correctly parsed by all GraphQL tools. The key is to pick a style your team agrees on and stick with it—this way, when you add new types like Section6 or Section7 later, you just append a new line instead of cramming everything into one unwieldy line that’s hard to scan.
This approach is a lifesaver for large schemas where unions can grow to include dozens of member types over time.
内容的提问来源于stack exchange,提问作者drupov

