11import Q from './q' ;
22
33function getFields ( info ) {
4- const fields = [ ] ;
5- info . fieldNodes [ 0 ] . selectionSet . selections . map ( ( value , key ) => {
6- if ( ! value . selectionSet ) fields . push ( value . name . value ) ;
4+ const fields : string [ ] = [ ] ;
5+ info . fieldNodes . map ( fieldNode => {
6+ if ( fieldNode . selectionSet ) {
7+ fieldNode . selectionSet . selections . map ( value => {
8+ if ( ! value . selectionSet ) fields . push ( value . name . value ) ;
9+ } ) ;
10+ }
711 } ) ;
812 return fields ;
913}
1014
11- function getWheres ( info : any ) : any [ ] {
12- const wheres = [ ] ;
13- info . fieldNodes [ 0 ] . arguments . map ( ( val , key ) => {
14- const field = val . name . value ;
15- const value = val . value . value ;
16- if ( field !== 'limit' ) {
17- wheres . push ( { field, value, operator : '=' } ) ;
18- }
15+ function getWheres ( info ) : any [ ] {
16+ const wheres : { field : string ; value : string ; operator : string } [ ] = [ ] ;
17+ info . fieldNodes . map ( fieldNode => {
18+ fieldNode . arguments . map ( val => {
19+ const field = val . name . value ;
20+ const value = val . value . value ;
21+ if ( field !== 'limit' ) {
22+ wheres . push ( { field, value, operator : '=' } ) ;
23+ }
24+ } ) ;
1925 } ) ;
2026 return wheres ;
2127}
2228
23- function getLimit ( info : any ) : number | void {
29+ function getLimit ( info ) : number | void {
2430 let limit ;
25- info . fieldNodes [ 0 ] . arguments . map ( ( value , key ) => {
26- if ( value . name . value === 'limit' ) {
27- limit = value . value . value ;
28- }
31+ info . fieldNodes . map ( fieldNode => {
32+ fieldNode . arguments . map ( value => {
33+ if ( value . name . value === 'limit' ) {
34+ limit = value . value . value ;
35+ }
36+ } ) ;
2937 } ) ;
3038 return limit ;
3139}
3240
33- export class Salesforce {
34- public conn ;
41+ class Salesforce {
42+ conn : any ;
3543
3644 constructor ( props ) {
45+ console . log ( 'CONSTRUCTOR' )
3746 this . conn = props . conn ;
3847 }
3948
40- query = ( parent , info ) => {
49+ public query = ( parent : { key : string } , info ) => {
50+ console . log ( 'BEFORE' )
4151 const queryBuilder = new Q ( info . returnType . ofType || info . returnType ) . select ( getFields ( info ) ) ;
4252 const limit = getLimit ( info ) ;
4353
@@ -54,3 +64,5 @@ export class Salesforce {
5464 return this . conn . query ( query ) ;
5565 } ;
5666}
67+
68+ export { Salesforce } ;
0 commit comments