Babel Relay Plugin #Facebook Relay文档翻译#
来源:互联网 发布:淘宝找回密码系统繁忙 编辑:程序博客网 时间:2024/05/18 02:37
原文地址
上一篇 Network Layer
Relay文档翻译目录
Relay uses a babel plugin to convert from Relay.QL
string templates to
JavaScript code that describes each query and includes data from the GraphQL
schema.
Relay使用**babel**plugin来将Relay.QL
字符串模板转换成描述查询的JS代码,还能通过GraphQL schema来引入数据。
While you type queries as follows:
当你用下面方式写query的时候:
Relay.QL` fragment on User { # ... }`
This gets converted into an immediately-invoked function:
它将转换成一个立刻执行函数
(function() { // Return a description of the query ...})();
Usage
The easiest way to get started for now is with the Relay Starter Kit - this includes an example schema file and configures the babel-relay-plugin
npm module to transpile queries.
最简单的方式开始使用Relay是通过Relay Starter Kit,它包含了schema的样例,配置好了babel-relay-plugin
Advanced Usage
If you’re not using the starter kit, you’ll have to configure babel
to use the babel-relay-plugin
. The steps are as follows:
如果你不用start kit,你需要配置babel
来使用babel-relay-plugin
,步骤如下:
// `babel-relay-plugin` returns a function for creating plugin instancesvar getBabelRelayPlugin = require('babel-relay-plugin');// load previously saved schema data (see "Schema JSON" below)var schemaData = require('schema.json');// create a plugin instancevar plugin = getBabelRelayPlugin(schemaData);// compile code with babel using the pluginreturn babel.transform(source, { plugins: [plugin],});
Schema JSON
The plugin needs to understand your schema - schemaData
in the above snippet. There are two ways to get this information, depending on the GraphQL implementation.
该插件需要理解你的schema——上面的schemaData
片段。有两种方法获得该信息,取决于GraphQL的实现。
Using graphql
An example of how to load a schema.js
file, run the introspection query to get schema information, and save it to a JSON file can be found in the starter kit.
加载schema.js
的例子,在 starter kit中运行自检查询获得schema信息,并且输出到一个JSON文件中。
Using Other GraphQL Implementations
If you’re using a different GraphQL server implementation, we recommend adapting the above example to load the schema from your GraphQL server (e.g. via an HTTP request) and then save the result as JSON.
如果你使用的是不同的GraphQL实现,我们建议您适配上面的例子,通过您的GraphQL server加载schema并输出JSON。
Additional Options
By default, babel-relay-plugin
catches GraphQL validation errors and logs them without exiting. The compiled code will also throw the same errors at runtime, making it obvious that something went wrong whether you’re looking at your terminal or browser console.
默认情况,babel-relay-plugin
捕捉GraphQL的校验错误并且在不退出的情况下记下错误日志。编译的代码运行时还是会继续抛出该错误,让你可以在终端上容易的看到错误。
When compiling code for production deployment, the plugin can be configured to immediately throw upon encountering a validation problem:
当编译在生产环境部署时,该插件可以被配置为遇到校验错误立刻中止。
var plugin = getBabelRelayPlugin(schemaData, { abortOnError: true,});
- Babel Relay Plugin #Facebook Relay文档翻译#
- GraphQL Relay Specification #Facebook Relay文档翻译#
- Thinking In Relay #Facebook Relay文档翻译#
- Tutorial #Facebook Relay文档翻译#
- Containers #Facebook Relay文档翻译#
- Routes #Facebook Relay文档翻译#
- Mutations #Facebook Relay文档翻译#
- Connection #Facebook Relay文档翻译#
- Mutations #Facebook Relay文档翻译#
- Relay文档翻译目录 #Facebook Relay文档翻译#
- Getting Start #Facebook Relay文档翻译#
- Root Container #Facebook Relay文档翻译#
- Ready State #Facebook Relay文档翻译#
- Network Layer #Facebook Relay文档翻译#
- Object Identification #Facebook Relay文档翻译#
- Thinking in GraphQL #Facebook Relay文档翻译#
- relay
- [SQL Relay文档] SQL Relay中PHP API参考手册 (英文)
- SQL SERVER 2008 中三种分页方法与比较
- ARM平台上蓝牙协议栈Bluez的移植使用和配置
- 【Java】hashMap和hashTable的区别
- ARM术语
- 大数据学习篇:hadoop深入浅出系列之HDFS(七) ——小文件解决方案
- Babel Relay Plugin #Facebook Relay文档翻译#
- Linux下core文件的生成和使用
- 运行Oracle SQL Developer出错
- 辨析String、StringBuffer和StringBuilder
- Implicit declaration of function 'NSFileTypeForHFSTypeCode' is invalid in C99
- POJ2018 最大平均值问题
- exit(0),ExitProcess和ThrminateProcess的区别的联系
- linux下mysql yum 安装 新建用户 设置权限
- Java NIO 系列教程