httpyac-codegen-graphql

2.0.0 • Public • Published

httpyac-codegen-graphql

A GraphQL code generator preset for generating httpyac requests.

Usage

Add dependencies:

npm i -D @graphql-codegen/cli httpyac-codegen-graphql

Add codegen.yml:

schema: https://api.spacex.land/graphql
generates:
  spacex:
    preset: httpyac-codegen-graphql
    presetConfig:
      host: https://api.spacex.land/graphql
      variables:
        ship_query:
          id: HAWK
        cores_query:
          id: B1034

Generate requests:

npx graphql-codegen

Execute request:

httpyac spacex/ship_query.http --all

Configuration

See Config.ts for all configuration options.

The following configuration example uses a jwt to authenticate to appsync for introspection, and then generates .http files with authentication configured

# codegen.yml
generates:
  output:
    schema:
      # to use introspection - othwerise just specify a graph.schema file
      https://<your-appsync-id>.appsync-api.ap-southeast-2.amazonaws.com/graphql:
        headers:
          Authorization: <your jwt>
    preset: httpyac-codegen-graphql
    presetConfig:
      host: https://<your-appsync-id>.appsync-api.ap-southeast-2.amazonaws.com/graphql
      headers:
        # enables implicit auth
        Authorization: openid implicit oauth
      httpFileVariables:
        # your oauth settings
        oauth_clientId: <your-client-id>
        oauth_authorizationEndpoint: https://login.microsoftonline.com/<your-tenant>/oauth2/authorize?resource=<your-resource-id>
        oauth_tokenEndpoint: https://login.microsoftonline.com/<your-tenant>/oauth2/v2.0/token
      scripts:
        # this script needed to remove 'Bearer' as appsync doesn't use it
        - event: request
          script: request.headers.Authorization = request.headers.Authorization.slice('Bearer '.length);
      variables:
        # set any graphql variables in your generated requests
        some_query:
          someVariable: some-value

Developing

This preset can be cloned locally and developed. During development however, graphql-code-generator needs to be patched locally until this PR is merged.

Build & run

yarn
yarn build && yarn codegen

With logging

yarn build && yarn codegen | more

/httpyac-codegen-graphql/

    Package Sidebar

    Install

    npm i httpyac-codegen-graphql

    Weekly Downloads

    0

    Version

    2.0.0

    License

    ISC

    Unpacked Size

    14 kB

    Total Files

    7

    Last publish

    Collaborators

    • staff0rd