Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
apollo-codegen
Advanced tools
Readme
This is a tool to generate API code or type annotations based on a GraphQL schema and query documents.
It currently generates Swift code, TypeScript annotations and Flow annotations, we hope to add support for other targets in the future.
See Apollo iOS for details on the mapping from GraphQL results to Swift types, as well as runtime support for executing queries and mutations.
If you want to experiment with the tool, you can install the apollo-codegen
command globally:
npm install -g apollo-codegen
introspect-schema
To download a GraphQL schema by sending an introspection query to a server:
apollo-codegen introspect-schema http://localhost:8080/graphql --output 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>"
.
You can use the insecure
option to ignore any SSL errors (for example if the server is running with self-signed certificate).
Note: The command for downloading an introspection query was named download-schema
but it was renamed to introspect-schema
in order to have a single command for introspecting local or remote schemas. The old name download-schema
is still available is an alias for backward compatibility.
To generate a GraphQL schema introspection JSON from a local GraphQL schema:
apollo-codegen introspect-schema schema.graphql --output schema.json
generate
This tool will generate Swift code by default from a set of query definitions in .graphql
files:
apollo-codegen generate **/*.graphql --schema schema.json --output API.swift
You can also generate type annotations for TypeScript or Flow using the --target
option:
# TypeScript
apollo-codegen generate **/*.graphql --schema schema.json --target typescript --output schema.ts
# Flow
apollo-codegen generate **/*.graphql --schema schema.json --target flow --output schema.flow.js
gql
template supportIf the source file for generation is a javascript or typescript file, the codegen will try to extrapolate the queries inside the gql tag templates.
Running tests locally:
npm install
npm test
FAQs
Generate API code or type annotations based on a GraphQL schema and query documents
We found that apollo-codegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).