All Projects → firede → Ts Transform Graphql Tag

firede / Ts Transform Graphql Tag

Licence: mit
Compiles GraphQL tagged template strings using graphql-tag in TypeScript files.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Ts Transform Graphql Tag

Graphql Serverless
GraphQL (incl. a GraphiQL interface) middleware for the webfunc serverless web framework.
Stars: ✭ 124 (-2.36%)
Mutual labels:  graphql
Graphqlcore
Learn how to implement scalable APIs with GraphQL and ASP.NET Core. Branch wise code with relevant topic for smooth and easy walkthrough.
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Serverless Prisma
AWS Serverless Prisma Boilerplate
Stars: ✭ 126 (-0.79%)
Mutual labels:  graphql
Graphql Schema Registry
GraphQL schema registry
Stars: ✭ 124 (-2.36%)
Mutual labels:  graphql
Goofi
✨Let's contribute to OSS. Here is how to find good first issues in GitHub. "goofi" is an abbreviation of "good first issues".
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Directus
Open-Source Data Platform 🐰 — Directus wraps any SQL database with a real-time GraphQL+REST API and an intuitive app for non-technical users.
Stars: ✭ 13,190 (+10285.83%)
Mutual labels:  graphql
Api
🚀 GraphQL & REST APIs to explore all the rockets, launches & other SpaceX's data
Stars: ✭ 123 (-3.15%)
Mutual labels:  graphql
Catchup
An app for catching up on things.
Stars: ✭ 1,690 (+1230.71%)
Mutual labels:  graphql
Apollo2 Subscriptions How To
Apollo Server 2 how to setup subscriptions
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Relay Example
[READONLY] 💝 Examples of common Relay patterns used in real-world applications. This repository is automatically exported from https://github.com/adeira/universe via Shipit
Stars: ✭ 126 (-0.79%)
Mutual labels:  graphql
Nextjs Pwa Graphql Sql Boilerplate
Next.js serverless PWA with GraphQL (Apollo) + Postgres SQL boilerplate
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Agoo C
Agoo webserver in C.
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Gqless Movies Demo
A movies app using Hasura and gqless
Stars: ✭ 126 (-0.79%)
Mutual labels:  graphql
Aqls Server
An intelligent full-stack GraphQL subscription and analytics module. Server-side analytics processing, self-auditing router, and resolver plugins.
Stars: ✭ 125 (-1.57%)
Mutual labels:  graphql
Awesome Apollo Graphql
A curated list of amazingly awesome things regarding Apollo GraphQL ecosystem 🌟
Stars: ✭ 126 (-0.79%)
Mutual labels:  graphql
Apollo upload server Ruby
Stars: ✭ 124 (-2.36%)
Mutual labels:  graphql
Dataloader
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
Stars: ✭ 11,040 (+8592.91%)
Mutual labels:  graphql
Go Proto Gql
Protobuff plugins for generating graphql schema and golang to graphql bindings. Also supports a graphql gateway (Alpha)
Stars: ✭ 127 (+0%)
Mutual labels:  graphql
Talk
A better commenting experience from Vox Media
Stars: ✭ 1,717 (+1251.97%)
Mutual labels:  graphql
Nextjs Hasura Boilerplate
🎨 Boilerplate for building applications using Hasura and Next.js
Stars: ✭ 126 (-0.79%)
Mutual labels:  graphql

ts-transform-graphql-tag

npm Travis FOSSA Status license

Compiles GraphQL tagged template strings using graphql-tag in TypeScript files.

The plugin was mostly inspired by great Babel's plugin babel-plugin-graphql-tag.

Warning:

Because I moved to @babel/preset-typescript from typescript, this package is no longer maintained.
However, if you are still using it, PR is welcome.

Motivation

Compiling GraphQL queries at the build time:

  • reduces the script initialization time; and
  • removes the graphql-tag dependency

Removing the graphql-tag dependecy from the bundle saves approx. 50 KB.

Implementation

  • Searches for imports of graphql-tag and removes them.
  • Searches for tagged template literals with gql identifier and compiles them using graphql-tag.

Installation

The following command adds the packages to the project as a development-time dependency:

npm i --save-dev ts-transform-graphql-tag

This also depends on graphql and graphql-tag so you'll need those in your project as well (if you don't already have them):

# usually, this is a production dependency
npm i graphql

# add this as a development-time dependency
npm i --save-dev graphql-tag

Usage

Integration with Webpack

If you using Webpack, there are two popular TypeScript loaders that support specifying custom transformers:

Both loaders use the same setting getCustomTransformers which is an optional function that returns { before?: Transformer[], after?: Transformer[] }. In order to inject the transformer into compilation, add it to before transformers array, like: { before: [getTransformer()] }.

awesome-typescript-loader

In the webpack.config.js file in the section where awesome-typescript-loader is configured as a loader:

// 1. import `getTransformer` from the module
var getTransformer = require('ts-transform-graphql-tag').getTransformer

// 2. create a transformer and add getCustomTransformer method to the loader config
var config = {
  /// ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'awesome-typescript-loader',
        options: {
          // ... other loader's options
          getCustomTransformers: () => ({ before: [getTransformer()] })
        }
      }
    ]
  }
  /// ...
}

ts-loader

In the webpack.config.js file in the section where ts-loader is configured as a loader:

// 1. import `getTransformer` from the module
var getTransformer = require('ts-transform-graphql-tag').getTransformer

// 2. create a transformer and add getCustomTransformer method to the loader config
var config = {
  // ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
          // ... other loader's options
          getCustomTransformers: () => ({ before: [getTransformer()] })
        }
      }
    ]
  }
  // ...
};

Integration with FuseBox

FuseBox is a blazing fast (TypeScipt first) bundler/module loader.

In the fuse.ts file, you can configured like this:

// 1. import `getTransformer` from the module
import { getTransformer } from "ts-transform-graphql-tag"

// 2. create a transformer and add it to the `transformers.before` config
const fuse = FuseBox.init({
  // ... other init options
  transformers: {
    before: [
      getTransformer()
    ]
  }
})

Example

before

// with transformer
import gql from "graphql-tag"
export default gql`query Hello {hello}`

after

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "Hello" }, "variableDefinitions": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "alias": undefined, "name": { "kind": "Name", "value": "hello" }, "arguments": [], "directives": [], "selectionSet": undefined }] } }], "loc": { "start": 0, "end": 19, "source": { "body": "query Hello {hello}", "name": "GraphQL request", "locationOffset": { "line": 1, "column": 1 } } } };

Need more example? run npm test and checkout test/fixture/actual/*.js.

Related

Thanks


MIT © Firede, built with ☕️ & 💖

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].