A webpack loader / babel-plugin / babel-plugin-macros / CLI / generated file manager of GraphQL code generator.
APACHE-2.0 License
This patch version includes JEST v26 & v27 support. So nice, @cbmd!
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()
.
Published by piglovesyou over 3 years ago
Fixes bug #506
Published by piglovesyou over 3 years ago
Fixed bug #516
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.
Published by piglovesyou over 3 years ago
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.
Please install @graphql-codegen/import-types-preset
as an additional peer dependency.
yarn add -D @graphql-codegen/import-types-preset
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.
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@'
Resolver Types also go in graphql-let/__generated__/__types__
.
- import { Resolvers } from "./${config.schemaEntrypoint}";
+ import { Resolvers } from "graphql-let/__generated__/__types__";
Published by piglovesyou over 3 years ago
Supports silent
option to suppress all the standard output coming from graphql-let.
Published by piglovesyou over 3 years ago
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 entrypointsgql()
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')
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
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.
Published by piglovesyou almost 4 years ago
https://github.com/piglovesyou/graphql-let/commit/7a14dfe5845079ea845e0254f9dd2251f819f71f by @hasparus 🎉
https://github.com/piglovesyou/graphql-let/commit/e59286a5ed649212f39df2d508325f39594bfe5e by @andrenanninga 🎉
Published by piglovesyou about 4 years ago
.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
Published by piglovesyou about 4 years ago
# 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
}
}
schema: **/*.graphqls
💫Now specifying multiple pointers in schema
is available.
schema:
- "src/**/*.graphqls"
- "lib/**/*.graphqls"
schemaEntrypoint
if you use Resolver TypesSince 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.
withHooks: true
option if you use @graphql-codegen/react-apollo@2
and React Hooks functionsYou'll need withHooks: true
option in .graphql-let.yml config, if:
@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
withHOC: false; withHooks: true
, since I wanted it😣Users cloned source from vercel/next.js/examples/with-typescript-graphql recently should fall into this category.
Published by piglovesyou about 4 years ago
Please refer to the document to know how to set up.
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.
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.ts
s 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.
Published by piglovesyou over 4 years ago
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
Published by piglovesyou over 4 years ago
Published by piglovesyou over 4 years ago
Published by piglovesyou over 4 years ago
cacheDir
option can specify the cache directory for those who want to have full control of the output files.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.