You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check out the [demo](https://codesandbox.io/s/k3qrkl8qlv) on CodeSandbox: https://codesandbox.io/s/k3qrkl8qlv
6
7
7
-
## What is included
8
+
</div>
8
9
9
-
Graphpack utilizes [`webpack`](https://github.com/webpack/webpack)with [`nodemon`](https://github.com/remy/nodemon) and lets you create GraphQL servers with zero configuration. It uses [`Apollo Server`](https://github.com/apollographql/apollo-server) under the hood, so we get features like [GraphQL Playground](https://github.com/prisma/graphql-playground), [GraphQL Imports](https://github.com/prisma/graphql-import) and many more right out of the box.
10
+
<hr>
10
11
11
-
- 📦 **Zero-config** out of the box experience
12
-
- 🚦 Built-in **Live reload** and automatic recompilation
12
+
## What is included?
13
+
14
+
Graphpack utilizes [`webpack`](https://github.com/webpack/webpack) with [`nodemon`](https://github.com/remy/nodemon) and lets you create GraphQL servers with zero configuration. It uses [`Apollo Server`](https://github.com/apollographql/apollo-server) under the hood, so we get features like [GraphQL Playground](https://github.com/prisma/graphql-playground), [GraphQL Imports](https://github.com/prisma/graphql-import) and many more right out of the box.
15
+
16
+
- 📦 **Zero-config** out of the box
17
+
- 🚦 Built-in **Live reload**
13
18
- 🚨 Super-friendly error messages
14
-
- 🎮 GraphQL **Playground** IDE
19
+
- 🎮 **GraphQL Playground** IDE
15
20
- ⭐️ **GraphQL imports** in Schema Definition Language
16
21
- 🔥 [**Blazing fast**](https://twitter.com/acdlite/status/974390255393505280) bundle times
17
-
- ⚡️ **ES module imports** thanks to [Babel](https://github.com/babel/babel)
18
-
19
-
## Install
22
+
- ⚡️ **ES module imports** and dynamic `import()`'s thanks to [Babel](https://github.com/babel/babel)
Graphpack will watch for changes in your `./src` folder and automatically reloads the server.
103
108
104
109
### `graphpack build`
105
110
@@ -109,35 +114,129 @@ Creates a production ready build under the project roots `build` folder.
109
114
110
115
## Entry files
111
116
112
-
tbd
113
-
114
117
### `src/resolvers.js` (required)
115
118
116
-
tbd
119
+
In this file you define all your resolvers:
120
+
121
+
```js
122
+
// src/resolvers.js
123
+
constresolvers= {
124
+
Query: {
125
+
article: (obj, args) =>getArticleById(args.id),
126
+
articles: () =>getArticles(),
127
+
},
128
+
};
129
+
130
+
exportdefaultresolvers;
131
+
```
132
+
133
+
> You can use any of these folder/file structure:
134
+
>
135
+
> -`src/resolvers.js`
136
+
> -`src/resolvers/index.js`
117
137
118
138
### `src/schema.js` (required)
119
139
120
-
tbd
140
+
Here you define all your GraphQL type definitions:
141
+
142
+
```graphql
143
+
# src/schema.graphql
144
+
typeArticle {
145
+
title: String
146
+
body: String
147
+
}
148
+
149
+
typeQuery {
150
+
article: Article
151
+
articles: [Article!]!
152
+
}
153
+
```
154
+
155
+
Alternativelyyoucancreatea `src/schema.js` and use the template literal tag `gql` by [`graphql-tag`](https://github.com/apollographql/graphql-tag):
156
+
157
+
```js
158
+
// src/schema.js
159
+
import { gql } from 'graphql-tag';
160
+
161
+
consttypeDefs = gql`
162
+
typeArticle {
163
+
title: String
164
+
body: String
165
+
}
166
+
167
+
typeQuery {
168
+
article: Article
169
+
articles: [Article!]!
170
+
}
171
+
`;
172
+
173
+
exportdefaulttypeDefs;
174
+
```
175
+
176
+
Note that you need install `graphql-tag` in this case.
177
+
178
+
> Graphpack can resolve both `.js` and `.graphql` files. This means you can use any of these folder/file structure:
179
+
>
180
+
> -`src/schema.js`
181
+
> -`src/schema/index.js`
182
+
> -`src/schema.graphql`
183
+
> -`src/schema/index.graphql`
121
184
122
185
### `src/context.js`
123
186
124
-
tbd
187
+
Create `src/context.js` and do following:
188
+
189
+
```js
190
+
constcontext=req=> ({
191
+
/* context props here */
192
+
});
193
+
194
+
exportdefaultcontext;
195
+
```
196
+
197
+
> You can use any of these folder/file structure:
198
+
>
199
+
> -`src/context.js`
200
+
> -`src/context/index.js`
125
201
126
202
### `src/config.js`
127
203
128
-
tbd
204
+
In `src/config.js` you can set further options of your Apollo Server. Refer to the [Apollo Server docs](https://www.apollographql.com/docs/apollo-server/api/apollo-server.html#constructor-options-lt-ApolloServer-gt) for more details about the options.
205
+
206
+
```js
207
+
// src/config.js
208
+
constIS_DEV=process.env.NODE_ENV!=='production';
209
+
210
+
constconfig= {
211
+
debug:process.env.DEBUG,
212
+
playground:IS_DEV,
213
+
introspection:IS_DEV,
214
+
mocks:IS_DEV,
215
+
// ...
216
+
};
129
217
130
-
## Customize configuration
218
+
exportdefaultconfig;
219
+
```
220
+
221
+
Note that you cannot to set `resolvers`, `typeDefs` or `context` in the config file. In these cases please refer to [entry files](#entry-files).
222
+
223
+
> You can use any of these folder/file structure:
224
+
>
225
+
> -`src/config.js`
226
+
> -`src/config/index.js`
131
227
132
-
tbd
228
+
## Custom configuration
133
229
134
-
### Webpack
230
+
For custom configuration you can create a `graphpack` config file in [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) format:
135
231
136
-
tbd
232
+
-`graphpack.config.js`
233
+
-`"graphpack"` field in `package.json`
234
+
-`.grahpackrc` in JSON or YAML
235
+
-`.graphpackrc` with the extensions `.json`, `.yaml`, `.yml`, or `.js`
137
236
138
-
### Apollo Server
237
+
### Customize Webpack configuration
139
238
140
-
tbd
239
+
To extend webpack, you can define a function that extends its config via `graphpack.config.js`.
0 commit comments