Apollo client code generator
This is a tool to generate client code based on a GraphQL schema and query documents.
It currently only generates Swift code, and only for a subset of GraphQL queries. Most importantly, fragments are not yet supported. See Apollo iOS for details on the proposed mapping from GraphQL results to Swift types, as well as runtime support for performing queries.
Getting Started
Apollo iOS Quickstart is a sample Xcode project that makes it easy to get started with a generated API for your own schema and queries.
Usage
If you want to experiment with the tool, you can install the apollo-codegen
command globally:
npm install apollo-codegen -g
To download a GraphQL schema by sending an introspection query to a server:
apollo-codegen download-schema http://localhost:8080/graphql --output GitHuntAPI/Definitions/schema.json
You can use the header
option to add additional HTTP headers to the request. For example, to include an authentication token, use --header "Authorization: Bearer <token>"
.
To generate Swift code from a set of query definitions in .graphql
files:
apollo-codegen generate GitHuntAPI/Definitions/**/*.graphql --schema GitHuntAPI/Definitions/schema.json --output GitHuntAPI/GitHuntAPI.swift
apollo@2.16.0
, apollo-codegen-swift@0.34.0
, apollo-language-server@1.13.0
, apollo-tools@0.4.0
, vscode-apollo@1.8.0
apollo@2.16.0
- Add
service:list
and tests #1358 and header #1377 - Update
service:list
test to use a simulated time to prevent relative dates causing snapshot failures #1374 - Update
service:check
to support --markdown
and --json
flags for federated schema #1378 - Exit status code 1 after composition errors in service:push #1403
- Update
service:check
to include graphCompositionId
in query params for UI #1401
apollo-codegen-swift@0.34.0
- Update Swift codegen to add operation name to generated query classes #1386
- Append terminating newline character to generated files #531
apollo-language-server@1.13.0
- Allow template literal placeholders that span multiple rows#1299
- Add support for extracting GraphQL documents from Ruby source files using
<<-GRAPHQL...GRAPHQL
heredoc. #1304
apollo-tools@0.4.0
- Handle
subscribe
in buildServiceDefinition
and add type in resolverMap
#1047
vscode-apollo@1.8.0
- Add support for Ruby source files using
<<-GRAPHQL...GRAPHQL
heredoc. #1304