JSPM

@metaengine/graphql-react

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q66040F
  • License MIT

Generate React TypeScript hooks and models from GraphQL schemas with TanStack Query (useQuery/useMutation), typed queries, mutations & subscriptions, and the native Fetch API

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@metaengine/graphql-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @metaengine/graphql-react

    Generate React TypeScript hooks and models from GraphQL schemas.

    Typed queries, mutations & subscriptions, TanStack Query (useQuery/useMutation) integration, and the native Fetch API for React 18+.

    Install

    npm install --save-dev @metaengine/graphql-react

    Or use directly with npx:

    npx @metaengine/graphql-react <input> <output>

    Requirements

    • Node.js 18.0 or later
    • .NET 8.0 or later runtime (Download)

    Quick start

    npx @metaengine/graphql-react schema.graphql ./src/api \
      --tanstack-query \
      --documentation

    CLI options

    Option Description Default
    --fragments Emit reusable named fragments for object-type selections false
    --one-of-inputs Generate idiomatic @oneOf input types (tagged-union inputs) false
    --custom-scalar <Scalar=target> Map a GraphQL custom scalar to a TS type. Repeatable. See Custom scalar mappings -
    --base-url-env <name> Environment variable name for base URL (e.g. VITE_API_URL, NEXT_PUBLIC_API_URL) REACT_APP_API_BASE_URL
    --tanstack-query Enable TanStack Query integration (useQuery/useMutation) false
    --error-handling Smart error handling based on HTTP status semantics false
    --retries <max-attempts> Enable retries with exponential backoff (status codes 429, 503) -
    --documentation Generate JSDoc comments from SDL descriptions false
    --date-transformation Convert Date-typed scalar fields (e.g. DateTime) in responses to Date objects false
    --options-threshold <n> Parameter count for options object 4
    --service-suffix <suffix> Service naming suffix Api
    --types-barrel Emit an index.ts barrel per folder plus a root index.ts re-exporting everything false
    --clean Clean output directory (remove files not in generation) false
    --verbose Enable verbose logging false
    --help, -h Show help message -

    Custom scalar mappings

    GraphQL custom scalars resolve to idiomatic TypeScript types. Well-known scalars are mapped out of the box; any other custom scalar defaults to string.

    GraphQL scalar TypeScript type
    DateTime, Date, Time, DateTimeOffset Date
    Decimal, Long, BigInt, ULong, UInt, Short, Byte number
    UUID, Guid, Email, URL, URI string

    Use --custom-scalar to override the TS type emitted for a scalar. Repeatable. Unsupported targets are hard errors.

    Target Emitted TS type
    string string
    number number
    boolean boolean
    Date Date
    npx @metaengine/graphql-react schema.graphql ./src/api \
      --custom-scalar DateTime=string \
      --custom-scalar UUID=string

    Integer-like scalars (Long, BigInt, ULong) map to number by design so request variables survive JSON.stringify.

    See it live

    Try the generator with your own schema at https://www.metaengine.eu/converters.

    License

    MIT

    Support

    For issues and feature requests, please visit: https://github.com/meta-engine/graphql-react/issues