@@ -146,25 +146,23 @@ 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' ,
153
153
diet : {
154
154
__typename : 'diet' ,
155
155
id : 'diet' ,
156
156
options : {
157
- // tslint:disable-next-line:object-literal-key-quotes
158
157
__typename : 'diet-options' ,
159
- 'calorie-count' : {
158
+ calorieCount : {
160
159
__typename : 'calorie-count' ,
161
160
category : 'Diet' ,
162
161
icon : 'fa fa-question-circle' ,
163
162
id : 'calorie-count' ,
164
163
selected : false ,
165
164
text : 'Calorie Count'
166
165
} ,
167
- // tslint:disable-next-line:object-literal-key-quotes
168
166
mood : {
169
167
__typename : 'mood' ,
170
168
category : 'Diet' ,
@@ -173,7 +171,6 @@ describe('jsonToGraphQL()', () => {
173
171
selected : false ,
174
172
text : 'Mood'
175
173
} ,
176
- // tslint:disable-next-line:object-literal-key-quotes
177
174
weight : {
178
175
__typename : 'weight' ,
179
176
category : 'Diet' ,
@@ -197,14 +194,42 @@ describe('jsonToGraphQL()', () => {
197
194
input [ key ] [ '__directives' ] = { client : true , } ;
198
195
} ) ;
199
196
input = { query : input } ;
200
- // Do I want to add some keysToStrip functionality separately?
201
- // - const input = jsonToGraphqlQuery(preInput, { keysToStrip: ['__typename'] });
202
- const expected = 'query { diet @client { id options { calorie-count { category ' +
197
+ const expected = 'query { diet @client { id options { calorieCount { category ' +
203
198
'icon id text } mood { category icon id text } weight { category icon id text } } ' +
204
199
'title } someOtherAbritraryKey @client { arb1 arb2 } }' ;
205
200
expect ( jsonToGraphQLQuery ( input ) ) . to . equal ( expected ) ;
206
201
} ) ;
207
202
203
+ it ( 'Converts a JavaScript object into a valid query, including single directives ' +
204
+ 'with args, so long as any variables used are enclosed in a string with "$" included.' , ( ) => {
205
+ interface ILooseObject { [ key : string ] : any ; }
206
+ let input : ILooseObject = {
207
+ someOtherAbritraryKey : {
208
+ __typename : 'someArbitraryObjType' ,
209
+ arb1 : 'arbitrary value' ,
210
+ arb2 : 'some other arbitrary value'
211
+ }
212
+ } ;
213
+ Object . keys ( input )
214
+ . filter ( filterNonConfigFields )
215
+ . forEach ( ( key ) => {
216
+ input [ key ] [ '__directives' ] = { include : { if : '$isAwesome' } , } ;
217
+ } ) ;
218
+ input = { query : input } ;
219
+ const expected = 'query { someOtherAbritraryKey @include(if: $isAwesome) { arb1 arb2 } }' ;
220
+ expect ( jsonToGraphQLQuery ( input ) ) . to . equal ( expected ) ;
221
+ } ) ;
222
+
223
+ // TODO
224
+ // it('Converts a JavaScript object into a valid query, including *multiple* directives ' +
225
+ // 'with args, so long as any variables used are enclosed in a string with "$" included.', () => {
226
+ // });
227
+
228
+ // TODO
229
+ // it('Creates a query, stripping/ignoring certain, specified keys.', () => {
230
+ // // Example usage: jsonToGraphqlQuery(preInput, { keysToStrip: ['__typename'] });
231
+ // });
232
+
208
233
it ( 'converts a query with nested objects' , ( ) => {
209
234
const query = {
210
235
query : {
0 commit comments