# graphql-let [](https://github.com/piglovesyou/graphql-let/actions/workflows/nodejs.yml) [](https://www.npmjs.com/package/graphql-let) [](https://www.npmjs.com/package/graphql-let) [](https://github.com/kentcdodds/babel-plugin-macros) [](https://stakes.social/0xaC5f6A59f4b40eCF0815eB53Af49A83834b47005) A webpack loader/babel-plugin/babel-plugin-macros/CLI/generated file manager of GraphQL code generator. Try [Create React App example](https://github.com/piglovesyou/cra-template-graphql#readme) and [Next.js example](https://github.com/zeit/next.js/blob/canary/examples/with-typescript-graphql/README.md#readme) integrating graphql-let. [A blog post](https://the-guild.dev/blog/graphql-let) 🛰 **[Migration guide to v0.18.0](https://github.com/piglovesyou/graphql-let/releases/tag/v0.18.0)** ## Table of Contents - [Why this exists](#why-this-exists) - [Entrypoints and features](#entrypoints-and-features) - [Getting started with webpack loader](#getting-started-with-webpack-loader) - [Getting started with babel-plugin-macros](#getting-started-with-babel-plugin-macros) - [Getting started with Babel Plugin](#getting-started-with-babel-plugin) - [Difference between .graphql-let.yml and codegen.yml](#difference-between-graphql-letyml-and-codegenyml) - [Jest Transformer](#jest-transformer) - [Experimental feature: Resolver Types](#experimental-feature-resolver-types) - [FAQ](#faq) - [Contribution](#contribution) - [License](#license) ## Why this exists One of the strengths of GraphQL is [enforcing data types on runtime](https://graphql.github.io/graphql-spec/June2018/#sec-Value-Completion). Further, TypeScript and [GraphQL code generator](https://graphql-code-generator.com/) help it even safer by typing your codebase statically. Both make a truly type-protected development environment with rich IDE assists. graphql-let enhances that development pattern by minimizing configuration setup, introducing intuitive syntax, and comfortable development experience through HMR (hot module replacement). ```typescript jsx import { useNewsQuery } from './news.graphql' // webpack // or import { gql, load } from "graphql-let/macro" // babel-plugin-macros const { useNewsQuery } = gql("query News { braa }") const News: React.FC = () => { // Typed already️⚡️ const { data: { news } } = useNewsQuery() return
| Entry pointsYou need .graphql-let.yml and: | Getting codegen result from | Use values of codegen result | Use types of codegen result | Pros/Cons |
|---|---|---|---|---|
| webpack loader Configure "graphql-let/loader"to files "/.*\.(tsx?|graphql)$/" in webpack.config.(js|ts)
| File | ✅ Import both value and types from a GraphQL document as a module.import { useQuery, Query } from "./a.graphql" |
HMR works as expected. Webpack config is required even though your project only uses Babel |
|
| String literal | ✅ byimport { gql } from "graphql-let" |
⚠️ You can, but you have to find the internal d.ts.import { gql } from "graphql-let" |
||
| babel-plugin-macros If you've already setupbabel-plugin-macros,no config needed any more | File | ✅ byimport { load } from "graphql-let/macro" |
⚠️ You can, but you have to find the internally generated d.ts.import { load } from "graphql-let/macro" |
Easiest to integrate if your project already has babel-plugin-macros. create-react-app is the great fit.Cannot load types from function call. Modifying *.graphql doesn't emit HMR. |
| String literal | ✅ byimport { gql } from "graphql-let/macro" |
⚠️ You can, but you have to find the internally generated d.ts.import { gql } from "graphql-let/macro" |
||
| babel-plugin Put "graphql-let/babel"to you .babelrc as a plugin | File | ✅ byimport { load } from "graphql-let" |
⚠️ You can, but you have to find the internally generated d.ts.import { load } from "graphql-let" |
Mostly equivalent to babel-plugin-macros, but you always need your .babelrc configuration. Possibly, "import "./a.graphql"" could be implemented, but not supported yet.Cannot load types from function call. Modifying *.graphql doesn't emit HMR.Possibly I can make "--watch" option butlots to do for dependency management to detect file change. |
| String literal | ✅ byimport { gql } from "graphql-let" |
⚠️ You can, but you have to find the internally generated d.ts.import { gql } from "graphql-let" |
||