Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@lightspeed/apollo-generate-types
Advanced tools
Tool to generate the typescript types of the GraphQL queries, based on the GraphQL schema
@lightspeed/apollo-generate-types
Generate TypeScript types for GraphQL queries based on a schema, with a watch command to auto-update on changes.
Install dependency in your app:
yarn add @lightspeed/apollo-generate-types -D
yarn apollo-generate-types [--output=<dir>] [--output-filename=<filename>] [--watch] --schema=<GraphQLSchemaPath> [globFiles]
We recommend creating an npm script to run the command. In your package.json
inside scripts
:
"gql:generate-types": "apollo-generate-types --schema=./src/__generated__/graphql-schema.graphql 'src/**/*.ts,src/**/*.tsx'"
You can then call yarn gql:generate-types
to generate types based on the schema.
For development, we recommend running the gql:generate-types
script in watch mode:
"dev": "NODE_ENV=development nodemon server.js && yarn gql:generate-types --watch"
Whenever a query is added to a .ts
or .tsx
file a type file will be generated in the output
dir. For example:
const GET_PRODUCTS = gql`
query getProducts($term: String) {
products(term: $term, pageSize: 5) {
edges {
node {
id
name
}
}
}
}
`;
Will generate a src/__generated__/getProducts.ts
file with types for this query.
Name | Required | Default | Description |
---|---|---|---|
--schema=<GraphQLSchemaPath> | Yes | - | Path to GraphQL schema file |
--output=<dir> | No | src/__generated__/ | Path where files will be generated |
--output-filename=<file> | No | <graphql-schema-file-name>-types.ts | Name of the generated files for full schema types |
--watch | No | - | If a file containing a gql query or the schema changes, types will be re-generated |
[globFiles] | No | - | Files to look for gql queries. It can be a glob parameter. If no files is set, then the process will only watch the schema |
yarn apollo-generate-types --schema=schema.graphql 'src/**/*.ts,src/**/*.tsx'
yarn apollo-generate-types --output=generated --watch --schema=schema.graphql 'src/**/*.ts,src/**/*.tsx'
yarn apollo-generate-types --schema=schema.graphql
Q: I have the error GraphQLError: Cannot query field "XXXX" on type "Query"
when I run the command.
A: It's an issue with your graphql package in your project. It must be graphql >=14.4.2
FAQs
Tool to generate the typescript types of the GraphQL queries, based on the GraphQL schema
The npm package @lightspeed/apollo-generate-types receives a total of 16 weekly downloads. As such, @lightspeed/apollo-generate-types popularity was classified as not popular.
We found that @lightspeed/apollo-generate-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.