File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " graphql-js-tree" ,
3- "version" : " 0.3.7 " ,
3+ "version" : " 0.3.8 " ,
44 "private" : false ,
55 "license" : " MIT" ,
66 "description" : " GraphQL Parser providing simplier structure" ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export interface ParserField {
1515 directives : ParserField [ ] ;
1616 description ?: string ;
1717 fromInterface ?: string [ ] ;
18+ fromLibrary ?: boolean ;
1819 value ?: {
1920 type : Value ;
2021 value ?: string ;
Original file line number Diff line number Diff line change @@ -3,11 +3,13 @@ import { Parser } from '@/Parser';
33import { isExtensionNode } from '@/TreeOperations/shared' ;
44import { TreeToGraphQL } from '@/TreeToGraphQL' ;
55
6+ const addFromLibrary = ( n : ParserField ) : ParserField => ( { ...n , fromLibrary : true } ) ;
7+
68const mergeNode = ( n1 : ParserField , n2 : ParserField ) => {
79 const mergedNode = {
810 ...n1 ,
9- args : [ ...n1 . args , ...n2 . args ] ,
10- directives : [ ...n1 . directives , ...n2 . directives ] ,
11+ args : [ ...n1 . args , ...n2 . args . map ( addFromLibrary ) ] ,
12+ directives : [ ...n1 . directives , ...n2 . directives . map ( addFromLibrary ) ] ,
1113 interfaces : [ ...n1 . interfaces , ...n2 . interfaces ] ,
1214 } as ParserField ;
1315 //dedupe
Original file line number Diff line number Diff line change 1- import { mergeSDLs } from '@/TreeOperations/merge' ;
1+ import { Parser } from '@/Parser' ;
2+ import { mergeSDLs , mergeTrees } from '@/TreeOperations/merge' ;
23import { expectTrimmedEqual } from '@/__tests__/TestUtils' ;
34
45// const mergingErrorSchema = `
@@ -81,6 +82,37 @@ describe('Merging GraphQL Schemas', () => {
8182 }` ,
8283 ) ;
8384 } ) ;
85+ it ( 'Tree test - Should merge interfaces and implementation of both nodes matching library fields.' , ( ) => {
86+ const baseSchema = `
87+ type Person implements Node{
88+ firstName: String
89+ health: String
90+ _id: String
91+ }
92+ interface Node {
93+ _id: String
94+ }
95+ ` ;
96+
97+ const mergingSchema = `
98+ type Person implements Dateable{
99+ lastName: String
100+ createdAt: String
101+ }
102+ interface Dateable {
103+ createdAt: String
104+ }
105+ ` ;
106+ const baseTree = Parser . parse ( baseSchema ) ;
107+ const libraryTree = Parser . parse ( mergingSchema ) ;
108+ const mergedTree = mergeTrees ( baseTree , libraryTree ) ;
109+ if ( mergedTree . __typename === 'error' ) throw new Error ( 'Invalid parse' ) ;
110+ const PersonNode = mergedTree . nodes . find ( ( n ) => n . name === 'Person' ) ;
111+ const lastNameField = PersonNode ?. args . find ( ( a ) => a . name === 'lastName' ) ;
112+ const createdAtField = PersonNode ?. args . find ( ( a ) => a . name === 'createdAt' ) ;
113+ expect ( lastNameField ?. fromLibrary ) . toBeTruthy ( ) ;
114+ expect ( createdAtField ?. fromLibrary ) . toBeTruthy ( ) ;
115+ } ) ;
84116 it ( 'Should merge interfaces and implementation of both nodes' , ( ) => {
85117 const baseSchema = `
86118 type Person implements Node{
You can’t perform that action at this time.
0 commit comments