Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6d2f8da

Browse files
author
Mark
committed
Initial commit v1
1 parent 9eeec75 commit 6d2f8da

File tree

8 files changed

+3792
-1
lines changed

8 files changed

+3792
-1
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

‎.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src
2+
.circleci
3+
renovate.json

‎README.md

100644100755
Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,93 @@
1-
# graphql-cli-generate-fragments
1+
# graphql-cli-generate-fragments [![npm]
2+
3+
## Installation
4+
5+
```npm i -g graphql-cli graphql-cli-generate-fragments```
6+
7+
## Usage
8+
```
9+
graphql generate-fragments
10+
211
Generate Fragments for Graphql Schemas
12+
13+
Options:
14+
--dotenv Path to .env file [string]
15+
-p, --project Project name [string]
16+
--output, -o Output folder [string]
17+
--save, -s Save settings to config file [boolean] [default: "false"]
18+
"false"]
19+
--generator, -g Generate to 'js' or 'graphq' [string]
20+
--verbose Show verbose output messages [boolean] [default: "false"]
21+
-h, --help Show help [boolean]
22+
-v, --version Show version number [boolean]
23+
```
24+
25+
26+
### Graphql Fragments Generation
27+
Creates graphql fragments containing the fields for each type in the supplied schema.
28+
29+
30+
31+
The first time you use fragment generation in your project, you need to provide an output folder for your fragments, and the generator you want to use:
32+
```shell
33+
$ graphql generate-fragments -p database -o src/generated -g graphql --save
34+
✔ Fragments for project database written to src/generated/database.fragments.js
35+
```
36+
This will also save the configuration in your `.graphqlconfig` file (see below).
37+
38+
### Automating `graphql generate-fragments`
39+
After you have set up fragment generation for all projects, you can simply run `graphql generate-fragments` without any parameters to process all projects:
40+
```shell
41+
$ graphql prepare
42+
✔ Fragments for project app written to src/generated/app.fragments.graphql
43+
✔ Fragments for project database written to src/generated/database.fragments.js
44+
```
45+
## Advanced topics
46+
47+
### Available generators
48+
The following generators are provided:
49+
50+
| Generator | Purpose |
51+
| ------------ | -------------------------------------------- |
52+
| graphql | Generates fragments for all types in schema |
53+
| js | Wraps the graphql and exports them for inclusion in javascript projects |
54+
55+
56+
### `graphql-config` extensions
57+
58+
To store the project configuration for fragment generation, `graphql-cli-generate-fragments` uses two extension keys in the `graphql-config` configuration file. These keys can be set manually, or using the `--save` parameter.
59+
```diff
60+
# ./.graphqlconfig.yml
61+
projects:
62+
app:
63+
schemaPath: src/schema.graphql
64+
extensions:
65+
endpoints:
66+
default: 'http://localhost:4000'
67+
+ prepare-bundle:
68+
+ src/generated/app.fragments.js
69+
+ generator: js
70+
database:
71+
schemaPath: src/generated/prisma.graphql
72+
extensions:
73+
prisma: database/prisma.yml
74+
+ generate-fragments:
75+
+ output: src/generated/database.fragments.graphql
76+
+ generator: graphql
77+
78+
```
79+
80+
## License
81+
82+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
83+
84+
## Acknowledgments
85+
86+
* [lachenmayer](https://github.com/lachenmayer) for [`graphql-fragment-codegen`](https://github.com/lachenmayer/graphql-fragment-codegen)
87+
* [kbrandwijk](https://github.com/kbrandwijk)/[supergraphql](https://github.com/supergraphql) for [`graphql-cli-prepare`](https://github.com/supergraphql/graphql-cli-prepare)
88+
89+
<hr>
90+
<p align="center">
91+
<img src="https://img.shields.io/badge/built-with_love-blue.svg?style=for-the-badge"/><a href="https://github.com/develomark" target="-_blank"><img src="https://img.shields.io/badge/by-develomark-red.svg?style=for-the-badge"/></a>
92+
</p>
93+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /