• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

samsarahq/graphql-loader: A webpack loader for .graphql documents

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

samsarahq/graphql-loader

开源软件地址(OpenSource Url):

https://github.com/samsarahq/graphql-loader

开源编程语言(OpenSource Language):

TypeScript 98.5%

开源软件介绍(OpenSource Introduction):

GraphQL Loader for Webpack

npm Version Build Status

A webpack loader for .graphql query documents with first class support for schema validation and fragments definitions. graphql-loader works great with thunder, apollo-client, and anywhere you might want to provide a GraphQL query document in the frontend.

Installation

yarn add --dev webpack-graphql-loader # or npm install --save-dev webpack-graphql-loader

You will also need to install a copy of graphql, which is a peer dependency of this package.

yarn add --dev graphql # or npm install --save-dev graphql

Configuration

Add webpack-graphql-loader to your webpack configuration:

module.exports = {
  // ...
  module: {
    rules: [ // or "loaders" for webpack 1.x
      { test: /\.graphql?$/, loader: 'webpack-graphql-loader' }
    ]
  }
}

Specifying options

You can also pass options to the loader via webpack options:

module.exports = {
  // ...
  module: {
    rules: [ // or "loaders" for webpack 1.x
      {
        test: /\.graphql?$/,
        use: [
          {
            loader: 'webpack-graphql-loader',
            options: {
              // validate: true,
              // schema: "./path/to/schema.json",
              // removeUnusedFragments: true
              // etc. See "Loader Options" below
            }
          }
        ]
      }
    ]
  }
}

Loader Options

schema (string) (default="")

The location of your graphql introspection query schema JSON file. If used with the validate option, this will be used to validate imported queries and fragments.

validate (boolean) (default=false)

If true, the loader will validate the imported document against your specified schema file.

output ("string" | "document") (default="string")

Specifies whether or not the imported document should be a printed graphql string, or a graphql DocumentNode AST. The latter is useful for interop with graphql-tag.

minify (boolean) (default=false)

If true and the output option is string, the loader will strip comments and whitespace from the graphql document strings. This helps to reduce bundled code size.

removeUnusedFragments (boolean) (default=false)

If true, the loader will remove unused fragments from the imported document. This may be useful if a query is importing fragments from a file, but does not use all fragments in that file. Also see this issue.

Import statements in .graphql files

The loader supports importing .graphql files from other .graphql files using an #import statement. For example:

query.graphql:

#import "./fragments.graphql"

query {
  ...a
  ...b
}

fragments.graphql:

fragment a on A {}
fragment b on A {
  foo(bar: 1)
}

In the above example, fragments a and b will be made available within query.graphql. Note that all fragments in the imported file should be used in the top-level query, or the removeUnusedFragments should be specified.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap