@@ -14,12 +14,15 @@ npm install json-to-graphql-query
14
14
## Features
15
15
16
16
* Converts a JavaScript object to a GraphQL Query string
17
- * Full support for nested query nodes and arguments
18
- * Support for aliases via ` __alias `
19
- * Support for input arguments via ` __args `
20
- * Support for Enum values via ` EnumType `
17
+ * Full support for nested query / mutation nodes and arguments
18
+ * Support for input arguments via [ ` __args ` ] ( #query-with-arguments )
19
+ * Support for query aliases via [ ` __alias ` ] ( #using-aliases )
20
+ * Support for Enum values via [ ` EnumType ` ] ( #query-with-enum-values )
21
+ * Support for variables via [ ` __variables ` ] ( #query-with-variables )
21
22
22
- See usage examples below :)
23
+ ## Recent Changes
24
+
25
+ See the [ CHANGELOG] ( CHANGELOG.md )
23
26
24
27
## Usage
25
28
@@ -57,18 +60,17 @@ query {
57
60
}
58
61
```
59
62
60
- ### Query with arguments
63
+ ### Query with arguments
61
64
62
65
``` typescript
63
- import { jsonToGraphQLQuery , EnumType } from ' json-to-graphql-query' ;
66
+ import { jsonToGraphQLQuery } from ' json-to-graphql-query' ;
64
67
65
68
const query = {
66
69
query: {
67
70
Posts: {
68
71
__args: {
69
72
where: { id: 2 }
70
- orderBy : ' post_date' ,
71
- status: new EnumType (' PUBLISHED' )
73
+ orderBy : ' post_date'
72
74
},
73
75
id: true ,
74
76
title: true ,
@@ -83,7 +85,7 @@ Resulting `graphql_query`
83
85
84
86
``` graphql
85
87
query {
86
- Posts (where : {id : 2 }, orderBy : " post_date" , status : PUBLISHED ) {
88
+ Posts (where : {id : 2 }, orderBy : " post_date" ) {
87
89
id
88
90
title
89
91
post_date
@@ -198,6 +200,72 @@ query {
198
200
}
199
201
```
200
202
203
+ ### Query with Enum Values
204
+
205
+ ``` typescript
206
+ import { jsonToGraphQLQuery , EnumType } from ' json-to-graphql-query' ;
207
+
208
+ const query = {
209
+ query: {
210
+ Posts: {
211
+ __args: {
212
+ orderBy: ' post_date' ,
213
+ status: new EnumType (' PUBLISHED' )
214
+ },
215
+ title: true ,
216
+ body: true
217
+ }
218
+ }
219
+ };
220
+ const graphql_query = jsonToGraphQLQuery (query , { pretty: true });
221
+ ```
222
+
223
+ Resulting ` graphql_query `
224
+
225
+ ``` graphql
226
+ query {
227
+ Posts (orderBy : " post_date" , status : PUBLISHED ) {
228
+ title
229
+ body
230
+ }
231
+ }
232
+ ```
233
+
234
+ ### Query with variables
235
+
236
+ ``` typescript
237
+ import { jsonToGraphQLQuery , VariableType } from ' json-to-graphql-query' ;
238
+
239
+ const query = {
240
+ query: {
241
+ __variables: {
242
+ variable1: ' String!' ,
243
+ variableWithDefault: ' String = "default_value"'
244
+ },
245
+ Posts: {
246
+ __args: {
247
+ arg1: 20 ,
248
+ arg2: new VariableType (' variable1' )
249
+ },
250
+ id: true ,
251
+ title: true
252
+ }
253
+ }
254
+ };
255
+ const graphql_query = jsonToGraphQLQuery (query , { pretty: true });
256
+ ```
257
+
258
+ Resulting ` graphql_query `
259
+
260
+ ``` graphql
261
+ query ($variable1 : String ! , $variableWithDefault : String = " default_value" ) {
262
+ Posts (arg1 : 20 , arg2 : $variable1 ) {
263
+ id
264
+ title
265
+ }
266
+ }
267
+ ```
268
+
201
269
## TO-DO List
202
270
203
271
* Support Named Queries / Mutations
0 commit comments