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
Apollo CLI brings together your GraphQL clients and servers with tools for validating your schema, linting your operations for compatibility with your server, and generating static types for improved client-side type safety.
The Apollo CLI and VS Code extension can be configured with an Apollo Config file. Apollo configuration is stored as a plain object and can be either specified under the `apollo` key in your `package.json` or as a separate `apollo.config.js` which exports the config data.
218
+
219
+
The core of any configuration is specifying schemas and queries. Schemas specify information about your backend such as where to get the schema, what endpoint to make requests against, and the Apollo Engine API key to get schema updates and stats from. Queries define which documents Apollo tooling should analyze and tie them to the schema they are targeting.
220
+
221
+
Let's take a look at a basic configuration file (`package.json` style):
222
+
223
+
```js
224
+
{
225
+
...
226
+
"apollo": {
227
+
"schemas": {
228
+
"myPrimaryBackend": {
229
+
"schema":"downloadedSchema.json", // if not defined the an introspection query will be run
230
+
"endpoint":"http://example.com/graphql", // if not defined the schema will be downloaded from Apollo Engine
231
+
"engineKey":"my-engine-key"// use this key when connecting to Apollo Engine
232
+
}
233
+
},
234
+
"queries": [
235
+
{
236
+
"schema":"myPrimaryBackend", // reference the previously defined schema
237
+
"includes": [ "**/*.tsx" ], // load queries from .tsx files
238
+
"excludes": [ "node_modules/**" ] // don't include any matching files from node_modules
239
+
}
240
+
]
241
+
}
242
+
}
243
+
```
244
+
245
+
Or in `apollo.config.js` style:
246
+
247
+
```js
248
+
...
249
+
250
+
module.exports= {
251
+
schemas: {
252
+
myPrimaryBackend: {
253
+
schema:"downloadedSchema.json", // if not defined the an introspection query will be run
254
+
endpoint:"http://example.com/graphql", // if not defined the schema will be downloaded from Apollo Engine
255
+
engineKey:"my-engine-key"// use this key when connecting to Apollo Engine
256
+
}
257
+
},
258
+
queries: [
259
+
{
260
+
schema:"myPrimaryBackend", // reference the previously defined schema
261
+
includes: [ "**/*.tsx" ], // load queries from .tsx files
262
+
excludes: [ "node_modules/**" ] // don't include any matching files from node_modules
263
+
}
264
+
]
265
+
}
266
+
```
267
+
268
+
## Endpoint Configuration
269
+
270
+
When configuring a schema's endpoint, you can either pass in a string or an object, which allows for specifying advanced options like headers and subscription endpoints.
271
+
272
+
```js
273
+
endpoint: {
274
+
url:"http://example.com/graphql",
275
+
subscriptions:"ws://example.com/graphql",
276
+
headers: {
277
+
cookie:"myCookie=myCookieValue"
278
+
}
279
+
}
280
+
```
281
+
282
+
## Schema Dependencies
283
+
284
+
Schemas can also declare dependencies on eachother, which can be useful in situations like having a client-side schema for `apollo-link-state`. To declare a dependency, use the `extends` key. When working with a client-side schema, make sure to also specify the `clientSide` key to enable code-generation support.
0 commit comments