@@ -146,7 +146,7 @@ describe('jsonToGraphQL()', () => {
146
146
}` ) ;
147
147
} ) ;
148
148
149
- it ( 'Converts a JavaScript object into a valid Apollo query, including single directives with no arguments.' , ( ) => {
149
+ it ( 'Converts a JavaScript object into a valid query, including a single directive w/ no arguments.' , ( ) => {
150
150
interface ILooseObject { [ key : string ] : any ; }
151
151
let input : ILooseObject = {
152
152
__typename : 'everyday-health-focuses' ,
@@ -197,14 +197,42 @@ describe('jsonToGraphQL()', () => {
197
197
input [ key ] [ '__directives' ] = { client : true , } ;
198
198
} ) ;
199
199
input = { query : input } ;
200
- // Do I want to add some keysToStrip functionality separately?
201
- // - const input = jsonToGraphqlQuery(preInput, { keysToStrip: ['__typename'] });
202
200
const expected = 'query { diet @client { id options { calorie-count { category ' +
203
201
'icon id text } mood { category icon id text } weight { category icon id text } } ' +
204
202
'title } someOtherAbritraryKey @client { arb1 arb2 } }' ;
205
203
expect ( jsonToGraphQLQuery ( input ) ) . to . equal ( expected ) ;
206
204
} ) ;
207
205
206
+ it ( 'Converts a JavaScript object into a valid query, including single directives ' +
207
+ 'with args, so long as any variables used are enclosed in a string with "$" included.' , ( ) => {
208
+ interface ILooseObject { [ key : string ] : any ; }
209
+ let input : ILooseObject = {
210
+ someOtherAbritraryKey : {
211
+ __typename : 'someArbitraryObjType' ,
212
+ arb1 : 'arbitrary value' ,
213
+ arb2 : 'some other arbitrary value'
214
+ }
215
+ } ;
216
+ Object . keys ( input )
217
+ . filter ( filterNonConfigFields )
218
+ . forEach ( ( key ) => {
219
+ input [ key ] [ '__directives' ] = { include : { if : '$isAwesome' } , } ;
220
+ } ) ;
221
+ input = { query : input } ;
222
+ const expected = 'query { someOtherAbritraryKey @include(if: $isAwesome) { arb1 arb2 } }' ;
223
+ expect ( jsonToGraphQLQuery ( input ) ) . to . equal ( expected ) ;
224
+ } ) ;
225
+
226
+ // TODO
227
+ // it('Converts a JavaScript object into a valid query, including *multiple* directives ' +
228
+ // 'with args, so long as any variables used are enclosed in a string with "$" included.', () => {
229
+ // });
230
+
231
+ // TODO
232
+ // it('Creates a query, stripping/ignoring certain, specified keys.', () => {
233
+ // // Example usage: jsonToGraphqlQuery(preInput, { keysToStrip: ['__typename'] });
234
+ // });
235
+
208
236
it ( 'converts a query with nested objects' , ( ) => {
209
237
const query = {
210
238
query : {
0 commit comments