apollo-tooling
Apollo CLI
[2022-07-07] Are you here for codegen? We highly recommend using graphql-code-generator instead. Codegen in this repo is no longer supported and will be removed completely in a future version. For additional migration details, please see this fantastic writeup by @dotansimha: #2053
[2022-01-21] Note – Upcoming Deprecation Plans: We (Apollo) are working towards fully deprecating this repository and its related projects. Most of the functionality in this repository has been replaced by newer projects and the rest will be soon. We’ll share detailed migration documentation when everything here is ready to be officially deprecated, but just a heads up in case you’re planning on adopting anything here for a new project (which you still can of course if the tooling here works for you – support for this tooling will be minimal however).
[2021-07-23] Note – Housekeeping: Apollo’s GraphQL VSCode extension is no longer housed in this repository. It is now maintained separately in this repo.
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.
Usage
Disclaimer: The following API documentation is only for the latest version released on NPM, and may not be accurate for previous or future versions.
$ npm install -g apollo $ apollo COMMAND running command... $ apollo (-v|--version|version) apollo/2.33.11 darwin-arm64 node-v16.14.2 $ apollo --help [COMMAND] USAGE $ apollo COMMAND ...
Commands
-
apollo client:check
-
apollo client:codegen [OUTPUT]
-
apollo client:download-schema OUTPUT
-
apollo client:extract OUTPUT
-
apollo client:push
-
apollo help [COMMAND]
-
apollo plugins
-
apollo plugins:inspect PLUGIN...
-
apollo plugins:install PLUGIN...
-
apollo plugins:link PLUGIN
-
apollo plugins:uninstall PLUGIN...
-
apollo plugins:update
-
apollo service:check
-
apollo service:delete
-
apollo service:download OUTPUT
-
apollo service:list
-
apollo service:push
apollo client:check
Check a client project against a pushed service
USAGE
$ apollo client:check
OPTIONS
-c, --config=config
Path to your Apollo config file
-g, --graph=graph
The ID for the graph in Apollo to operate client commands with.
Overrides config file if set.
-v, --variant=variant
The variant of the graph in Apollo to associate this client to
--clientName=clientName
Name of the client that the queries will be attached to
--clientReferenceId=clientReferenceId
Reference id for the client which will match ids from client traces,
will use clientName if not provided
--clientVersion=clientVersion
The version of the client that the queries will be attached to
--endpoint=endpoint
The URL for the CLI use to introspect your service
--excludes=excludes
Glob of files to exclude for GraphQL operations. Caveat: this doesn't
currently work in watch mode
--header=header
Additional header to send during introspection. May be used multiple
times to add multiple headers. NOTE: The `--endpoint` flag is REQUIRED
if using the `--header` flag.
--includes=includes
Glob of files to search for GraphQL operations. This should be used to
find queries *and* any client schema extensions
--key=key
The API key to use for authentication to Apollo
--queries=queries
Deprecated in favor of the includes flag
--tagName=tagName
Name of the template literal tag used to identify template literals
containing GraphQL queries in Javascript/Typescript code
See code: src/commands/client/check.ts
apollo client:codegen [OUTPUT]
Generate static types for GraphQL queries. Can use the published schema in the Apollo registry or a downloaded schema.
USAGE
$ apollo client:codegen [OUTPUT]
ARGUMENTS
OUTPUT
Directory to which generated files will be written.
- For TypeScript/Flow generators, this specifies a directory relative
to each source file by default.
- For TypeScript/Flow generators with the "outputFlat" flag is set,
and for the Swift generator, this specifies a file or directory
(absolute or relative to the current working directory) to which:
- a file will be written for each query (if "output" is a directory)
- all generated types will be written
- For all other types, this defines a file (absolute or relative to
the current working directory) to which all generated types are
written.
OPTIONS
-c, --config=config
Path to your Apollo config file
-g, --graph=graph
The ID for the graph in Apollo to operate client commands with.
Overrides config file if set.
-v, --variant=variant
The variant of the graph in Apollo to associate this client to
--[no-]addTypename
[default: true] Automatically add __typename to your queries, can be
unset with --no-addTypename
--clientName=clientName
Name of the client that the queries will be attached to
--clientReferenceId=clientReferenceId
Reference id for the client which will match ids from client traces,
will use clientName if not provided
--clientVersion=clientVersion
The version of the client that the queries will be attached to
--customScalarsPrefix=customScalarsPrefix
Include a prefix when using provided types for custom scalars
--endpoint=endpoint
The URL for the CLI use to introspect your service
--excludes=excludes
Glob of files to exclude for GraphQL operations. Caveat: this doesn't
currently work in watch mode
--globalTypesFile=globalTypesFile
By default, TypeScript will put a file named "globalTypes.ts" inside
the "output" directory. Set "globalTypesFile" to specify a different
path. Alternatively, set "tsFileExtension" to modify the extension of
the file, for example "d.ts" will output "globalTypes.d.ts"
--header=header
Additional header to send during introspection. May be used multiple
times to add multiple headers. NOTE: The `--endpoint` flag is REQUIRED
if using the `--header` flag.
--includes=includes
Glob of files to search for GraphQL operations. This should be used to
find queries *and* any client schema extensions
--key=key
The API key to use for authentication to Apollo
--localSchemaFile=localSchemaFile
Path to one or more local GraphQL schema file(s), as introspection
result or SDL. Supports comma-separated list of paths (ex.
`--localSchemaFile=schema.graphql,extensions.graphql`)
--mergeInFieldsFromFragmentSpreads
Merge fragment fields onto its enclosing type
--namespace=namespace
The namespace to emit generated code into.
--omitDeprecatedEnumCases
Omit deprecated enum cases from generated code [Swift only]
--only=only
Parse all input files, but only output generated code for the
specified file [Swift only]
--operationIdsPath=operationIdsPath
Path to an operation id JSON map file. If specified, also stores the
operation ids (hashes) as properties on operation types [currently
Swift-only]
--outputFlat
By default, TypeScript/Flow will put each generated file in a
directory next to its source file using the value of the "output" as
the directory name. Set "outputFlat" to put all generated files in the
directory relative to the current working directory defined by
"output".
--passthroughCustomScalars
Use your own types for custom scalars
--queries=queries
Deprecated in favor of the includes flag
--suppressSwiftMultilineStringLiterals
Prevents operations from being rendered as multiline strings [Swift
only]
--tagName=tagName
Name of the template literal tag used to identify template literals
containing GraphQL queries in Javascript/Typescript code
--target=target
(required) Type of code generator to use (swift | typescript | flow |
scala | json | json-modern (exposes raw json types))
--tsFileExtension=tsFileExtension
By default, TypeScript will output "ts" files. Set "tsFileExtension"
to specify a different file extension, for example "d.ts"
--useFlowExactObjects
Use Flow exact objects for generated types [flow only]
--useFlowReadOnlyTypes
Use read only types for generated types [flow only]. **Deprecated in
favor of `useReadOnlyTypes`.**
--useReadOnlyTypes
Use read only types for generated types [flow | typescript]
--watch
Watch for file changes and reload codegen
ALIASES
$ apollo codegen:generate
See code: src/commands/client/codegen.ts
apollo client:download-schema OUTPUT
Download a schema from Apollo or a GraphQL endpoint in JSON or SDL format
USAGE
$ apollo client:download-schema OUTPUT
ARGUMENTS
OUTPUT [default: schema.json] Path to write the introspection result
to. Can be `.graphql`, `.gql`, `.graphqls`, or `.json`
OPTIONS
-c, --config=config
Path to your Apollo config file
-g, --graph=graph
The ID for the graph in Apollo to operate client commands with.
Overrides config file if set.
-v, --variant=variant
The variant of the graph in Apollo to associate this client to
--clientName=clientName
Name of the client that the queries will be attached to
--clientReferenceId=clientReferenceId
Reference id for the client which will match ids from client traces,
will use clientName if not provided
--clientVersion=clientVersion
The version of the client that the queries will be attached to
--endpoint=endpoint
The URL for the CLI use to introspect your service
--excludes=excludes
Glob of files to exclude for GraphQL operations. Caveat: this doesn't
currently work in watch...