Skip to content

Commit a399050

Browse files
committed
Updated examples and added changelog
1 parent 8c9caf1 commit a399050

File tree

2 files changed

+92
-10
lines changed

2 files changed

+92
-10
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# json-to-graphql-query Changelog
3+
4+
## 1.4.0
5+
6+
* Added Variables support. Thanks @terion-name
7+
8+
## 1.3.0
9+
10+
* Added Alias support and made it possible to disable fields. Thanks @wellguimaraes
11+
12+
## 1.2.0
13+
14+
* Added Enum support, thanks @douglaseggleton

README.md

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ npm install json-to-graphql-query
1414
## Features
1515

1616
* 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)
2122

22-
See usage examples below :)
23+
## Recent Changes
24+
25+
See the [CHANGELOG](CHANGELOG.md)
2326

2427
## Usage
2528

@@ -57,18 +60,17 @@ query {
5760
}
5861
```
5962

60-
### Query with arguments
63+
### Query with arguments
6164

6265
```typescript
63-
import { jsonToGraphQLQuery, EnumType } from 'json-to-graphql-query';
66+
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
6467

6568
const query = {
6669
query: {
6770
Posts: {
6871
__args: {
6972
where: { id: 2 }
70-
orderBy: 'post_date',
71-
status: new EnumType('PUBLISHED')
73+
orderBy: 'post_date'
7274
},
7375
id: true,
7476
title: true,
@@ -83,7 +85,7 @@ Resulting `graphql_query`
8385

8486
```graphql
8587
query {
86-
Posts (where: {id: 2}, orderBy: "post_date", status: PUBLISHED) {
88+
Posts (where: {id: 2}, orderBy: "post_date") {
8789
id
8890
title
8991
post_date
@@ -198,6 +200,72 @@ query {
198200
}
199201
```
200202

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+
201269
## TO-DO List
202270

203271
* Support Named Queries / Mutations

0 commit comments

Comments
 (0)