npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gqlpt/cli

v0.0.0-alpha.22

Published

Leverage AI to generate GraphQL queries from plain text.

Downloads

685

Readme

@gqlpt/cli

GQLPT CLI is a powerful command-line tool for generating type definitions for GQLPT (GraphQL Plain Text) queries. It scans your project for GQLPT usage and generates corresponding TypeScript type definitions.

Installation

npm install -g @gqlpt/cli

Usage

npx @gqlpt/cli generate <source> [options]

Arguments

  • <source>: Source directory to scan for GQLPT usage

Options

  • -a, --adapter <adapter>: The type of adapter to use, either 'openai' or 'anthropic' (default: 'openai')
  • -k, --key <key>: API key for the chosen adapter
  • -o, --output <path>: Custom output path for generated types
  • -t, --typeDefs <typeDefs>: Path to GraphQL schema definition file
  • -u, --url <url>: GraphQL server URL for schema introspection
  • -h, --headers <headers>: Headers to send to the GraphQL server (as JSON string)
  • -r, --raw: Output raw type definitions to stdout instead of writing to a file
  • --help: Display help for command

Environment Variables

You can set the following environment variables as alternatives to the CLI options:

  • GQLPT_ADAPTER: Corresponds to -a, --adapter
  • OPENAI_API_KEY or ANTHROPIC_API_KEY: Corresponds to -k, --key (depending on the chosen adapter)
  • GQLPT_OUTPUT_PATH: Corresponds to -o, --output
  • GQLPT_TYPE_DEFS: Corresponds to -t, --typeDefs
  • GQLPT_URL: Corresponds to -u, --url
  • GQLPT_HEADERS: Corresponds to -h, --headers
  • GQLPT_RAW: Corresponds to -r, --raw (set to any value to enable)

These environment variables can be overridden by their corresponding command-line options.

Examples

  1. Generate types using OpenAI adapter (default) with GitHub API:
npx @gqlpt/cli generate ./src -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN"}'
  1. Generate types using Anthropic adapter with GitHub API:
npx @gqlpt/cli generate ./src -a anthropic -k YOUR_ANTHROPIC_API_KEY -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN"}'
  1. Specify custom output path:
npx @gqlpt/cli generate ./src -o ./types/gqlpt-types.d.ts -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN"}'
  1. Use a specific GitHub API version:
npx @gqlpt/cli generate ./src -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN", "X-GitHub-Api-Version": "2022-11-28"}'
  1. Output raw type definitions to stdout:
npx @gqlpt/cli generate ./src -r -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN"}' > github-types.ts
  1. Combine multiple options:
npx @gqlpt/cli generate ./src -a openai -k YOUR_OPENAI_API_KEY -o ./types/github-types.d.ts -u https://api.github.com/graphql -h '{"Authorization": "Bearer YOUR_GITHUB_TOKEN", "X-GitHub-Api-Version": "2022-11-28"}' -r

How It Works

  1. The CLI scans the specified source directory for TypeScript files.
  2. It parses these files to find GQLPT query usage.
  3. Using the specified adapter (OpenAI or Anthropic), it generates TypeScript type definitions for the found queries.
  4. The generated types are either written to the specified output file or output to stdout if the -r, --raw option or GQLPT_RAW environment variable is set.

Notes

  • If neither typeDefs nor url is provided, the CLI will attempt to connect to a GraphQL server using the provided or default configuration.
  • When using a GraphQL server URL, the CLI will perform schema introspection to generate the types.
  • The default output path is node_modules/gqlpt/build/types.d.ts if not specified. Ensure you have write permissions for this directory.

Troubleshooting

If you encounter any issues, make sure:

  1. You have the correct API key set (either as an environment variable or using the -k, --key option).
  2. The source directory you're specifying exists and contains TypeScript files.
  3. If using typeDefs, the GraphQL schema file exists at the specified location.
  4. If using url, the GraphQL server is accessible and responds to introspection queries.
  5. You have write permissions for the output directory (when not using the -r, --raw option or GQLPT_RAW environment variable).

For any other issues, please open an issue on the GitHub repository.

License

MIT - Rocket Connect - https://github.com/rocket-connect