@@ -2,6 +2,7 @@ import { astVisitor, VISITOR_REMOVE_NODE, VISITOR_SKIP_CHILDREN } from '../astVi
22import { directoryToAst , AstRootNode } from '../directoryToAst' ;
33import { astToSchema } from '../astToSchema' ;
44import { graphql } from 'graphql' ;
5+ import sortBy from 'lodash.sortby' ;
56
67describe ( 'astVisitor' , ( ) => {
78 let ast : AstRootNode ;
@@ -114,6 +115,59 @@ describe('astVisitor', () => {
114115 } ) ;
115116 } ) ;
116117
118+ describe ( 'visitFn should have path & operation & name properties' , ( ) => {
119+ it ( 'check ROOT_TYPE' , ( ) => {
120+ const nodes = [ ] as Array < any > ;
121+ astVisitor ( ast , {
122+ ROOT_TYPE : ( node , info ) => {
123+ nodes . push ( { operation : info . operation , name : info . name , path : info . path } ) ;
124+ } ,
125+ } ) ;
126+ expect ( sortBy ( nodes , [ 'operation' , 'name' ] ) ) . toEqual ( [
127+ { name : 'mutation' , operation : 'mutation' , path : [ ] } ,
128+ { name : 'query' , operation : 'query' , path : [ ] } ,
129+ ] ) ;
130+ } ) ;
131+
132+ it ( 'check DIR & FILE elements' , ( ) => {
133+ const nodes = [ ] as Array < any > ;
134+ astVisitor ( ast , {
135+ DIR : ( node , info ) => {
136+ nodes . push ( { operation : info . operation , name : info . name , path : info . path } ) ;
137+ } ,
138+ FILE : ( node , info ) => {
139+ nodes . push ( { operation : info . operation , name : info . name , path : info . path } ) ;
140+ } ,
141+ } ) ;
142+ expect ( sortBy ( nodes , [ 'operation' , 'name' ] ) ) . toEqual ( [
143+ { operation : 'mutation' , name : 'auth' , path : [ 'mutation' ] } ,
144+ { operation : 'mutation' , name : 'create' , path : [ 'mutation' , 'user' ] } ,
145+ { operation : 'mutation' , name : 'list' , path : [ 'mutation' , 'logs.nested' ] } ,
146+ { operation : 'mutation' , name : 'login' , path : [ 'mutation' , 'auth' ] } ,
147+ { operation : 'mutation' , name : 'logout' , path : [ 'mutation' , 'auth' ] } ,
148+ { operation : 'mutation' , name : 'logs.nested' , path : [ 'mutation' ] } ,
149+ { operation : 'mutation' , name : 'method' , path : [ 'mutation' , 'auth' , 'nested' ] } ,
150+ { operation : 'mutation' , name : 'nested' , path : [ 'mutation' , 'auth' ] } ,
151+ { operation : 'mutation' , name : 'update' , path : [ 'mutation' , 'user' ] } ,
152+ { operation : 'mutation' , name : 'user' , path : [ 'mutation' ] } ,
153+ { operation : 'query' , name : 'address.city' , path : [ 'query' , 'me' ] } ,
154+ { operation : 'query' , name : 'address.street' , path : [ 'query' , 'me' ] } ,
155+ { operation : 'query' , name : 'auth' , path : [ 'query' ] } ,
156+ { operation : 'query' , name : 'extendedData' , path : [ 'query' , 'user' ] } ,
157+ { operation : 'query' , name : 'field' , path : [ 'query' ] } ,
158+ { operation : 'query' , name : 'isLoggedIn' , path : [ 'query' , 'auth' ] } ,
159+ { operation : 'query' , name : 'me' , path : [ 'query' ] } ,
160+ { operation : 'query' , name : 'method' , path : [ 'query' , 'auth' , 'nested' ] } ,
161+ { operation : 'query' , name : 'name' , path : [ 'query' , 'me' ] } ,
162+ { operation : 'query' , name : 'nested' , path : [ 'query' , 'auth' ] } ,
163+ { operation : 'query' , name : 'roles' , path : [ 'query' , 'user' ] } ,
164+ { operation : 'query' , name : 'some.index' , path : [ 'query' ] } ,
165+ { operation : 'query' , name : 'some.nested' , path : [ 'query' ] } ,
166+ { operation : 'query' , name : 'user' , path : [ 'query' ] } ,
167+ ] ) ;
168+ } ) ;
169+ } ) ;
170+
117171 it ( 'try to wrap all mutations' , async ( ) => {
118172 const logs : any [ ] = [ ] ;
119173 astVisitor ( ast , {
0 commit comments