rescript-relay 0.21.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -233,7 +233,7 @@ module RouteRenderer = {
233
233
  let (initialized, setInitialized) = React.useState(() => false)
234
234
  let router = use()
235
235
 
236
- let (startTransition, isPending) = ReactExperimental.unstable_useTransition()
236
+ let (isPending, startTransition) = ReactExperimental.useTransition()
237
237
 
238
238
  let (routeEntry, setRouteEntry) = React.useState(() => router.get())
239
239
 
@@ -306,10 +306,12 @@ module Link = {
306
306
  ~className=?,
307
307
  ~classNameDynamic=?,
308
308
  ~target as browserTarget=?,
309
+ ~tabIndex=?,
309
310
  ~mode=?,
310
311
  ~render=?,
311
312
  ~preloadOnHover=?,
312
313
  ~children,
314
+ ~onClick=?,
313
315
  (),
314
316
  ) => {
315
317
  let router = use()
@@ -350,12 +352,19 @@ module Link = {
350
352
  }}
351
353
  ?title
352
354
  ?id
355
+ ?tabIndex
353
356
  className={className->Belt.Option.getWithDefault("") ++
354
357
  switch classNameDynamic {
355
358
  | Some(f) => " " ++ f(url, to_->Url.make)
356
359
  | None => ""
357
360
  }}
358
- onClick=changeRoute
361
+ onClick={e => {
362
+ changeRoute(e)
363
+ switch onClick {
364
+ | None => ()
365
+ | Some(onClick) => onClick()
366
+ }
367
+ }}
359
368
  onMouseDown={_ => preload()}
360
369
  onTouchStart={_ => preload()}
361
370
  onMouseEnter={_ =>
@@ -56,6 +56,7 @@ module Link: {
56
56
  ~className: string=?,
57
57
  ~classNameDynamic: (RescriptReactRouter.url, RescriptReactRouter.url) => string=?,
58
58
  ~target: [#self | #blank]=?,
59
+ ~tabIndex: int=?,
59
60
  ~mode: [#push | #replace]=?,
60
61
  ~render: (
61
62
  ~preload: unit => unit,
@@ -65,6 +66,7 @@ module Link: {
65
66
  ) => React.element=?,
66
67
  ~preloadOnHover: bool=?,
67
68
  ~children: React.element,
69
+ ~onClick: unit => unit=?,
68
70
  unit,
69
71
  ) => React.element
70
72
  }
package/src/utils.js CHANGED
@@ -108,10 +108,7 @@ function traverse(
108
108
  ) {
109
109
  isUnion = true;
110
110
 
111
- var newPath = makeNewPath(currentPath, [
112
- key,
113
- v.__typename.toLowerCase(),
114
- ]);
111
+ var newPath = makeNewPath(currentPath, [key, v.__typename]);
115
112
 
116
113
  var unionRootHasFragment =
117
114
  (instructionMap[getPathName(newPath)] || {}).f === "";
@@ -186,10 +183,7 @@ function traverse(
186
183
  ) {
187
184
  isUnion = true;
188
185
 
189
- var newPath = makeNewPath(currentPath, [
190
- key,
191
- v.__typename.toLowerCase(),
192
- ]);
186
+ var newPath = makeNewPath(currentPath, [key, v.__typename]);
193
187
 
194
188
  var unionRootHasFragment =
195
189
  (instructionMap[getPathName(newPath)] || {}).f === "";
@@ -276,7 +270,7 @@ function traverse(
276
270
  */
277
271
  function traverser(
278
272
  root,
279
- _instructionMaps,
273
+ instructionMaps_,
280
274
  theConverters,
281
275
  nullableValue,
282
276
  rootObjectKey
@@ -285,7 +279,7 @@ function traverser(
285
279
  return nullableValue;
286
280
  }
287
281
 
288
- var instructionMaps = _instructionMaps || {};
282
+ var instructionMaps = instructionMaps_ || {};
289
283
  var instructionMap = instructionMaps[rootObjectKey || "__root"];
290
284
 
291
285
  // No instructions
@@ -311,9 +305,19 @@ function traverser(
311
305
  return nullableValue;
312
306
  }
313
307
 
308
+ var n = [];
309
+
310
+ // Since a root level union is treated as a "new root level", we'll need
311
+ // to do a separate check here of whether there's a fragment on the root
312
+ // we need to account for, or not.
313
+ if (unionRootConverter != null) {
314
+ n = [v.__typename];
315
+ fragmentsOnRoot = (instructionMap[v.__typename] || {}).f === "";
316
+ }
317
+
314
318
  var traversedObj = traverse(
315
319
  instructionMaps,
316
- [],
320
+ n,
317
321
  v,
318
322
  instructionMap,
319
323
  converters,
@@ -330,9 +334,18 @@ function traverser(
330
334
 
331
335
  var newObj = Object.assign({}, root);
332
336
 
337
+ var n = [];
338
+
339
+ // Same as in the union array check above - if there's a fragment in the new
340
+ // root created by the union, we need to account for that separately here.
341
+ if (unionRootConverter != null) {
342
+ n = [newObj.__typename];
343
+ fragmentsOnRoot = (instructionMap[newObj.__typename] || {}).f === "";
344
+ }
345
+
333
346
  var v = traverse(
334
347
  instructionMaps,
335
- [],
348
+ n,
336
349
  newObj,
337
350
  instructionMap,
338
351
  converters,
package/bin-darwin DELETED
Binary file
package/bin-linux DELETED
Binary file
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
- const path = require("path");
3
- const { spawn } = require("child_process");
4
-
5
- let relayConfig = require("relay-config").loadConfig();
6
-
7
- if (!relayConfig) {
8
- console.error(
9
- "Could not find relay.config.js. You must configure Relay through relay.config.js for RescriptRelay to work."
10
- );
11
-
12
- process.exit(1);
13
- }
14
-
15
- if (!relayConfig.artifactDirectory) {
16
- console.error(
17
- "RescriptRelay requires you to define 'artifactDirectory' (for outputing generated files in a single directory) in your relay.config.js. Please define it and re-run this command."
18
- );
19
- process.exit(1);
20
- }
21
-
22
- function runRelayCompiler(args) {
23
- const proc = spawn("relay-compiler", args, {
24
- stdio: "inherit",
25
- })
26
- // Propagate the relay compiler's exit code.
27
- .on("close", process.exit.bind(process));
28
-
29
- process.on("SIGINT", () => {
30
- proc.kill("SIGINT");
31
- });
32
- }
33
-
34
- function findArg(name) {
35
- return relayConfig[name];
36
- }
37
-
38
- async function runCompiler() {
39
- const schemaPath = findArg("schema");
40
-
41
- if (schemaPath) {
42
- runRelayCompiler(
43
- [
44
- "--language",
45
- path.resolve(__dirname + "/../language-plugin/dist/index.js"),
46
- process.argv.find((a) => a === "--watch"),
47
- ].filter(Boolean)
48
- );
49
- } else {
50
- runRelayCompiler(["--help"]);
51
- }
52
- }
53
-
54
- runCompiler();
@@ -1 +0,0 @@
1
- module.exports=(()=>{"use strict";var e={338:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.find=void 0,t.find=function(e,t){return function(e,t){if(!e.includes("%relay"))return[];const n=e.match(/(?<=\[%relay)([\s\S]*?)(?=];)/g);if(n)return n.map((e=>({template:e.replace(/({\||\|})/g,""),keyName:null,sourceLocationOffset:{line:1,column:1}})));const r=e.match(/(?<=\%relay\([\s]*`)[\s\S.]+?(?=`[\s]*\))/g);return r?r.map((e=>({template:e,keyName:null,sourceLocationOffset:{line:1,column:1}}))):[]}(e)}},189:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.generateFromFlowTypes=void 0;const r=n(129),o=n(622);t.generateFromFlowTypes=e=>{var t;const n=r.spawnSync(o.resolve(o.join(__dirname,"../RescriptRelayBin.exe")),["generate-from-flow"],{cwd:__dirname,stdio:"pipe",encoding:"utf-8",input:JSON.stringify(e)});if(0!==n.status)throw null!==(t=n.error)&&void 0!==t?t:new Error("Error generating types");return n.output.filter(Boolean).join("")}},571:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transforms=t.generate=void 0;const r=n(791),o=n(224),a=n(148),i=n(354),s=n(189),l=n(602);function c(e){const t=Object.assign({Int:"int",Float:"float"},e);return Object.keys(t).forEach((e=>{t[e]=l.maskDots(t[e])})),t}t.generate=function(e,t,n){var a;let i=r.generate(e,t,Object.assign(Object.assign({},n),{customScalars:c(n.customScalars)}));const l=o.makeOperationDescriptor(t),d=o.extractOperationInfo(t);return s.generateFromFlowTypes({content:i,operation_type:["Query","Mutation","Subscription"].includes(l.tag)?{operation:l.tag,operation_value:l.value}:{operation:"Fragment",fragment_value:l.value},print_config:{variables_holding_connection_ids:null!==(a=d.variablesHoldingConnectionIds)&&void 0!==a?a:null,connection:d.connection?{at_object_path:d.connection.atObjectPath,field_name:d.connection.fieldName,key:d.connection.key}:null}})},t.transforms=[i.transform,a.transform,...r.transforms]},942:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(366),o=n(622);e.exports=({moduleName:e,documentType:t,concreteText:n,typeText:a,definition:i})=>{let s=null;"Source"===i.loc.kind&&(s=o.basename(i.loc.source.name));const l="ConcreteRequest"===t&&e.toLowerCase().endsWith("query_graphql")?"include RescriptRelay.MakeLoadQuery({\n type variables = Types.variables\n type loadedQueryRef = queryRef\n type response = Types.response\n type node = relayOperationNode\n let query = node\n let convertVariables = Internal.convertVariables\n });":"",{processedText:c,referencedNodes:d}=r.processConcreteText(n),u=`%raw(json\` ${c} \`)`;return[s?`/* @sourceLoc ${s} */`:null,a||"",...d.length>0?[`%%private(let makeNode = (${d.map((({identifier:e})=>e)).join(", ")}): operationType => {`,...d.map((({identifier:e})=>` ignore(${e})`)),` ${u}`,"})",`let node: operationType = makeNode(${d.map((({moduleName:e})=>`${e}_graphql.node`)).join(", ")})`]:[`let node: operationType = ${u}`],"",l,""].filter((e=>null!=e)).join("\n")}},602:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.unmaskDots=t.maskDots=void 0,t.maskDots=e=>e.split(".").join("__oo__"),t.unmaskDots=e=>e.split("__oo__").join(".")},607:(e,t,n)=>{const r=n(571),o=n(942),{find:a}=n(338),i=n(622),s=n(747);function l(e){return t=>{const n=i.join(e,t.relPath);let r="";try{r=s.readFileSync(n,"utf8")}catch(e){return console.warn(`RelaySourceModuleParser: Unable to read the file "${n}". Looks like it was removed.`),!1}return r.indexOf("%relay")>=0}}e.exports=()=>({inputExtensions:["re","res"],outputExtension:"res",schemaExtensions:[],typeGenerator:r,formatModule:o,findGraphQLTags:a,isGeneratedFile:e=>e.endsWith("_graphql.res")||e.endsWith(".js")||e.endsWith(".mjs"),keepExtraFile:e=>e.endsWith(".js")||e.endsWith(".mjs"),getFileFilter:l,getModuleName:e=>`${e}_graphql`})},224:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.makeOperationDescriptor=t.extractOperationInfo=void 0;const r=n(195);function o(e,t,n){if("Root"===e.kind&&["mutation","subscription"].includes(e.operation)){const e=t.directives.filter((e=>["appendNode","prependNode","appendEdge","prependEdge","deleteEdge"].includes(e.name)));e.length>0&&e.forEach((e=>{const t=e.args.find((e=>"connections"===e.name)),r=null==t?void 0:t.value;r&&"Variable"===r.kind&&(n.variablesHoldingConnectionIds?n.variablesHoldingConnectionIds.push(r.variableName):n.variablesHoldingConnectionIds=[r.variableName])}))}}t.extractOperationInfo=function(e){let t={};const n="Fragment"===e.kind?"fragment":"response";return n?(function e(n,a){r.IRVisitor.visit(a,{ScalarField(e){o(a,e,t)},LinkedField(e){const r=e.directives.find((e=>"connection"===e.name));if(r&&!t.connection){let o=null;r.args.forEach((e=>{"key"===e.name&&"Literal"===e.value.kind&&(o=e.value.value)})),o&&(t=Object.assign(Object.assign({},t),{connection:{key:o,atObjectPath:[...n],fieldName:e.alias}}))}o(a,e,t),n.push(e.alias)},InlineFragment(t){t.typeCondition.name&&t.selections.forEach((r=>{e([...n,t.typeCondition.name.toLowerCase()],r)}))}})}([n],e),t):t},t.makeOperationDescriptor=function(e){if("Root"===e.kind)switch(e.operation){case"mutation":return{tag:"Mutation",value:e.name};case"query":return{tag:"Query",value:e.name};case"subscription":return{tag:"Subscription",value:e.name}}else if("Fragment"==e.kind)return{tag:"Fragment",value:[e.name,Boolean(e.metadata&&e.metadata.plural)]};throw new Error("Could not map root node. This should not happen.")}},148:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transform=void 0;const r=n(724),{createUserError:o}=n(182),a=["and","as","asr","assert","begin","class","constraint","do","while","for","done","while","for","downto","else","end","exception","external","false","for","fun","function","functor","if","in","include","inherit","initializer","land","lazy","let","lor","lsl","lsr","lxor","match","method","mod","module","open","mutable","new","nonrec","object","of","open","open!","or","private","rec","let","module","sig","struct","then","to","true","try","type","val","virtual","val","method","class","when","while","with","switch"];let i=["fragment","t_fragment","subscription","mutation","response","variables","refetchVariables","t","fragmentRef","fragmentRefs","fragmentRefSelector","operationType"];function s(e){if(e.alias){let{disallowed:t,message:n}=function(e){let t=e[0];return/[A-Z]/.test(t)?{disallowed:!0,message:`Field names may not start with an uppercase letter. Please alias the '${e}' field to something starting with a lowercase letter.`}:a.includes(e)?{disallowed:!0,message:`'${e}' is a reserved keyword in ReasonML and therefore cannot be used as a field name. Please alias your field to something else.`}:i.includes(e)?{disallowed:!0,message:`'${e}' is a reserved keyword in RescriptRelay and therefore cannot be used as a field name. Please alias your field to something else.`}:{disallowed:!1,message:""}}(e.alias);if(t)throw o("Found an invalid field name: "+n,[e.loc])}e.selections&&e.selections.forEach(s)}function l(e){return s(e),e}t.transform=function(e){return r.transform(e,{ScalarField:l,LinkedField:l})}},354:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transform=void 0;const r=n(724),{createUserError:o}=n(182),{hasUnaliasedSelection:a}=n(124);function i(e){const t=this.getContext().getSchema();let n=this.traverse(e);if(t.isAbstractType(t.getRawType(n.type))&&!a(n,"__typename"))throw o('Unions and interfaces must have the field __typename explicitly selected. Please add __typename to the fields selected by "'+e.alias+'" in your operation.',[e.loc]);return n}t.transform=function(e){return r.transform(e,{LinkedField:i})}},366:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.processConcreteText=void 0,t.processConcreteText=function(e){let t=/(require\('.\/)([A-Za-z_.0-9/]+)(.graphql.\w*'\))/gm,n=e;const r=[];let o;for(;null!==(o=t.exec(e));){let[e,t,a]=o;const i=`node_${a}`;r.push({moduleName:a,identifier:i}),n=n.replace(e,`node_${a}`)}return{processedText:n,referencedNodes:r}}},129:e=>{e.exports=require("child_process")},747:e=>{e.exports=require("fs")},622:e=>{e.exports=require("path")},195:e=>{e.exports=require("relay-compiler")},182:e=>{e.exports=require("relay-compiler/lib/core/CompilerError")},724:e=>{e.exports=require("relay-compiler/lib/core/IRTransformer")},791:e=>{e.exports=require("relay-compiler/lib/language/javascript/RelayFlowGenerator")},124:e=>{e.exports=require("relay-compiler/lib/transforms/TransformUtils")}},t={};return function n(r){if(t[r])return t[r].exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}(607)})();