Skip to content

Commit 8d4e128

Browse files
committed
🦺 Parse tree
1 parent 8e93d96 commit 8d4e128

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/TreeOperations/merge.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export const mergeTrees = (tree1: ParserTree, tree2: ParserTree) => {
3232
const errors: Array<{ conflictingNode: string; conflictingField: string }> = [];
3333
// merge nodes
3434
tree1.nodes.forEach((t1n) => {
35-
const matchingNode = tree2.nodes.find((t2n) => t2n.name === t1n.name && t1n.data.type === t2n.data.type);
35+
const matchingNode = tree2.nodes
36+
.filter((t) => t.data.type !== TypeSystemDefinition.SchemaDefinition)
37+
.find((t2n) => t2n.name === t1n.name && t1n.data.type === t2n.data.type);
3638
if (matchingNode) {
3739
if (isExtensionNode(matchingNode.data.type)) {
3840
t1n.args.forEach((t1nA) => {

src/__tests__/TreeOperations/merge.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,44 @@ describe('Merging GraphQL Schemas', () => {
189189
`,
190190
);
191191
});
192+
it('Should merge schemas but maintain original schema node', () => {
193+
const baseSchema = `
194+
type DDD{
195+
firstName: String
196+
health: String
197+
}
198+
schema{
199+
query: DDD
200+
}
201+
`;
202+
203+
const mergingSchema = `
204+
type Query{
205+
lastName: String
206+
}
207+
type Mutation{
208+
ddd: String
209+
}
210+
`;
211+
const t1 = mergeSDLs(baseSchema, mergingSchema);
212+
if (t1.__typename === 'error') throw new Error('Invalid parse');
213+
expectTrimmedEqual(
214+
t1.sdl,
215+
`
216+
type DDD{
217+
firstName: String
218+
health: String
219+
}
220+
schema{
221+
query: DDD
222+
}
223+
type Query{
224+
lastName: String
225+
}
226+
type Mutation{
227+
ddd: String
228+
}
229+
`,
230+
);
231+
});
192232
});

0 commit comments

Comments
 (0)