graphql-let

A webpack loader / babel-plugin / babel-plugin-macros / CLI / generated file manager of GraphQL code generator.

APACHE-2.0 License

Downloads
100.4K
Stars
453
Committers
19
graphql-let - Latest Release

Published by piglovesyou about 3 years ago

This patch version includes JEST v26 & v27 support. So nice, @cbmd!

graphql-let - v0.18.4

Published by piglovesyou over 3 years ago

Fixes #506 again. It now prints PRINT_PREFIX + err.toString() + '\n' + err.stack to use GraphQLError's .toString().

graphql-let - v0.18.2

Published by piglovesyou over 3 years ago

Fixes bug #506

graphql-let - v0.18.3

Published by piglovesyou over 3 years ago

Fixed bug #516

graphql-let - v0.18.1

Published by piglovesyou over 3 years ago

This release fixes a bug introduced in v0.18.0, described in #495. Thank you for all your investigation, @rtrembecky.

graphql-let - v0.18.0

Published by piglovesyou over 3 years ago

v0.18.0 release🎉

v0.18.0 fixed #60, which pointed out duplicated generation of schema types are in trouble, especially in production-size GraphQL schema possibly having massive stitched GrpahQL types.

The types, generated by the typescript plugin, are now all in graphql-let/__generated__/__types__ and shared by the other outputs. This requires you to migrate to use v0.18.0.

Many users realize this release. Thank you for the awesome Preset, @dotansimha. Thanks for your support, @StevenLangbroek, @acao.

Frame 11

Migration guide to v0.18.0

1. Install additional peer dependency

Please install @graphql-codegen/import-types-preset as an additional peer dependency.

yarn add -D @graphql-codegen/import-types-preset

2. Change .graphql-let.yml

Please change your config file as below. schemaEntrypoint became obsolete since it's always graphql-let/__generated__/__types__ from v0.18.0. The plugin typescript is recommended to remove, also because it's always in graphql-let/__generated__/__types__ now.

  schema: '**/*.graphqls'
- # "schemaEntrypoint" became obsolete
- schemaEntrypoint: lib/type-defs.graphqls
  documents: '**/*.graphql'
  plugins:
-   # "typescript" is not recommended
-   - typescript
    - typescript-operations
    - typescript-react-apollo
- cacheDir: __generated__
+ # ".cache" is now recommended to distinguish from "graphql-let/__generated__"
+ cacheDir: .cache

Please note that files in cacheDir are only intermediates. Exclude them from your TypeScript source.

  // tsconfig.json
  {
+   "excludes": [".cache"]
  }

Also, you're still able to have the plugin typescript in your config to keep importing types from the per-document output (*.graphql.d.ts). If so, you can skip step 3.

3. Change where you import types from

Again, your schema types are extracted and shared as graphql-let/__generated__/__types__. Please replace import parts of your source.

- import { User, ViewerDocument } from './viewer.graphql'
+ import { User } from 'graphql-let/__generated__/__types__'
+ import { ViewerDocument } from './viewer.graphql'

Optionally, you may want to have a path alias to it in your tsconfig.json for convenience.

  {
    "compilerOptions": {
      "noEmit": true,
      "esModuleInterop": true,
+     "baseUrl": ".",
+     "paths": {
+       "@graphql-types@": ["node_modules/@types/graphql-let/__generated__/__types__"]
+     }
    }
  }
import { User } from '@graphql-types@'

For Resolver Types users

Resolver Types also go in graphql-let/__generated__/__types__.

- import { Resolvers } from "./${config.schemaEntrypoint}";
+ import { Resolvers } from "graphql-let/__generated__/__types__";
graphql-let - v0.17.2

Published by piglovesyou over 3 years ago

Supports silent option to suppress all the standard output coming from graphql-let.

graphql-let - v0.17.0

Published by piglovesyou over 3 years ago

New features

babel-plugin-macros support

We now exports graphql-let/macro. It needs the least configuration. Now Create React App is able to use graphql-let without ejecting.

import { gql, load } from 'graphql-let/macro'

const { useQuery } = load('./a.graphql')

gql() and load() support in all entrypoints

gql() used to be only for Babel Plugin, but now you can use it in webpack loader and babel-plugin-macros.

import { gql, load } from 'graphql-let'              // If you use webpack loader or Babel Plugin
import { gql, load } from 'graphql-let/macro'  // If you use babel-plugin-macros

const { useNewsQuery } = gql("query News { braa }")
const { useViewerQuery } = load('./viewer.graphql')

Breaking changes

Import named export gql instead of default export for Babel Plugin

- import gql from 'graphql-let'
+ import { gql } from 'graphql-let'

A config name changes. "typeInjectEntrypoint" from "gqlDtsEntrypoint" in .graphql-let.yml.

- gqlDtsEntrypoint: graphql-let-custom-typings/index.d.ts
+ typeInjectEntrypoint: graphql-let-custom-typings/index.d.ts

Other improvements

More efficient code generation. It used to call GraphQL code generator API for each type (document file, schema file, string literal document) but now it calls it one for all types.

graphql-let - v0.16.3

Published by piglovesyou almost 4 years ago

#226 Accept absolute config file paths in webpack config

https://github.com/piglovesyou/graphql-let/commit/7a14dfe5845079ea845e0254f9dd2251f819f71f by @hasparus 🎉

#263 Accept config paths in jestTransformer

https://github.com/piglovesyou/graphql-let/commit/e59286a5ed649212f39df2d508325f39594bfe5e by @andrenanninga 🎉

graphql-let - v0.16.1

Published by piglovesyou about 4 years ago

configFile option in webpack loader options

Now you put your webpack.config.js in a subdirectory by passing a path to .graphql-let.yml. Excellent work, @hasparus!!

Test

graphql-let - v0.15.1

Published by piglovesyou about 4 years ago

Environment variable interpolation

.graphql-let.yml can contain environment variables. Please read the docs of string-env-interpolation for more details.

schema:
  - ${GRAPHQL_ENDPOINT}:
      headers:
        Authorization: Bearer ${ACCESS_TOKEN}
  - lib/type-defs.graphqls
graphql-let - v0.15.0

Published by piglovesyou about 4 years ago

GraphQL fragments through # import syntax🚀🚀🚀

The more your project gets bigger, the more you get chances to have duplicated GraphQL documents. # import is useful when you share common definitions as GraphQL fragments.

Define your fragment named as partial.graphql

fragment Partial on User {
    id
    name
}

then import it and apply.

# import Partial from './partial.graphql'

query Viewer {
    viewer {
        ...Partial
    }
}

Glob and multiple schema pointers as schema: **/*.graphqls💫

Now specifying multiple pointers in schema is available.

schema:
    - "src/**/*.graphqls"
    - "lib/**/*.graphqls"

Breaking change: You need schemaEntrypoint if you use Resolver Types

Since you can specify multiple schema files in the schema field. Please specify

schemaEntrypoint: lib/schema.graphqls

Then graphql-let generates lib/schema.graphqls.d.ts as Resolver Types.

Breaking change: You need to specify withHooks: true option if you use @graphql-codegen/react-apollo@2 and React Hooks functions

You'll need withHooks: true option in .graphql-let.yml config, if:

  • you upgrade graphql-let from <15 to >=15
  • you use @graphql-codegen/react-apollo@2

The background of this is mainly because of my decision failure.

  • @graphql-codegen/react-apollo@2's default setting is withHOC: true; withHooks: false
  • @graphql-codegen/react-apollo@3 is withHOC: false; withHooks: true
  • In graphql-let < 15, I passed hard code options of withHOC: false; withHooks: true, since I wanted it😣
  • From graphql-let >= 15, I erased the hard code options in order to passes most of the user config options through to GraphQL code generator API ←Breaking change

Users cloned source from vercel/next.js/examples/with-typescript-graphql recently should fall into this category.

graphql-let - v0.14.0

Published by piglovesyou about 4 years ago

Inline GraphQL document support by Babel Plugin⚡️⚡️⚡️

Please refer to the document to know how to set up.

graphql-let - v0.13.0

Published by piglovesyou about 4 years ago

Jest Transformer is now available by #126 @irrelevelephant 🎉

Please refer to the document to know how to use it.

graphql-let - v0.12.1

Published by piglovesyou about 4 years ago

A bug fix: https://github.com/piglovesyou/graphql-let/issues/118#issuecomment-667028475, thanks to the perfect test case by @marklawlor

Before: TS API will write the number of .d.tss more than .ts(x)s when a .ts(x) imports modules of project files and it succeeds to resolve the file. Here I described when it happens.

After: We should filter .d.ts only for .ts(x)s that we put as entry points. Now it does so the number of generated .d.ts must always be identical to the input .ts(x)s.

I refactored the code additionally.

graphql-let - v0.12.0

Published by piglovesyou over 4 years ago

Accept object in schema in .graphql-let.yml by 2a6ceccf67c6b51708ec4672f4e40f42be654612 @salzhrani 🎉

Now you can specify an authorization token to GraphQL endpoint, for example.

schema:
  https://api.github.com/graphql:
    headers:
      authorization: bearer YOUR_TOKEN

Other improvements

  • Fix bug: respect and keep valid caches 19e3fe9
    • as-is: Generate caches first run and use it second, but remove them so it has to regenerate in the third run
    • to-be: Always respect and keep valid caches
graphql-let - v0.11.3

Published by piglovesyou over 4 years ago

graphql-let - v0.11.2

Published by piglovesyou over 4 years ago

graphql-let - v0.11.1

Published by piglovesyou over 4 years ago

  • graphql-tag commands now removes old caches so the size of the cache directory does not keep growing anymore.
  • cacheDir option can specify the cache directory for those who want to have full control of the output files.
graphql-let - v0.11.0

Published by piglovesyou over 4 years ago

Now graphql-let uses tsconfig.json in your root directory, thanks to https://github.com/piglovesyou/graphql-let/pull/116 by @salzhrani ! If you want to use a specific config for graphql-let, TSConfigFile option in .graphql-let.yml will overwrite the config path.

Be careful: It's possible to break if you tsconfig.json doesn't fit graphql-let's TypeScript compilation. Please have your own if there's trouble.

Package Rankings
Top 2.22% on Npmjs.org
Top 6.67% on Proxy.golang.org
Badges
Extracted from project README
Node CI npm version downloads Babel Macro Stake to support us
Related Projects