@@ -47,50 +47,92 @@ function wrapConcreteTypes(
4747 return document ;
4848 }
4949
50- const queryRootType = targetSchema . getQueryType ( ) ;
51- const mutationRootType = targetSchema . getMutationType ( ) ;
52- const subscriptionRootType = targetSchema . getSubscriptionType ( ) ;
53-
5450 const typeInfo = new TypeInfo ( targetSchema ) ;
5551 const newDocument = visit (
5652 document ,
5753 visitWithTypeInfo ( typeInfo , {
58- [ Kind . FIELD ] ( node : FieldNode ) {
59- const maybeType = typeInfo . getParentType ( ) ;
60- if ( maybeType == null ) {
61- return false ;
54+ [ Kind . FIELD ] : ( node : FieldNode ) => {
55+ if ( isAbstractType ( getNamedType ( typeInfo . getType ( ) ) ) ) {
56+ return {
57+ ...node ,
58+ selectionSet : {
59+ kind : Kind . SELECTION_SET ,
60+ selections : [
61+ {
62+ kind : Kind . INLINE_FRAGMENT ,
63+ typeCondition : {
64+ kind : Kind . NAMED_TYPE ,
65+ name : {
66+ kind : Kind . NAME ,
67+ value : namedType . name ,
68+ } ,
69+ } ,
70+ selectionSet : node . selectionSet ,
71+ } ,
72+ ] ,
73+ } ,
74+ } ;
6275 }
76+ } ,
77+ } ) ,
78+ // visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
79+ // empty keys cannot be removed only because of typescript errors
80+ // will hopefully be fixed in future version of graphql-js to be optional
81+ {
82+ Name : [ ] ,
6383
64- const parentType = getNamedType ( maybeType ) ;
65- if ( parentType !== queryRootType && parentType !== mutationRootType && parentType !== subscriptionRootType ) {
66- return false ;
67- }
84+ Document : [ 'definitions' ] ,
85+ OperationDefinition : [ 'selectionSet' ] ,
86+ VariableDefinition : [ ] ,
87+ Variable : [ ] ,
88+ SelectionSet : [ 'selections' ] ,
89+ Field : [ ] ,
90+ Argument : [ ] ,
6891
69- if ( ! isAbstractType ( getNamedType ( typeInfo . getType ( ) ) ) ) {
70- return false ;
71- }
92+ FragmentSpread : [ ] ,
93+ InlineFragment : [ 'selectionSet' ] ,
94+ FragmentDefinition : [ 'selectionSet' ] ,
7295
73- return {
74- ...node ,
75- selectionSet : {
76- kind : Kind . SELECTION_SET ,
77- selections : [
78- {
79- kind : Kind . INLINE_FRAGMENT ,
80- typeCondition : {
81- kind : Kind . NAMED_TYPE ,
82- name : {
83- kind : Kind . NAME ,
84- value : namedType . name ,
85- } ,
86- } ,
87- selectionSet : node . selectionSet ,
88- } ,
89- ] ,
90- } ,
91- } ;
92- } ,
93- } )
96+ IntValue : [ ] ,
97+ FloatValue : [ ] ,
98+ StringValue : [ ] ,
99+ BooleanValue : [ ] ,
100+ NullValue : [ ] ,
101+ EnumValue : [ ] ,
102+ ListValue : [ ] ,
103+ ObjectValue : [ ] ,
104+ ObjectField : [ ] ,
105+
106+ Directive : [ ] ,
107+
108+ NamedType : [ ] ,
109+ ListType : [ ] ,
110+ NonNullType : [ ] ,
111+
112+ SchemaDefinition : [ ] ,
113+ OperationTypeDefinition : [ ] ,
114+
115+ ScalarTypeDefinition : [ ] ,
116+ ObjectTypeDefinition : [ ] ,
117+ FieldDefinition : [ ] ,
118+ InputValueDefinition : [ ] ,
119+ InterfaceTypeDefinition : [ ] ,
120+ UnionTypeDefinition : [ ] ,
121+ EnumTypeDefinition : [ ] ,
122+ EnumValueDefinition : [ ] ,
123+ InputObjectTypeDefinition : [ ] ,
124+
125+ DirectiveDefinition : [ ] ,
126+
127+ SchemaExtension : [ ] ,
128+
129+ ScalarTypeExtension : [ ] ,
130+ ObjectTypeExtension : [ ] ,
131+ InterfaceTypeExtension : [ ] ,
132+ UnionTypeExtension : [ ] ,
133+ EnumTypeExtension : [ ] ,
134+ InputObjectTypeExtension : [ ] ,
135+ }
94136 ) ;
95137
96138 return newDocument ;
0 commit comments