Skip to content

Commit 633096d

Browse files
committed
docs(README.md): document Node.js async API
1 parent fdebfe1 commit 633096d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ JSCodeshift transform that inserts Flow types generated from GraphQL documents i
3131
- [`external as`](#external-as-)
3232
- [`extract [as ]`](#extract-as-)
3333
- [CLI Usage](#cli-usage)
34+
- [Node.js API](#nodejs-api)
3435

3536
<!-- tocstop -->
3637

@@ -726,3 +727,18 @@ type User = {
726727
```
727728
jscodeshift -t path/to/graphql-typegen/graphql-typegen.js src/**/*.js
728729
```
730+
731+
# Node.js API
732+
733+
Because `jscodeshift` unfortunately requires transform functions to be sync,
734+
`graphql-typegen` uses an `execFileSync` hack to synchronously fetch your schema
735+
from your schema file or server.
736+
737+
If you're calling directly from node, you can bypass this by using `graphql-typegen-async`:
738+
739+
```js
740+
import graphqlTypegen from 'graphql-typegen/graphql-typegen-async'
741+
```
742+
743+
It has the same API as a `jscodeshift` transform, except that it returns a `Promise` instead
744+
of a sync result. Maybe someday `jscodeshift` will support async transforms.

0 commit comments

Comments
 (0)