javascript - 如何在没有 relay-babel-plugin 和 relay-compiler 的情况下获取 GraphhQLTaggedNode
问题描述
在中继中,用于将字符串转换为 GraphQLTaggedNode 的方法声明如下:
function graphql(strings: Array<string>): GraphQLTaggedNode {
invariant(
false,
'graphql: Unexpected invocation at runtime. Either the Babel transform ' +
'was not set up, or it failed to identify this call site. Make sure it ' +
'is being used verbatim as `graphql`. Note also that there cannot be ' +
'a space between graphql and the backtick that follows.',
);
}
Relay是这样设计的,强制开发者使用“babel-plugin-relay”和“replay-compiler”,“relay-compiler”将字符串转换为GraphQLTaggedNode并将节点保存到生成的文件中,用“babel-plugin-relay”替换通过引用该节点来调用“graphql()”。这在正常情况下效果很好。
现在,我正在开发一个可以让用户不使用“babel-plugin-relay”和“replay-compiler”的开源框架,我有自己的方式来处理查询、突变和片段,所以我需要在内部直接将字符串转换为 GraphQLTaggedNode,没有“babel-plugin-relay”和“replay-compiler”。
我该怎么做?理论上我可以使用graphql-js甚至ANTLR来开发自己的编译器,但是我不想做重复的工作。可以复用中继编译器已有的功能吗?
解决方案
推荐阅读
- asp.net - Azure Function 卡住,没有高 CPU
- python - 使用 keras 的具有 VGG16 预训练模型的 U-Net 模型 - 图形断开错误
- c# - Roslyn 分析器代码修复提供程序替换文档中的字符串
- javascript - 无法在 ios 设备中安装 ionic 应用程序
- c++ - 'chrono' 库的错误输出
- python - 以颜色作为第三维连接二维散点图中的点
- php - 重定向到同一页面时,表单验证错误未在 codeigniter 中显示
- neo4j - Neo.ClientError.Procedure.ProcedureNotFound
- html - CSS flexitem 的 paddingleft 属性在页面刷新时不起作用
- c# - 为单一平台创建缺少的自定义渲染器