houdini 0.17.7 → 0.17.9

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.
Files changed (48) hide show
  1. package/.turbo/turbo-compile.log +2 -2
  2. package/.turbo/turbo-typedefs.log +2 -2
  3. package/CHANGELOG.md +9 -1
  4. package/build/cmd-cjs/index.js +124 -38
  5. package/build/cmd-esm/index.js +124 -38
  6. package/build/codegen-cjs/index.js +112 -36
  7. package/build/codegen-esm/index.js +112 -36
  8. package/build/lib/config.d.ts +3 -0
  9. package/build/lib-cjs/index.js +31 -12
  10. package/build/lib-esm/index.js +31 -12
  11. package/build/runtime/cache/cache.d.ts +1 -1
  12. package/build/runtime/cache/lists.d.ts +1 -1
  13. package/build/runtime/lib/config.d.ts +10 -2
  14. package/build/runtime/lib/types.d.ts +1 -0
  15. package/build/runtime-cjs/cache/cache.d.ts +1 -1
  16. package/build/runtime-cjs/cache/cache.js +6 -6
  17. package/build/runtime-cjs/cache/lists.d.ts +1 -1
  18. package/build/runtime-cjs/cache/lists.js +15 -6
  19. package/build/runtime-cjs/cache/tests/list.test.js +160 -70
  20. package/build/runtime-cjs/lib/config.d.ts +10 -2
  21. package/build/runtime-cjs/lib/types.d.ts +1 -0
  22. package/build/runtime-esm/cache/cache.d.ts +1 -1
  23. package/build/runtime-esm/cache/cache.js +6 -6
  24. package/build/runtime-esm/cache/lists.d.ts +1 -1
  25. package/build/runtime-esm/cache/lists.js +15 -6
  26. package/build/runtime-esm/cache/tests/list.test.js +160 -70
  27. package/build/runtime-esm/lib/config.d.ts +10 -2
  28. package/build/runtime-esm/lib/types.d.ts +1 -0
  29. package/build/test-cjs/index.js +122 -36
  30. package/build/test-esm/index.js +122 -36
  31. package/build/vite-cjs/index.js +122 -36
  32. package/build/vite-esm/index.js +122 -36
  33. package/package.json +1 -1
  34. package/src/codegen/generators/artifacts/artifacts.test.ts +268 -0
  35. package/src/codegen/generators/artifacts/operations.ts +31 -13
  36. package/src/codegen/generators/definitions/schema.test.ts +9 -0
  37. package/src/codegen/transforms/list.ts +0 -1
  38. package/src/codegen/transforms/paginate.test.ts +47 -0
  39. package/src/codegen/transforms/paginate.ts +28 -8
  40. package/src/codegen/transforms/schema.ts +5 -0
  41. package/src/codegen/validators/typeCheck.test.ts +56 -0
  42. package/src/codegen/validators/typeCheck.ts +66 -11
  43. package/src/lib/config.ts +11 -0
  44. package/src/runtime/cache/cache.ts +9 -6
  45. package/src/runtime/cache/lists.ts +24 -10
  46. package/src/runtime/cache/tests/list.test.ts +173 -66
  47. package/src/runtime/lib/config.ts +12 -2
  48. package/src/runtime/lib/types.ts +1 -0
@@ -63978,22 +63978,31 @@ var ListManager = class {
63978
63978
  }
63979
63979
  lists = /* @__PURE__ */ new Map();
63980
63980
  listsByField = /* @__PURE__ */ new Map();
63981
- get(listName, id) {
63981
+ get(listName, id, allLists) {
63982
63982
  const matches = this.lists.get(listName);
63983
63983
  if (!matches || matches.size === 0) {
63984
63984
  return null;
63985
63985
  }
63986
+ if (allLists) {
63987
+ return new ListCollection(
63988
+ Array.from(matches, ([key, value]) => [...value.lists]).flat()
63989
+ );
63990
+ }
63986
63991
  const head = [...matches.values()][0];
63992
+ const { recordType } = head.lists[0];
63993
+ const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
63987
63994
  if (matches?.size === 1) {
63988
- return head;
63995
+ if (!id) {
63996
+ return head;
63997
+ }
63998
+ return parentID === Array.from(matches.keys())[0] ? head : null;
63989
63999
  }
63990
64000
  if (!id) {
63991
- throw new Error(
63992
- `Found multiple instances of "${listName}". Please provide a parentID that corresponds to the object containing the field marked with @list or @paginate.`
64001
+ console.error(
64002
+ `Found multiple instances of "${listName}". Please provide one of @parentID or @allLists directives to help identify which list you want modify. For more information, visit this guide: https://www.houdinigraphql.com/api/graphql#parentidvalue-string `
63993
64003
  );
64004
+ return null;
63994
64005
  }
63995
- const { recordType } = head.lists[0];
63996
- const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
63997
64006
  return this.lists.get(listName)?.get(parentID);
63998
64007
  }
63999
64008
  remove(listName, id) {
@@ -64939,8 +64948,8 @@ var Cache2 = class {
64939
64948
  variables
64940
64949
  );
64941
64950
  }
64942
- list(name2, parentID) {
64943
- const handler = this._internal_unstable.lists.get(name2, parentID);
64951
+ list(name2, parentID, allLists) {
64952
+ const handler = this._internal_unstable.lists.get(name2, parentID, allLists);
64944
64953
  if (!handler) {
64945
64954
  throw new Error(
64946
64955
  `Cannot find list with name: ${name2}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
@@ -65207,15 +65216,15 @@ var CacheInternal = class {
65207
65216
  parentID = id;
65208
65217
  }
65209
65218
  }
65210
- if (operation.list && !this.lists.get(operation.list, parentID)) {
65219
+ if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
65211
65220
  continue;
65212
65221
  }
65213
65222
  const targets = Array.isArray(value) ? value : [value];
65214
65223
  for (const target of targets) {
65215
65224
  if (operation.action === "insert" && target instanceof Object && fields && operation.list) {
65216
- this.cache.list(operation.list, parentID).when(operation.when).addToList(fields, target, variables, operation.position || "last");
65225
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(fields, target, variables, operation.position || "last");
65217
65226
  } else if (operation.action === "remove" && target instanceof Object && fields && operation.list) {
65218
- this.cache.list(operation.list, parentID).when(operation.when).remove(target, variables);
65227
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
65219
65228
  } else if (operation.action === "delete" && operation.type) {
65220
65229
  if (typeof target !== "string") {
65221
65230
  throw new Error("Cannot delete a record with a non-string ID");
@@ -65226,7 +65235,7 @@ var CacheInternal = class {
65226
65235
  }
65227
65236
  this.cache.delete(targetID);
65228
65237
  } else if (operation.action === "toggle" && target instanceof Object && fields && operation.list) {
65229
- this.cache.list(operation.list, parentID).when(operation.when).toggleElement(fields, target, variables, operation.position || "last");
65238
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(fields, target, variables, operation.position || "last");
65230
65239
  }
65231
65240
  }
65232
65241
  }
@@ -67021,6 +67030,8 @@ var Config = class {
67021
67030
  cacheBufferSize;
67022
67031
  defaultCachePolicy;
67023
67032
  defaultPartial;
67033
+ internalListPosition;
67034
+ defaultListTarget = null;
67024
67035
  definitionsFolder;
67025
67036
  newSchema = "";
67026
67037
  newDocuments = "";
@@ -67052,6 +67063,8 @@ var Config = class {
67052
67063
  definitionsPath,
67053
67064
  defaultCachePolicy = "CacheOrNetwork" /* CacheOrNetwork */,
67054
67065
  defaultPartial = false,
67066
+ defaultListPosition = "append",
67067
+ defaultListTarget = null,
67055
67068
  defaultKeys,
67056
67069
  types: types15 = {},
67057
67070
  logLevel,
@@ -67085,6 +67098,8 @@ var Config = class {
67085
67098
  this.cacheBufferSize = cacheBufferSize;
67086
67099
  this.defaultCachePolicy = defaultCachePolicy;
67087
67100
  this.defaultPartial = defaultPartial;
67101
+ this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
67102
+ this.defaultListTarget == defaultListTarget;
67088
67103
  this.definitionsFolder = definitionsPath;
67089
67104
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
67090
67105
  this.disableMasking = disableMasking;
@@ -67299,6 +67314,9 @@ var Config = class {
67299
67314
  get listDirectiveParentIDArg() {
67300
67315
  return "parentID";
67301
67316
  }
67317
+ get listAllListsDirective() {
67318
+ return "allLists";
67319
+ }
67302
67320
  get listNameArg() {
67303
67321
  return "name";
67304
67322
  }
@@ -67380,6 +67398,7 @@ var Config = class {
67380
67398
  this.listPrependDirective,
67381
67399
  this.listAppendDirective,
67382
67400
  this.listDirectiveParentIDArg,
67401
+ this.listAllListsDirective,
67383
67402
  this.whenDirective,
67384
67403
  this.whenNotDirective,
67385
67404
  this.argumentsDirective,
@@ -68381,7 +68400,8 @@ function operationObject({
68381
68400
  }) {
68382
68401
  let parentID;
68383
68402
  let parentKind = "String";
68384
- let position = "last";
68403
+ let position = config3.internalListPosition;
68404
+ let allLists = config3.defaultListTarget ?? void 0;
68385
68405
  let operationWhen;
68386
68406
  const internalDirectives = selection2.directives?.filter(
68387
68407
  (directive) => config3.isInternalDirective(directive)
@@ -68393,15 +68413,21 @@ function operationObject({
68393
68413
  const append = internalDirectives.find(
68394
68414
  ({ name: name2 }) => name2.value === config3.listAppendDirective
68395
68415
  );
68396
- const when = internalDirectives.find(({ name: name2 }) => name2.value === "when");
68397
- const when_not = internalDirectives.find(({ name: name2 }) => name2.value === "when_not");
68416
+ if (append) {
68417
+ position = "last";
68418
+ }
68419
+ if (prepend) {
68420
+ position = "first";
68421
+ }
68422
+ const allListsDirective = internalDirectives.find(
68423
+ ({ name: name2 }) => name2.value === config3.listAllListsDirective
68424
+ );
68398
68425
  let parent = internalDirectives.find(
68399
68426
  ({ name: name2 }) => name2.value === config3.listParentDirective
68400
68427
  );
68401
- if (append && prepend) {
68402
- throw new HoudiniError({ filepath, message: "you have both applied" });
68403
- }
68404
- position = prepend ? "first" : "last";
68428
+ allLists = allListsDirective ? "all" : void 0;
68429
+ const when = internalDirectives.find(({ name: name2 }) => name2.value === "when");
68430
+ const when_not = internalDirectives.find(({ name: name2 }) => name2.value === "when_not");
68405
68431
  let parentIDArg = parent?.arguments?.find((argument) => argument.name.value === "value");
68406
68432
  if (!parentIDArg) {
68407
68433
  parentIDArg = (append || prepend)?.arguments?.find(
@@ -68463,7 +68489,10 @@ function operationObject({
68463
68489
  operation.type = type;
68464
68490
  }
68465
68491
  if (operationKind === "insert" || operationKind === "toggle") {
68466
- operation.position = position || "last";
68492
+ operation.position = position;
68493
+ }
68494
+ if (operationKind === "insert" && allLists) {
68495
+ operation.target = "all";
68467
68496
  }
68468
68497
  if (parentID) {
68469
68498
  operation.parentID = {
@@ -68587,12 +68616,15 @@ async function paginate(config3, documents) {
68587
68616
  {}
68588
68617
  ) || {};
68589
68618
  let newVariables = Object.fromEntries(
68590
- Object.entries(flags).filter(([, spec]) => spec.enabled).map(([fieldName, spec]) => [
68619
+ Object.entries(flags).filter(
68620
+ ([, spec]) => spec.enabled && spec.variableName === void 0
68621
+ ).map(([fieldName, spec]) => [
68591
68622
  fieldName,
68592
68623
  staticVariableDefinition(
68593
68624
  fieldName,
68594
68625
  spec.type,
68595
- spec.defaultValue
68626
+ spec.defaultValue,
68627
+ spec.variableName
68596
68628
  )
68597
68629
  ])
68598
68630
  );
@@ -68844,8 +68876,11 @@ function replaceArgumentsWithVariables(args, flags) {
68844
68876
  const oldValue = arg.value.value;
68845
68877
  flags[arg.name.value].defaultValue = spec.type === "Int" ? parseInt(oldValue) : oldValue;
68846
68878
  }
68879
+ if (arg.value.kind === "Variable") {
68880
+ flags[arg.name.value].variableName = arg.value.name.value;
68881
+ }
68847
68882
  seenArgs[arg.name.value] = true;
68848
- return variableAsArgument(arg.name.value);
68883
+ return variableAsArgument(arg.name.value, flags[arg.name.value].variableName);
68849
68884
  });
68850
68885
  for (const name2 of Object.keys(flags)) {
68851
68886
  const spec = flags[name2];
@@ -68862,7 +68897,7 @@ function replaceArgumentsWithVariables(args, flags) {
68862
68897
  }
68863
68898
  return newArgs;
68864
68899
  }
68865
- function variableAsArgument(name2) {
68900
+ function variableAsArgument(name2, variable) {
68866
68901
  return {
68867
68902
  kind: graphql9.Kind.ARGUMENT,
68868
68903
  name: {
@@ -68873,12 +68908,12 @@ function variableAsArgument(name2) {
68873
68908
  kind: graphql9.Kind.VARIABLE,
68874
68909
  name: {
68875
68910
  kind: graphql9.Kind.NAME,
68876
- value: name2
68911
+ value: variable ?? name2
68877
68912
  }
68878
68913
  }
68879
68914
  };
68880
68915
  }
68881
- function staticVariableDefinition(name2, type, defaultValue) {
68916
+ function staticVariableDefinition(name2, type, defaultValue, variableName) {
68882
68917
  return {
68883
68918
  kind: graphql9.Kind.VARIABLE_DEFINITION,
68884
68919
  type: {
@@ -68892,7 +68927,7 @@ function staticVariableDefinition(name2, type, defaultValue) {
68892
68927
  kind: graphql9.Kind.VARIABLE,
68893
68928
  name: {
68894
68929
  kind: graphql9.Kind.NAME,
68895
- value: name2
68930
+ value: variableName ?? name2
68896
68931
  }
68897
68932
  },
68898
68933
  defaultValue: !defaultValue ? void 0 : {
@@ -70701,6 +70736,11 @@ directive @${config3.listPrependDirective}(
70701
70736
  """
70702
70737
  directive @${config3.listAppendDirective}(${config3.listDirectiveParentIDArg}: ID) on FRAGMENT_SPREAD
70703
70738
 
70739
+ """
70740
+ @${config3.listAllListsDirective} is used to tell the runtime to add the result to all list
70741
+ """
70742
+ directive @${config3.listAllListsDirective} on FRAGMENT_SPREAD
70743
+
70704
70744
  """
70705
70745
  @${config3.listParentDirective} is used to provide a parentID without specifying position or in situations
70706
70746
  where it doesn't make sense (eg when deleting a node.)
@@ -71280,6 +71320,7 @@ async function typeCheck(config3, docs) {
71280
71320
  listTypes,
71281
71321
  fragments
71282
71322
  }),
71323
+ checkMutationOperation(config3),
71283
71324
  nodeDirectives(config3, [config3.paginateDirective]),
71284
71325
  knownArguments(config3),
71285
71326
  validateFragmentArguments(config3, filepath, fragments),
@@ -71338,24 +71379,33 @@ var validateLists = ({
71338
71379
  if (directive) {
71339
71380
  return;
71340
71381
  }
71382
+ let parentIdFound = false;
71341
71383
  directive = node.directives?.find(({ name: name2 }) => [
71342
71384
  [config3.listPrependDirective, config3.listAppendDirective].includes(name2.value)
71343
71385
  ]);
71344
- if (!directive) {
71345
- ctx.reportError(
71346
- new graphql25.GraphQLError("parentID is required for this list fragment")
71386
+ if (directive) {
71387
+ let parentArg = directive.arguments?.find(
71388
+ (arg) => arg.name.value === config3.listDirectiveParentIDArg
71347
71389
  );
71390
+ if (parentArg) {
71391
+ parentIdFound = true;
71392
+ }
71393
+ }
71394
+ if (parentIdFound) {
71348
71395
  return;
71349
71396
  }
71350
- let parentArg = directive.arguments?.find(
71351
- (arg) => arg.name.value === config3.listDirectiveParentIDArg
71397
+ const allLists = node.directives?.find(
71398
+ ({ name: name2 }) => config3.listAllListsDirective === name2.value
71352
71399
  );
71353
- if (!parentArg) {
71354
- ctx.reportError(
71355
- new graphql25.GraphQLError("parentID is required for this list fragment")
71356
- );
71400
+ if (allLists || config3.defaultListTarget === "all") {
71357
71401
  return;
71358
71402
  }
71403
+ ctx.reportError(
71404
+ new graphql25.GraphQLError(
71405
+ `For this list fragment, you need to add or @${config3.listParentDirective} or @${config3.listAllListsDirective} directive to specify the behavior`
71406
+ )
71407
+ );
71408
+ return;
71359
71409
  },
71360
71410
  Directive(node) {
71361
71411
  const directiveName = node.name.value;
@@ -71698,6 +71748,42 @@ function nodeDirectives(config3, directives) {
71698
71748
  };
71699
71749
  };
71700
71750
  }
71751
+ function checkMutationOperation(config3) {
71752
+ return function(ctx) {
71753
+ return {
71754
+ FragmentSpread(node, _, __, ___, ancestors) {
71755
+ const append = node.directives?.find(
71756
+ (c) => c.name.value === config3.listAppendDirective
71757
+ );
71758
+ const prepend = node.directives?.find(
71759
+ (c) => c.name.value === config3.listPrependDirective
71760
+ );
71761
+ if (append && prepend) {
71762
+ ctx.reportError(
71763
+ new graphql25.GraphQLError(
71764
+ `You can't apply both @${config3.listPrependDirective} and @${config3.listAppendDirective} at the same time`
71765
+ )
71766
+ );
71767
+ return;
71768
+ }
71769
+ const parentId = node.directives?.find(
71770
+ (c) => c.name.value === config3.listParentDirective
71771
+ );
71772
+ const allLists = node.directives?.find(
71773
+ (c) => c.name.value === config3.listAllListsDirective
71774
+ );
71775
+ if (parentId && allLists) {
71776
+ ctx.reportError(
71777
+ new graphql25.GraphQLError(
71778
+ `You can't apply both @${config3.listParentDirective} and @${config3.listAllListsDirective} at the same time`
71779
+ )
71780
+ );
71781
+ return;
71782
+ }
71783
+ }
71784
+ };
71785
+ };
71786
+ }
71701
71787
  function getAndVerifyNodeInterface(config3) {
71702
71788
  const { schema } = config3;
71703
71789
  const nodeInterface = schema.getType("Node");
@@ -63973,22 +63973,31 @@ var ListManager = class {
63973
63973
  }
63974
63974
  lists = /* @__PURE__ */ new Map();
63975
63975
  listsByField = /* @__PURE__ */ new Map();
63976
- get(listName, id) {
63976
+ get(listName, id, allLists) {
63977
63977
  const matches = this.lists.get(listName);
63978
63978
  if (!matches || matches.size === 0) {
63979
63979
  return null;
63980
63980
  }
63981
+ if (allLists) {
63982
+ return new ListCollection(
63983
+ Array.from(matches, ([key, value]) => [...value.lists]).flat()
63984
+ );
63985
+ }
63981
63986
  const head = [...matches.values()][0];
63987
+ const { recordType } = head.lists[0];
63988
+ const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
63982
63989
  if (matches?.size === 1) {
63983
- return head;
63990
+ if (!id) {
63991
+ return head;
63992
+ }
63993
+ return parentID === Array.from(matches.keys())[0] ? head : null;
63984
63994
  }
63985
63995
  if (!id) {
63986
- throw new Error(
63987
- `Found multiple instances of "${listName}". Please provide a parentID that corresponds to the object containing the field marked with @list or @paginate.`
63996
+ console.error(
63997
+ `Found multiple instances of "${listName}". Please provide one of @parentID or @allLists directives to help identify which list you want modify. For more information, visit this guide: https://www.houdinigraphql.com/api/graphql#parentidvalue-string `
63988
63998
  );
63999
+ return null;
63989
64000
  }
63990
- const { recordType } = head.lists[0];
63991
- const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
63992
64001
  return this.lists.get(listName)?.get(parentID);
63993
64002
  }
63994
64003
  remove(listName, id) {
@@ -64934,8 +64943,8 @@ var Cache2 = class {
64934
64943
  variables
64935
64944
  );
64936
64945
  }
64937
- list(name2, parentID) {
64938
- const handler = this._internal_unstable.lists.get(name2, parentID);
64946
+ list(name2, parentID, allLists) {
64947
+ const handler = this._internal_unstable.lists.get(name2, parentID, allLists);
64939
64948
  if (!handler) {
64940
64949
  throw new Error(
64941
64950
  `Cannot find list with name: ${name2}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
@@ -65202,15 +65211,15 @@ var CacheInternal = class {
65202
65211
  parentID = id;
65203
65212
  }
65204
65213
  }
65205
- if (operation.list && !this.lists.get(operation.list, parentID)) {
65214
+ if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
65206
65215
  continue;
65207
65216
  }
65208
65217
  const targets = Array.isArray(value) ? value : [value];
65209
65218
  for (const target of targets) {
65210
65219
  if (operation.action === "insert" && target instanceof Object && fields && operation.list) {
65211
- this.cache.list(operation.list, parentID).when(operation.when).addToList(fields, target, variables, operation.position || "last");
65220
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(fields, target, variables, operation.position || "last");
65212
65221
  } else if (operation.action === "remove" && target instanceof Object && fields && operation.list) {
65213
- this.cache.list(operation.list, parentID).when(operation.when).remove(target, variables);
65222
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
65214
65223
  } else if (operation.action === "delete" && operation.type) {
65215
65224
  if (typeof target !== "string") {
65216
65225
  throw new Error("Cannot delete a record with a non-string ID");
@@ -65221,7 +65230,7 @@ var CacheInternal = class {
65221
65230
  }
65222
65231
  this.cache.delete(targetID);
65223
65232
  } else if (operation.action === "toggle" && target instanceof Object && fields && operation.list) {
65224
- this.cache.list(operation.list, parentID).when(operation.when).toggleElement(fields, target, variables, operation.position || "last");
65233
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(fields, target, variables, operation.position || "last");
65225
65234
  }
65226
65235
  }
65227
65236
  }
@@ -67015,6 +67024,8 @@ var Config = class {
67015
67024
  cacheBufferSize;
67016
67025
  defaultCachePolicy;
67017
67026
  defaultPartial;
67027
+ internalListPosition;
67028
+ defaultListTarget = null;
67018
67029
  definitionsFolder;
67019
67030
  newSchema = "";
67020
67031
  newDocuments = "";
@@ -67046,6 +67057,8 @@ var Config = class {
67046
67057
  definitionsPath,
67047
67058
  defaultCachePolicy = "CacheOrNetwork" /* CacheOrNetwork */,
67048
67059
  defaultPartial = false,
67060
+ defaultListPosition = "append",
67061
+ defaultListTarget = null,
67049
67062
  defaultKeys,
67050
67063
  types: types15 = {},
67051
67064
  logLevel,
@@ -67079,6 +67092,8 @@ var Config = class {
67079
67092
  this.cacheBufferSize = cacheBufferSize;
67080
67093
  this.defaultCachePolicy = defaultCachePolicy;
67081
67094
  this.defaultPartial = defaultPartial;
67095
+ this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
67096
+ this.defaultListTarget == defaultListTarget;
67082
67097
  this.definitionsFolder = definitionsPath;
67083
67098
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
67084
67099
  this.disableMasking = disableMasking;
@@ -67293,6 +67308,9 @@ var Config = class {
67293
67308
  get listDirectiveParentIDArg() {
67294
67309
  return "parentID";
67295
67310
  }
67311
+ get listAllListsDirective() {
67312
+ return "allLists";
67313
+ }
67296
67314
  get listNameArg() {
67297
67315
  return "name";
67298
67316
  }
@@ -67374,6 +67392,7 @@ var Config = class {
67374
67392
  this.listPrependDirective,
67375
67393
  this.listAppendDirective,
67376
67394
  this.listDirectiveParentIDArg,
67395
+ this.listAllListsDirective,
67377
67396
  this.whenDirective,
67378
67397
  this.whenNotDirective,
67379
67398
  this.argumentsDirective,
@@ -68375,7 +68394,8 @@ function operationObject({
68375
68394
  }) {
68376
68395
  let parentID;
68377
68396
  let parentKind = "String";
68378
- let position = "last";
68397
+ let position = config3.internalListPosition;
68398
+ let allLists = config3.defaultListTarget ?? void 0;
68379
68399
  let operationWhen;
68380
68400
  const internalDirectives = selection2.directives?.filter(
68381
68401
  (directive) => config3.isInternalDirective(directive)
@@ -68387,15 +68407,21 @@ function operationObject({
68387
68407
  const append = internalDirectives.find(
68388
68408
  ({ name: name2 }) => name2.value === config3.listAppendDirective
68389
68409
  );
68390
- const when = internalDirectives.find(({ name: name2 }) => name2.value === "when");
68391
- const when_not = internalDirectives.find(({ name: name2 }) => name2.value === "when_not");
68410
+ if (append) {
68411
+ position = "last";
68412
+ }
68413
+ if (prepend) {
68414
+ position = "first";
68415
+ }
68416
+ const allListsDirective = internalDirectives.find(
68417
+ ({ name: name2 }) => name2.value === config3.listAllListsDirective
68418
+ );
68392
68419
  let parent = internalDirectives.find(
68393
68420
  ({ name: name2 }) => name2.value === config3.listParentDirective
68394
68421
  );
68395
- if (append && prepend) {
68396
- throw new HoudiniError({ filepath, message: "you have both applied" });
68397
- }
68398
- position = prepend ? "first" : "last";
68422
+ allLists = allListsDirective ? "all" : void 0;
68423
+ const when = internalDirectives.find(({ name: name2 }) => name2.value === "when");
68424
+ const when_not = internalDirectives.find(({ name: name2 }) => name2.value === "when_not");
68399
68425
  let parentIDArg = parent?.arguments?.find((argument) => argument.name.value === "value");
68400
68426
  if (!parentIDArg) {
68401
68427
  parentIDArg = (append || prepend)?.arguments?.find(
@@ -68457,7 +68483,10 @@ function operationObject({
68457
68483
  operation.type = type;
68458
68484
  }
68459
68485
  if (operationKind === "insert" || operationKind === "toggle") {
68460
- operation.position = position || "last";
68486
+ operation.position = position;
68487
+ }
68488
+ if (operationKind === "insert" && allLists) {
68489
+ operation.target = "all";
68461
68490
  }
68462
68491
  if (parentID) {
68463
68492
  operation.parentID = {
@@ -68581,12 +68610,15 @@ async function paginate(config3, documents) {
68581
68610
  {}
68582
68611
  ) || {};
68583
68612
  let newVariables = Object.fromEntries(
68584
- Object.entries(flags).filter(([, spec]) => spec.enabled).map(([fieldName, spec]) => [
68613
+ Object.entries(flags).filter(
68614
+ ([, spec]) => spec.enabled && spec.variableName === void 0
68615
+ ).map(([fieldName, spec]) => [
68585
68616
  fieldName,
68586
68617
  staticVariableDefinition(
68587
68618
  fieldName,
68588
68619
  spec.type,
68589
- spec.defaultValue
68620
+ spec.defaultValue,
68621
+ spec.variableName
68590
68622
  )
68591
68623
  ])
68592
68624
  );
@@ -68838,8 +68870,11 @@ function replaceArgumentsWithVariables(args, flags) {
68838
68870
  const oldValue = arg.value.value;
68839
68871
  flags[arg.name.value].defaultValue = spec.type === "Int" ? parseInt(oldValue) : oldValue;
68840
68872
  }
68873
+ if (arg.value.kind === "Variable") {
68874
+ flags[arg.name.value].variableName = arg.value.name.value;
68875
+ }
68841
68876
  seenArgs[arg.name.value] = true;
68842
- return variableAsArgument(arg.name.value);
68877
+ return variableAsArgument(arg.name.value, flags[arg.name.value].variableName);
68843
68878
  });
68844
68879
  for (const name2 of Object.keys(flags)) {
68845
68880
  const spec = flags[name2];
@@ -68856,7 +68891,7 @@ function replaceArgumentsWithVariables(args, flags) {
68856
68891
  }
68857
68892
  return newArgs;
68858
68893
  }
68859
- function variableAsArgument(name2) {
68894
+ function variableAsArgument(name2, variable) {
68860
68895
  return {
68861
68896
  kind: graphql9.Kind.ARGUMENT,
68862
68897
  name: {
@@ -68867,12 +68902,12 @@ function variableAsArgument(name2) {
68867
68902
  kind: graphql9.Kind.VARIABLE,
68868
68903
  name: {
68869
68904
  kind: graphql9.Kind.NAME,
68870
- value: name2
68905
+ value: variable ?? name2
68871
68906
  }
68872
68907
  }
68873
68908
  };
68874
68909
  }
68875
- function staticVariableDefinition(name2, type, defaultValue) {
68910
+ function staticVariableDefinition(name2, type, defaultValue, variableName) {
68876
68911
  return {
68877
68912
  kind: graphql9.Kind.VARIABLE_DEFINITION,
68878
68913
  type: {
@@ -68886,7 +68921,7 @@ function staticVariableDefinition(name2, type, defaultValue) {
68886
68921
  kind: graphql9.Kind.VARIABLE,
68887
68922
  name: {
68888
68923
  kind: graphql9.Kind.NAME,
68889
- value: name2
68924
+ value: variableName ?? name2
68890
68925
  }
68891
68926
  },
68892
68927
  defaultValue: !defaultValue ? void 0 : {
@@ -70695,6 +70730,11 @@ directive @${config3.listPrependDirective}(
70695
70730
  """
70696
70731
  directive @${config3.listAppendDirective}(${config3.listDirectiveParentIDArg}: ID) on FRAGMENT_SPREAD
70697
70732
 
70733
+ """
70734
+ @${config3.listAllListsDirective} is used to tell the runtime to add the result to all list
70735
+ """
70736
+ directive @${config3.listAllListsDirective} on FRAGMENT_SPREAD
70737
+
70698
70738
  """
70699
70739
  @${config3.listParentDirective} is used to provide a parentID without specifying position or in situations
70700
70740
  where it doesn't make sense (eg when deleting a node.)
@@ -71274,6 +71314,7 @@ async function typeCheck(config3, docs) {
71274
71314
  listTypes,
71275
71315
  fragments
71276
71316
  }),
71317
+ checkMutationOperation(config3),
71277
71318
  nodeDirectives(config3, [config3.paginateDirective]),
71278
71319
  knownArguments(config3),
71279
71320
  validateFragmentArguments(config3, filepath, fragments),
@@ -71332,24 +71373,33 @@ var validateLists = ({
71332
71373
  if (directive) {
71333
71374
  return;
71334
71375
  }
71376
+ let parentIdFound = false;
71335
71377
  directive = node.directives?.find(({ name: name2 }) => [
71336
71378
  [config3.listPrependDirective, config3.listAppendDirective].includes(name2.value)
71337
71379
  ]);
71338
- if (!directive) {
71339
- ctx.reportError(
71340
- new graphql25.GraphQLError("parentID is required for this list fragment")
71380
+ if (directive) {
71381
+ let parentArg = directive.arguments?.find(
71382
+ (arg) => arg.name.value === config3.listDirectiveParentIDArg
71341
71383
  );
71384
+ if (parentArg) {
71385
+ parentIdFound = true;
71386
+ }
71387
+ }
71388
+ if (parentIdFound) {
71342
71389
  return;
71343
71390
  }
71344
- let parentArg = directive.arguments?.find(
71345
- (arg) => arg.name.value === config3.listDirectiveParentIDArg
71391
+ const allLists = node.directives?.find(
71392
+ ({ name: name2 }) => config3.listAllListsDirective === name2.value
71346
71393
  );
71347
- if (!parentArg) {
71348
- ctx.reportError(
71349
- new graphql25.GraphQLError("parentID is required for this list fragment")
71350
- );
71394
+ if (allLists || config3.defaultListTarget === "all") {
71351
71395
  return;
71352
71396
  }
71397
+ ctx.reportError(
71398
+ new graphql25.GraphQLError(
71399
+ `For this list fragment, you need to add or @${config3.listParentDirective} or @${config3.listAllListsDirective} directive to specify the behavior`
71400
+ )
71401
+ );
71402
+ return;
71353
71403
  },
71354
71404
  Directive(node) {
71355
71405
  const directiveName = node.name.value;
@@ -71692,6 +71742,42 @@ function nodeDirectives(config3, directives) {
71692
71742
  };
71693
71743
  };
71694
71744
  }
71745
+ function checkMutationOperation(config3) {
71746
+ return function(ctx) {
71747
+ return {
71748
+ FragmentSpread(node, _, __, ___, ancestors) {
71749
+ const append = node.directives?.find(
71750
+ (c) => c.name.value === config3.listAppendDirective
71751
+ );
71752
+ const prepend = node.directives?.find(
71753
+ (c) => c.name.value === config3.listPrependDirective
71754
+ );
71755
+ if (append && prepend) {
71756
+ ctx.reportError(
71757
+ new graphql25.GraphQLError(
71758
+ `You can't apply both @${config3.listPrependDirective} and @${config3.listAppendDirective} at the same time`
71759
+ )
71760
+ );
71761
+ return;
71762
+ }
71763
+ const parentId = node.directives?.find(
71764
+ (c) => c.name.value === config3.listParentDirective
71765
+ );
71766
+ const allLists = node.directives?.find(
71767
+ (c) => c.name.value === config3.listAllListsDirective
71768
+ );
71769
+ if (parentId && allLists) {
71770
+ ctx.reportError(
71771
+ new graphql25.GraphQLError(
71772
+ `You can't apply both @${config3.listParentDirective} and @${config3.listAllListsDirective} at the same time`
71773
+ )
71774
+ );
71775
+ return;
71776
+ }
71777
+ }
71778
+ };
71779
+ };
71780
+ }
71695
71781
  function getAndVerifyNodeInterface(config3) {
71696
71782
  const { schema } = config3;
71697
71783
  const nodeInterface = schema.getType("Node");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "0.17.7",
3
+ "version": "0.17.9",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "type": "module",
6
6
  "devDependencies": {