I am writing a web application in TypeScript. The app uses React and Relay from Facebook. My TypeScript source code is compiled into ES6 code using the TypeScript TSC compiler. Then, the ES6 code is passed to the ES5 code using Babel. For Relay to work in a browser, the Babel plugin must convert Relay GraphQL queries: https://facebook.imtqy.com/relay/docs/guides-babel-plugin.html . The problem is that since TSC first forwards these requests, the Babel Relay plugin no longer recognizes them, so they are not passed to something that the browser understands, so the browser throws an error:
Unopened Invariant Violation: RelayQL: An unexpected call at runtime. Either the Babel transform has not been configured, or it does not identify this call site. Make sure it is used verbatim Relay.QL.
My TypeScript source code:
const SiteQuery = {
store: () => Relay.QL`query { site }`
};
... this compiles TSC into something like this:
var SiteQuery = {\r\n store: function () { return (_a = [\"query { site }\"], _a.raw = [\"query { site }\"], Relay.QL(_a)); var _a; }\r\n};
... instead of something like this (because the Babel Relay plugin is not doing its job properly):
var SiteQuery = {\n store: function store() {\n return (function () {\n return {\n fieldName: 'site',\n kind: 'Query',\n metadata: {},\n name: 'Router',\n type: 'Site'\n };
This is due to the fact that the Babel Relay plugin does not recognize the converted version and, as a result, does not translate the request into something that the browser understands.
How to do it?
source
share