Skip to content

Commit d0b0af7

Browse files
committed
📝 Update docs to include literal type
1 parent 198a83d commit d0b0af7

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

README.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<h1 align="center">
2-
<br>
3-
<img width="360" height="" src="https://cdn.rawgit.com/khaosdoctor/gotql/main/media/gotql.svg" alt="GotQL">
4-
<br>
5-
<br>
6-
<br>
2+
<br>
3+
<img width="360" height="" src="https://cdn.rawgit.com/khaosdoctor/gotql/main/media/gotql.svg" alt="GotQL">
4+
<br>
5+
<br>
6+
<br>
77
</h1>
88

99
> Write GraphQL queries as objects instead of strings
1010
1111
<h1 align="center">
12-
<a href="https://www.codacy.com/app/khaosdoctor/gotql?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=khaosdoctor/gotql&amp;utm_campaign=Badge_Grade">
13-
<img src= "https://api.codacy.com/project/badge/Grade/c993589aba95499691230a0a889377a9" alt="Codacy Badge">
14-
</a>
15-
<a href="https://opencollective.com/gotql" alt="Financial Contributors on Open Collective">
16-
<img src="https://opencollective.com/gotql/all/badge.svg?label=financial+contributors" />
17-
</a>
18-
<a href="https://github.com/khaosdoctor/gotql/actions?query=workflow%3A%22Build+and+Publish%22">
19-
<img src="https://github.com/khaosdoctor/gotql/workflows/Build%20and%20Publish/badge.svg" />
20-
</a>
21-
<a href="https://standardjs.com">
22-
<img src= "https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide">
23-
</a>
24-
<a href="https://snyk.io/test/github/khaosdoctor/gotql?targetFile=package.json">
25-
<img src="https://snyk.io/test/github/khaosdoctor/gotql/badge.svg?targetFile=package.json" alt="Known vulnerabilities">
26-
</a>
12+
<a href="https://www.codacy.com/app/khaosdoctor/gotql?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=khaosdoctor/gotql&amp;utm_campaign=Badge_Grade">
13+
<img src= "https://api.codacy.com/project/badge/Grade/c993589aba95499691230a0a889377a9" alt="Codacy Badge">
14+
</a>
15+
<a href="https://opencollective.com/gotql" alt="Financial Contributors on Open Collective">
16+
<img src="https://opencollective.com/gotql/all/badge.svg?label=financial+contributors" />
17+
</a>
18+
<a href="https://github.com/khaosdoctor/gotql/actions?query=workflow%3A%22Build+and+Publish%22">
19+
<img src="https://github.com/khaosdoctor/gotql/workflows/Build%20and%20Publish/badge.svg" />
20+
</a>
21+
<a href="https://standardjs.com">
22+
<img src= "https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide">
23+
</a>
24+
<a href="https://snyk.io/test/github/khaosdoctor/gotql?targetFile=package.json">
25+
<img src="https://snyk.io/test/github/khaosdoctor/gotql/badge.svg?targetFile=package.json" alt="Known vulnerabilities">
26+
</a>
2727
</h1>
2828

2929

@@ -432,52 +432,54 @@ query { users { name age friends { name age } } }
432432

433433
Recursive fields can go forever.
434434

435-
#### Enum args
435+
#### Enum and literal args
436+
437+
Enum or literal values should not be escaped, to do that, GotQL has a helper called `literal` which can be used to tell the query that value will not be escaped:
436438

437439
```js
440+
const { literal } = require('gotql')
441+
438442
const query = {
439443
operation: {
440444
name: 'user',
441445
args: {
442-
type: {
443-
value: 'internal',
444-
escape: false
445-
}
446+
type: literal`internal`
446447
},
447448
fields: ['name', 'age']
448449
}
449450
}
450451
```
451452

452-
Or with shorthand tagged template string:
453+
The code above outputs:
453454

454455
```js
455-
const { literal } = require('gotql')
456+
query { users(type: internal) { name age } }
457+
```
458+
459+
The `literal` helper is just a shorthand to the old-style `{value: string, escape: boolean}` object like below:
456460

461+
```js
457462
const query = {
458463
operation: {
459464
name: 'user',
460465
args: {
461-
type: literal`internal`
466+
type: {
467+
value: 'internal',
468+
escape: false
469+
}
462470
},
463471
fields: ['name', 'age']
464472
}
465473
}
466474
```
467475

468-
Outputs:
469-
470-
```js
471-
query { users(type: internal) { name age } }
472-
```
473-
474-
If `escape` is set to `true`, the output would be:
476+
If `literal` is omitted, or if `escape` is set to `true`, the output would be:
475477

476478
```js
477479
query { users(type: "internal") { name age } }
478480
```
479481

480-
> **Note:** Variables such as described [here](#query-with-variables) _will __not___ be recognized. If the arg object is not an `[argName]: value`, variables will not pass through the definition check (GotQL warns if a variable is not declared but used on operation).
482+
> **Note:** Variables such as described [here](#query-with-variables) will __not__ be recognized. If the arg object is not an `[argName]: value`, variables will not pass through the definition check (GotQL warns if a variable is not declared but used on operation).
481483
482484
## Contributing to this project
483485

0 commit comments

Comments
 (0)