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 1
1
{
2
2
"name" : " graphql-js-tree" ,
3
- "version" : " 0.3.7 " ,
3
+ "version" : " 0.3.8 " ,
4
4
"private" : false ,
5
5
"license" : " MIT" ,
6
6
"description" : " GraphQL Parser providing simplier structure" ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export interface ParserField {
15
15
directives : ParserField [ ] ;
16
16
description ?: string ;
17
17
fromInterface ?: string [ ] ;
18
+ fromLibrary ?: boolean ;
18
19
value ?: {
19
20
type : Value ;
20
21
value ?: string ;
Original file line number Diff line number Diff line change @@ -3,11 +3,13 @@ import { Parser } from '@/Parser';
3
3
import { isExtensionNode } from '@/TreeOperations/shared' ;
4
4
import { TreeToGraphQL } from '@/TreeToGraphQL' ;
5
5
6
+ const addFromLibrary = ( n : ParserField ) : ParserField => ( { ...n , fromLibrary : true } ) ;
7
+
6
8
const mergeNode = ( n1 : ParserField , n2 : ParserField ) => {
7
9
const mergedNode = {
8
10
...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 ) ] ,
11
13
interfaces : [ ...n1 . interfaces , ...n2 . interfaces ] ,
12
14
} as ParserField ;
13
15
//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' ;
2
3
import { expectTrimmedEqual } from '@/__tests__/TestUtils' ;
3
4
4
5
// const mergingErrorSchema = `
@@ -81,6 +82,37 @@ describe('Merging GraphQL Schemas', () => {
81
82
}` ,
82
83
) ;
83
84
} ) ;
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
+ } ) ;
84
116
it ( 'Should merge interfaces and implementation of both nodes' , ( ) => {
85
117
const baseSchema = `
86
118
type Person implements Node{
You can’t perform that action at this time.
0 commit comments