UNPKG

40.1 kBMarkdownView Raw
1# Apollo CLI
2
3[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg?maxAge=2592000)](https://raw.githubusercontent.com/apollographql/apollo-tooling/master/LICENSE) [![npm](https://img.shields.io/npm/v/apollo.svg)](https://www.npmjs.com/package/apollo) [![Get on Slack](https://img.shields.io/badge/spectrum-join-orange.svg)](https://spectrum.chat/apollo?tab=posts)
4
5Apollo 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.
6
7<!-- toc -->
8* [Apollo CLI](#apollo-cli)
9* [Usage](#usage)
10* [Commands](#commands)
11* [Configuration](#configuration)
12* [Code Generation](#code-generation)
13* [Contributing](#contributing)
14<!-- tocstop -->
15
16# Usage
17
18**Disclaimer**: The following API documentation is only for the latest version released on NPM, and may not be accurate for previous or future versions.
19
20<!-- usage -->
21```sh-session
22$ npm install -g apollo
23$ apollo COMMAND
24running command...
25$ apollo (-v|--version|version)
26apollo/2.32.1 linux-x64 node-v10.23.1
27$ apollo --help [COMMAND]
28USAGE
29 $ apollo COMMAND
30...
31```
32<!-- usagestop -->
33
34# Commands
35
36<!-- commands -->
37* [`apollo client:check`](#apollo-clientcheck)
38* [`apollo client:codegen [OUTPUT]`](#apollo-clientcodegen-output)
39* [`apollo client:download-schema OUTPUT`](#apollo-clientdownload-schema-output)
40* [`apollo client:extract OUTPUT`](#apollo-clientextract-output)
41* [`apollo client:push`](#apollo-clientpush)
42* [`apollo help [COMMAND]`](#apollo-help-command)
43* [`apollo plugins`](#apollo-plugins)
44* [`apollo plugins:install PLUGIN...`](#apollo-pluginsinstall-plugin)
45* [`apollo plugins:link PLUGIN`](#apollo-pluginslink-plugin)
46* [`apollo plugins:uninstall PLUGIN...`](#apollo-pluginsuninstall-plugin)
47* [`apollo plugins:update`](#apollo-pluginsupdate)
48* [`apollo service:check`](#apollo-servicecheck)
49* [`apollo service:delete`](#apollo-servicedelete)
50* [`apollo service:download OUTPUT`](#apollo-servicedownload-output)
51* [`apollo service:list`](#apollo-servicelist)
52* [`apollo service:push`](#apollo-servicepush)
53
54## `apollo client:check`
55
56Check a client project against a pushed service
57
58```
59Check a client project against a pushed service
60
61USAGE
62 $ apollo client:check
63
64OPTIONS
65 -c, --config=config Path to your Apollo config file
66
67 -g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides
68 config file if set.
69
70 -v, --variant=variant The variant of the graph in Apollo to associate this client to
71
72 --clientName=clientName Name of the client that the queries will be attached to
73
74 --clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will use
75 clientName if not provided
76
77 --clientVersion=clientVersion The version of the client that the queries will be attached to
78
79 --endpoint=endpoint The URL for the CLI use to introspect your service
80
81 --excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently
82 work in watch mode
83
84 --header=header Additional header to send during introspection. May be used multiple times to
85 add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the
86 `--header` flag.
87
88 --includes=includes Glob of files to search for GraphQL operations. This should be used to find
89 queries *and* any client schema extensions
90
91 --key=key The API key to use for authentication to Apollo
92
93 --queries=queries Deprecated in favor of the includes flag
94
95 --tagName=tagName Name of the template literal tag used to identify template literals containing
96 GraphQL queries in Javascript/Typescript code
97```
98
99_See code: [src/commands/client/check.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/check.ts)_
100
101## `apollo client:codegen [OUTPUT]`
102
103Generate static types for GraphQL queries. Can use the published schema in the Apollo registry or a downloaded schema.
104
105```
106Generate static types for GraphQL queries. Can use the published schema in the Apollo registry or a downloaded schema.
107
108USAGE
109 $ apollo client:codegen [OUTPUT]
110
111ARGUMENTS
112 OUTPUT
113 Directory to which generated files will be written.
114 - For TypeScript/Flow generators, this specifies a directory relative to each source file by default.
115 - For TypeScript/Flow generators with the "outputFlat" flag is set, and for the Swift generator, this specifies a
116 file or directory (absolute or relative to the current working directory) to which:
117 - a file will be written for each query (if "output" is a directory)
118 - all generated types will be written
119 - For all other types, this defines a file (absolute or relative to the current working directory) to which all
120 generated types are written.
121
122OPTIONS
123 -c, --config=config Path to your Apollo config file
124
125 -g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides
126 config file if set.
127
128 -v, --variant=variant The variant of the graph in Apollo to associate this client to
129
130 --[no-]addTypename [default: true] Automatically add __typename to your queries, can be unset
131 with --no-addTypename
132
133 --clientName=clientName Name of the client that the queries will be attached to
134
135 --clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will
136 use clientName if not provided
137
138 --clientVersion=clientVersion The version of the client that the queries will be attached to
139
140 --customScalarsPrefix=customScalarsPrefix Include a prefix when using provided types for custom scalars
141
142 --endpoint=endpoint The URL for the CLI use to introspect your service
143
144 --excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't
145 currently work in watch mode
146
147 --globalTypesFile=globalTypesFile By default, TypeScript will put a file named "globalTypes.ts" inside the
148 "output" directory. Set "globalTypesFile" to specify a different path.
149 Alternatively, set "tsFileExtension" to modify the extension of the file,
150 for example "d.ts" will output "globalTypes.d.ts"
151
152 --header=header Additional header to send during introspection. May be used multiple times
153 to add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using
154 the `--header` flag.
155
156 --includes=includes Glob of files to search for GraphQL operations. This should be used to find
157 queries *and* any client schema extensions
158
159 --key=key The API key to use for authentication to Apollo
160
161 --localSchemaFile=localSchemaFile Path to one or more local GraphQL schema file(s), as introspection result
162 or SDL. Supports comma-separated list of paths (ex.
163 `--localSchemaFile=schema.graphql,extensions.graphql`)
164
165 --mergeInFieldsFromFragmentSpreads Merge fragment fields onto its enclosing type
166
167 --namespace=namespace The namespace to emit generated code into.
168
169 --omitDeprecatedEnumCases Omit deprecated enum cases from generated code [Swift only]
170
171 --only=only Parse all input files, but only output generated code for the specified
172 file [Swift only]
173
174 --operationIdsPath=operationIdsPath Path to an operation id JSON map file. If specified, also stores the
175 operation ids (hashes) as properties on operation types [currently
176 Swift-only]
177
178 --outputFlat By default, TypeScript/Flow will put each generated file in a directory
179 next to its source file using the value of the "output" as the directory
180 name. Set "outputFlat" to put all generated files in the directory relative
181 to the current working directory defined by "output".
182
183 --passthroughCustomScalars Use your own types for custom scalars
184
185 --queries=queries Deprecated in favor of the includes flag
186
187 --suppressSwiftMultilineStringLiterals Prevents operations from being rendered as multiline strings [Swift only]
188
189 --tagName=tagName Name of the template literal tag used to identify template literals
190 containing GraphQL queries in Javascript/Typescript code
191
192 --target=target (required) Type of code generator to use (swift | typescript | flow | scala
193 | json | json-modern (exposes raw json types))
194
195 --tsFileExtension=tsFileExtension By default, TypeScript will output "ts" files. Set "tsFileExtension" to
196 specify a different file extension, for example "d.ts"
197
198 --useFlowExactObjects Use Flow exact objects for generated types [flow only]
199
200 --useFlowReadOnlyTypes Use read only types for generated types [flow only]. **Deprecated in favor
201 of `useReadOnlyTypes`.**
202
203 --useReadOnlyTypes Use read only types for generated types [flow | typescript]
204
205 --watch Watch for file changes and reload codegen
206
207ALIASES
208 $ apollo codegen:generate
209```
210
211_See code: [src/commands/client/codegen.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/codegen.ts)_
212
213## `apollo client:download-schema OUTPUT`
214
215Download a schema from Apollo or a GraphQL endpoint in JSON or SDL format
216
217```
218Download a schema from Apollo or a GraphQL endpoint in JSON or SDL format
219
220USAGE
221 $ apollo client:download-schema OUTPUT
222
223ARGUMENTS
224 OUTPUT [default: schema.json] Path to write the introspection result to. Can be `.graphql`, `.gql`, `.graphqls`, or
225 `.json`
226
227OPTIONS
228 -c, --config=config Path to your Apollo config file
229
230 -g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides
231 config file if set.
232
233 -v, --variant=variant The variant of the graph in Apollo to associate this client to
234
235 --clientName=clientName Name of the client that the queries will be attached to
236
237 --clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will use
238 clientName if not provided
239
240 --clientVersion=clientVersion The version of the client that the queries will be attached to
241
242 --endpoint=endpoint The URL for the CLI use to introspect your service
243
244 --excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently
245 work in watch mode
246
247 --header=header Additional header to send during introspection. May be used multiple times to
248 add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the
249 `--header` flag.
250
251 --includes=includes Glob of files to search for GraphQL operations. This should be used to find
252 queries *and* any client schema extensions
253
254 --key=key The API key to use for authentication to Apollo
255
256 --queries=queries Deprecated in favor of the includes flag
257
258 --tagName=tagName Name of the template literal tag used to identify template literals containing
259 GraphQL queries in Javascript/Typescript code
260```
261
262_See code: [src/commands/client/download-schema.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/download-schema.ts)_
263
264## `apollo client:extract OUTPUT`
265
266Extract queries from a client
267
268```
269Extract queries from a client
270
271USAGE
272 $ apollo client:extract OUTPUT
273
274ARGUMENTS
275 OUTPUT [default: manifest.json] Path to write the extracted queries to
276
277OPTIONS
278 -c, --config=config Path to your Apollo config file
279
280 -g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides
281 config file if set.
282
283 -v, --variant=variant The variant of the graph in Apollo to associate this client to
284
285 --clientName=clientName Name of the client that the queries will be attached to
286
287 --clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will use
288 clientName if not provided
289
290 --clientVersion=clientVersion The version of the client that the queries will be attached to
291
292 --endpoint=endpoint The URL for the CLI use to introspect your service
293
294 --excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently
295 work in watch mode
296
297 --header=header Additional header to send during introspection. May be used multiple times to
298 add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the
299 `--header` flag.
300
301 --includes=includes Glob of files to search for GraphQL operations. This should be used to find
302 queries *and* any client schema extensions
303
304 --key=key The API key to use for authentication to Apollo
305
306 --preserveStringAndNumericLiterals Disable redaction of string and numerical literals. Without this flag, these
307 values will be replaced with empty strings (`''`) and zeroes (`0`)
308 respectively. This redaction is intended to avoid inadvertently outputting
309 potentially personally identifiable information (e.g. embedded passwords or
310 API keys) into operation manifests
311
312 --queries=queries Deprecated in favor of the includes flag
313
314 --tagName=tagName Name of the template literal tag used to identify template literals containing
315 GraphQL queries in Javascript/Typescript code
316```
317
318_See code: [src/commands/client/extract.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/extract.ts)_
319
320## `apollo client:push`
321
322Register operations with Apollo, adding them to the safelist
323
324```
325Register operations with Apollo, adding them to the safelist
326
327USAGE
328 $ apollo client:push
329
330OPTIONS
331 -c, --config=config Path to your Apollo config file
332
333 -g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides
334 config file if set.
335
336 -v, --variant=variant The variant of the graph in Apollo to associate this client to
337
338 --clientName=clientName Name of the client that the queries will be attached to
339
340 --clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will use
341 clientName if not provided
342
343 --clientVersion=clientVersion The version of the client that the queries will be attached to
344
345 --endpoint=endpoint The URL for the CLI use to introspect your service
346
347 --excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently
348 work in watch mode
349
350 --header=header Additional header to send during introspection. May be used multiple times to
351 add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the
352 `--header` flag.
353
354 --includes=includes Glob of files to search for GraphQL operations. This should be used to find
355 queries *and* any client schema extensions
356
357 --key=key The API key to use for authentication to Apollo
358
359 --queries=queries Deprecated in favor of the includes flag
360
361 --tagName=tagName Name of the template literal tag used to identify template literals containing
362 GraphQL queries in Javascript/Typescript code
363```
364
365_See code: [src/commands/client/push.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/push.ts)_
366
367## `apollo help [COMMAND]`
368
369display help for apollo
370
371```
372display help for <%= config.bin %>
373
374USAGE
375 $ apollo help [COMMAND]
376
377ARGUMENTS
378 COMMAND command to show help for
379
380OPTIONS
381 --all see all commands in CLI
382```
383
384_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_
385
386## `apollo plugins`
387
388list installed plugins
389
390```
391list installed plugins
392
393USAGE
394 $ apollo plugins
395
396OPTIONS
397 --core show core plugins
398
399EXAMPLE
400 $ apollo plugins
401```
402
403_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.9.5/src/commands/plugins/index.ts)_
404
405## `apollo plugins:install PLUGIN...`
406
407installs a plugin into the CLI
408
409```
410installs a plugin into the CLI
411Can be installed from npm or a git url.
412
413Installation of a user-installed plugin will override a core plugin.
414
415e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in the CLI without the need to patch and update the whole CLI.
416
417
418USAGE
419 $ apollo plugins:install PLUGIN...
420
421ARGUMENTS
422 PLUGIN plugin to install
423
424OPTIONS
425 -f, --force yarn install with force flag
426 -h, --help show CLI help
427 -v, --verbose
428
429DESCRIPTION
430 Can be installed from npm or a git url.
431
432 Installation of a user-installed plugin will override a core plugin.
433
434 e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
435 will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
436 the CLI without the need to patch and update the whole CLI.
437
438ALIASES
439 $ apollo plugins:add
440
441EXAMPLES
442 $ apollo plugins:install myplugin
443 $ apollo plugins:install https://github.com/someuser/someplugin
444 $ apollo plugins:install someuser/someplugin
445```
446
447_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.9.5/src/commands/plugins/install.ts)_
448
449## `apollo plugins:link PLUGIN`
450
451links a plugin into the CLI for development
452
453```
454links a plugin into the CLI for development
455Installation of a linked plugin will override a user-installed or core plugin.
456
457e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work.
458
459
460USAGE
461 $ apollo plugins:link PLUGIN
462
463ARGUMENTS
464 PATH [default: .] path to plugin
465
466OPTIONS
467 -h, --help show CLI help
468 -v, --verbose
469
470DESCRIPTION
471 Installation of a linked plugin will override a user-installed or core plugin.
472
473 e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
474 command will override the user-installed or core plugin implementation. This is useful for development work.
475
476EXAMPLE
477 $ apollo plugins:link myplugin
478```
479
480_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.9.5/src/commands/plugins/link.ts)_
481
482## `apollo plugins:uninstall PLUGIN...`
483
484removes a plugin from the CLI
485
486```
487removes a plugin from the CLI
488
489USAGE
490 $ apollo plugins:uninstall PLUGIN...
491
492ARGUMENTS
493 PLUGIN plugin to uninstall
494
495OPTIONS
496 -h, --help show CLI help
497 -v, --verbose
498
499ALIASES
500 $ apollo plugins:unlink
501 $ apollo plugins:remove
502```
503
504_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.9.5/src/commands/plugins/uninstall.ts)_
505
506## `apollo plugins:update`
507
508update installed plugins
509
510```
511update installed plugins
512
513USAGE
514 $ apollo plugins:update
515
516OPTIONS
517 -h, --help show CLI help
518 -v, --verbose
519```
520
521_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.9.5/src/commands/plugins/update.ts)_
522
523## `apollo service:check`
524
525Check a service against known operation workloads to find breaking changes
526
527```
528Check a service against known operation workloads to find breaking changes
529
530USAGE
531 $ apollo service:check
532
533OPTIONS
534 -c, --config=config Path to your Apollo config file
535
536 -g, --graph=graph The ID of the graph in Apollo to check your proposed
537 schema changes against. Overrides config file if set.
538
539 -v, --variant=variant The variant to check the proposed schema against
540
541 --author=author The author to associate with this proposed schema
542
543 --branch=branch The branch name to associate with this check
544
545 --commitId=commitId The SHA-1 hash of the commit to associate with this
546 check
547
548 --endpoint=endpoint The URL for the CLI use to introspect your service
549
550 --header=header Additional header to send during introspection. May be
551 used multiple times to add multiple headers. NOTE: The
552 `--endpoint` flag is REQUIRED if using the `--header`
553 flag.
554
555 --ignoreFailures Exit with status 0 when the check completes, even if
556 errors are found
557
558 --json Output result in json, which can then be parsed by CLI
559 tools such as jq.
560
561 --key=key The API key to use for authentication to Apollo
562
563 --localSchemaFile=localSchemaFile Path to one or more local GraphQL schema file(s), as
564 introspection result or SDL. Supports comma-separated
565 list of paths (ex.
566 `--localSchemaFile=schema.graphql,extensions.graphql`)
567
568 --markdown Output result in markdown.
569
570 --queryCountThreshold=queryCountThreshold Minimum number of requests within the requested time
571 window for a query to be considered.
572
573 --queryCountThresholdPercentage=queryCountThresholdPercentage Number of requests within the requested time window for
574 a query to be considered, relative to total request
575 count. Expected values are between 0 and 0.05 (minimum
576 5% of total request volume)
577
578 --serviceName=serviceName Provides the name of the implementing service for a
579 federated graph. This flag will indicate that the
580 schema is a partial schema from a federated service
581
582 --validationPeriod=validationPeriod The size of the time window with which to validate the
583 schema against. You may provide a number (in seconds),
584 or an ISO8601 format duration for more granularity
585 (see: https://en.wikipedia.org/wiki/ISO_8601#Durations)
586
587ALIASES
588 $ apollo schema:check
589```
590
591_See code: [src/commands/service/check.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/service/check.ts)_
592
593## `apollo service:delete`
594
595Delete a federated service from Apollo and recompose remaining services
596
597```
598Delete a federated service from Apollo and recompose remaining services
599
600USAGE
601 $ apollo service:delete
602
603OPTIONS
604 -c, --config=config Path to your Apollo config file
605
606 -g, --graph=graph The ID of the graph in Apollo for which to delete an implementing service. Overrides config
607 file if set.
608
609 -v, --variant=variant The variant to delete the implementing service from
610
611 -y, --yes Bypass confirmation when deleting a service
612
613 --endpoint=endpoint The URL for the CLI use to introspect your service
614
615 --header=header Additional header to send during introspection. May be used multiple times to add multiple
616 headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag.
617
618 --key=key The API key to use for authentication to Apollo
619
620 --serviceName=serviceName (required) Provides the name of the implementing service for a federated graph
621```
622
623_See code: [src/commands/service/delete.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/service/delete.ts)_
624
625## `apollo service:download OUTPUT`
626
627Download the schema from your GraphQL endpoint.
628
629```
630Download the schema from your GraphQL endpoint.
631
632USAGE
633 $ apollo service:download OUTPUT
634
635ARGUMENTS
636 OUTPUT [default: schema.json] Path to write the introspection result to. Supports .json output only.
637
638OPTIONS
639 -c, --config=config Path to your Apollo config file
640
641 -g, --graph=graph The ID of the graph in the Apollo registry for which to download the schema for. Overrides
642 config file if provided.
643
644 -k, --skipSSLValidation Allow connections to an SSL site without certs
645
646 -v, --variant=variant The variant to download the schema of
647
648 --endpoint=endpoint The URL for the CLI use to introspect your service
649
650 --header=header Additional header to send during introspection. May be used multiple times to add multiple
651 headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag.
652
653 --key=key The API key to use for authentication to Apollo
654
655ALIASES
656 $ apollo schema:download
657```
658
659_See code: [src/commands/service/download.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/service/download.ts)_
660
661## `apollo service:list`
662
663List the services in a graph
664
665```
666List the services in a graph
667
668USAGE
669 $ apollo service:list
670
671OPTIONS
672 -c, --config=config Path to your Apollo config file
673
674 -g, --graph=graph The ID of the graph in the Apollo registry for which to list implementing services. Overrides
675 config file if set.
676
677 -v, --variant=variant The variant to list implementing services for
678
679 --endpoint=endpoint The URL for the CLI use to introspect your service
680
681 --header=header Additional header to send during introspection. May be used multiple times to add multiple
682 headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag.
683
684 --key=key The API key to use for authentication to Apollo
685```
686
687_See code: [src/commands/service/list.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/service/list.ts)_
688
689## `apollo service:push`
690
691Push a service definition to Apollo
692
693```
694Push a service definition to Apollo
695
696USAGE
697 $ apollo service:push
698
699OPTIONS
700 -c, --config=config Path to your Apollo config file
701
702 -g, --graph=graph The ID of the graph in Apollo to publish your service to. Overrides config file if
703 set.
704
705 -v, --variant=variant The variant to publish your service to in Apollo
706
707 --author=author The author to associate with this publication
708
709 --branch=branch The branch name to associate with this publication
710
711 --commitId=commitId The SHA-1 hash of the commit to associate with this publication
712
713 --endpoint=endpoint The URL for the CLI use to introspect your service
714
715 --header=header Additional header to send during introspection. May be used multiple times to add
716 multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header`
717 flag.
718
719 --key=key The API key to use for authentication to Apollo
720
721 --localSchemaFile=localSchemaFile Path to one or more local GraphQL schema file(s), as introspection result or SDL.
722 Supports comma-separated list of paths (ex.
723 `--localSchemaFile=schema.graphql,extensions.graphql`)
724
725 --serviceName=serviceName Provides the name of the implementing service for a federated graph
726
727 --serviceRevision=serviceRevision Provides a unique revision identifier for a change to an implementing service on a
728 federated service push. The default of this is a git sha
729
730 --serviceURL=serviceURL Provides the url to the location of the implementing service for a federated graph
731
732ALIASES
733 $ apollo schema:publish
734```
735
736_See code: [src/commands/service/push.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/service/push.ts)_
737<!-- commandsstop -->
738
739# Configuration
740
741The Apollo CLI and VS Code extension can be configured with an Apollo config file. Apollo configuration is stored as a plain object in an `apollo.config.js` file which exports the configuration. For more information about configuring an Apollo project, see: https://www.apollographql.com/docs/devtools/apollo-config/.
742
743> Note: the use of the `apollo` key in the project's package.json file for configuration is deprecated, and will no longer be supported in Apollo v3
744
745You'll need to set up your Apollo configuration for all the features of the Apollo CLI and VS Code extension to work correctly. For full details on how to do that, [visit our docs](https://www.apollographql.com/docs/devtools/apollo-config/). A basic configuration (`apollo.config.js` style) looks something like this:
746
747```js
748module.exports = {
749 client: {
750 name: "My Client Project",
751 service: "my-service-name"
752 }
753};
754```
755
756# Code Generation
757
758## Accompanying Libraries
759
760See [Apollo iOS](https://github.com/apollographql/apollo-ios) for details on the mapping from GraphQL results to Swift types, as well as runtime support for executing queries and mutations. For Scala, see [React Apollo Scala.js](https://github.com/apollographql/react-apollo-scalajs) for details on how to use generated Scala code in a Scala.js app with Apollo Client.
761
762## `gql` template support
763
764If the source file for generation is a JavaScript or TypeScript file, the codegen will try to extrapolate the queries inside the [gql tag](https://github.com/apollographql/graphql-tag) templates.
765
766The tag name is configurable using the CLI `--tagName` option.
767
768## Typescript and Flow
769
770When using the codegen command with Typescript or Flow, make sure to add the `__typename` introspection field to every selection set within your graphql operations.
771
772If you're using a client like `apollo-client` that does this automatically for your GraphQL operations, pass in the `--addTypename` option to `apollo codegen:generate` to make sure the generated Typescript and Flow types have the `__typename` field as well. This is required to ensure proper type generation support for `GraphQLUnionType` and `GraphQLInterfaceType` fields.
773
774## Why is the \_\_typename field required?
775
776Using the type information from the GraphQL schema, we can infer the possible types for fields. However, in the case of a `GraphQLUnionType` or `GraphQLInterfaceType`, there are multiple types that are possible for that field. This is best modeled using a disjoint union with the `__typename`
777as the discriminant.
778
779For example, given a schema:
780
781```graphql
782...
783
784interface Character {
785 name: String!
786}
787
788type Human implements Character {
789 homePlanet: String
790}
791
792type Droid implements Character {
793 primaryFunction: String
794}
795
796...
797```
798
799Whenever a field of type `Character` is encountered, it could be either a Human or Droid. Human and Droid objects
800will have a different set of fields. Within your application code, when interacting with a `Character` you'll want to make sure to handle both of these cases.
801
802Given this query:
803
804```graphql
805query Characters {
806 characters(episode: NEW_HOPE) {
807 name
808
809 ... on Human {
810 homePlanet
811 }
812
813 ... on Droid {
814 primaryFunction
815 }
816 }
817}
818```
819
820Apollo Codegen will generate a union type for Character.
821
822```javascript
823export type CharactersQuery = {
824 characters: Array<
825 | {
826 __typename: "Human",
827 name: string,
828 homePlanet: ?string
829 }
830 | {
831 __typename: "Droid",
832 name: string,
833 primaryFunction: ?string
834 }
835 >
836};
837```
838
839This type can then be used as follows to ensure that all possible types are handled:
840
841```javascript
842function CharacterFigures({ characters }: CharactersQuery) {
843 return characters.map(character => {
844 switch (character.__typename) {
845 case "Human":
846 return (
847 <HumanFigure
848 homePlanet={character.homePlanet}
849 name={character.name}
850 />
851 );
852 case "Droid":
853 return (
854 <DroidFigure
855 primaryFunction={character.primaryFunction}
856 name={character.name}
857 />
858 );
859 }
860 });
861}
862```
863
864# Contributing
865
866[![Build Status](https://circleci.com/gh/apollographql/apollo-tooling.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-tooling)
867
868This repo is composed of multiple packages managed by Lerna. The `apollo-cli` contains the core CLI commands. The `apollo-codegen-core` package contains all the compiler APIs needed to implement code generation support for new languages. The other `apollo-codegen-*` packages implement code generation support for individual languages.
869
870Running tests locally:
871
872```
873npm install
874npm test
875```
876
877You can also run `npm` commands within package folders after you have bootstrapped the repository (part of `npm install`).
878
879> Note: if you have issues, try `npm run clean && npm i` to get a fresh install of the packages. Occasionally problems arise when removed dependencies stay around
880
881## Nock tests
882
883To display the debugging messages for nock, run the following command:
884
885```bash
886DEBUG=nock.* npm test
887```
888
889It can also be helpful to print standard out during testing. To enable logging, add the following configuration to the `stdout` function call during test creation:
890
891```
892.stdout({ print: true })
893```
894
895## Active Development / Debugging
896
897To simplify the development process, you may want to step through and debug commands whose behavior you're modifying. To do this, run the executable with node in debug mode like so, where `<command>` is a valid CLI command like `client:check` or `service:push`:
898
899```
900node --inspect-brk=9002 packages/apollo/bin/run <command>
901```
902
903If you're using VS Code, you can run the included "Attach to CLI Debugger" launch task and debug right from VS Code! Otherwise, you may use the Chrome inspector or [other Node debugger](https://nodejs.org/en/docs/guides/debugging-getting-started/) of your choice.
904
905## Regenerating Mocked Network Data
906
907Some integration tests rely on mocked server data (service:check for example). Mock data is generated by making real network requests and recording those requests with [`nock`'s recording feature](https://github.com/nock/nock#recording). Stop mocking network calls and add `nock.recorder.rec()` before network calls are made. For `service:check`, change `apiKey` to a real Apollo API key. Then run the tests and nock will output code to mock requests to the console. You can (and probably should) pare down the request to be less brittle (by only checking for an operation name, for example). See [`src/commands/service/__tests__/check.test.ts`](./packages/apollo/src/commands/service/__tests__/check.test.ts) for an example of how a mocked network request will look.
908
909
910## Publishing
911
9121. Make sure the `CHANGELOG.md` is updated with all changes committed since the last release. Make sure the versions for each package to update are correct, and there's a blank `Upcoming` section for future work.
9132. Run `npm run release:version-bump -- <bumpish>`
914 - Can use major, minor, patch, prepatch, etc for the bump type. If not used, the command will prompt and ask for the bump type.
915 - This command updates git tags locally and on GitHub
9163. Run npm run release:start-ci-publish locally
917 - Pushes a `publish/XXXXXXXXXX` tag to GitHub to trigger circle CI build
9184. Circle will notify the appropriate Apollo team slack channel when ready to release
919 - Slack channel member will confirm through the Apollo Deploy Bot
920 - Circle will release to all channels (npm, cli binary to s3, vscode marketplace)
921 - Another slack bot notification will confirm success of release.
922
923## Maintainers
924
925- [@JakeDawkins](https://github.com/jakedawkins) (Apollo)