houdini 1.0.7 → 1.0.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.
@@ -10,7 +10,7 @@ const throwOnError = ({ operations, error }) => () => {
10
10
  return {
11
11
  async end(ctx, { value, resolve }) {
12
12
  if (value.errors && value.errors.length > 0 && throwOnKind(ctx.artifact.kind)) {
13
- const result = await (error ?? defaultErrorFn)(value.errors);
13
+ const result = await (error ?? defaultErrorFn)(value.errors, ctx);
14
14
  throw result;
15
15
  }
16
16
  resolve(ctx);
@@ -1,5 +1,5 @@
1
1
  import type { GraphQLSchema } from 'graphql';
2
- import type { CachePolicies } from './types';
2
+ import type { CachePolicies, PaginateModes } from './types';
3
3
  export declare function getMockConfig(): ConfigFile | null;
4
4
  export declare function setMockConfig(config: ConfigFile | null): void;
5
5
  export declare function defaultConfigValues(file: ConfigFile): ConfigFile;
@@ -67,6 +67,10 @@ export type ConfigFile = {
67
67
  * Specifies whether mutation should apply a specific target list. When you set `all`, it's like adding the directive `@allLists` to all _insert fragment (default: `null`)
68
68
  */
69
69
  defaultListTarget?: 'all' | null;
70
+ /**
71
+ * Specifies whether the default paginate mode is Infinite or SinglePage. (default: `Infinite`)
72
+ */
73
+ defaultPaginateMode?: PaginateModes;
70
74
  /**
71
75
  * A list of fields to use when computing a record’s id. The default value is ['id']. For more information: https://www.houdinigraphql.com/guides/caching-data#custom-ids
72
76
  */
@@ -1,11 +1,16 @@
1
+ type ValuesOf<Target> = Target[keyof Target];
1
2
  export declare const CachePolicy: {
2
3
  readonly CacheOrNetwork: "CacheOrNetwork";
3
4
  readonly CacheOnly: "CacheOnly";
4
5
  readonly NetworkOnly: "NetworkOnly";
5
6
  readonly CacheAndNetwork: "CacheAndNetwork";
6
7
  };
7
- type ValuesOf<Target> = Target[keyof Target];
8
8
  export type CachePolicies = ValuesOf<typeof CachePolicy>;
9
+ export declare const PaginateMode: {
10
+ readonly Infinite: "Infinite";
11
+ readonly SinglePage: "SinglePage";
12
+ };
13
+ export type PaginateModes = ValuesOf<typeof PaginateMode>;
9
14
  declare global {
10
15
  namespace App {
11
16
  interface Session {
@@ -77,6 +82,7 @@ export type BaseCompiledDocument<_Kind extends ArtifactKinds> = {
77
82
  targetType: string;
78
83
  paginated: boolean;
79
84
  direction: 'forward' | 'backward' | 'both';
85
+ mode: PaginateModes;
80
86
  };
81
87
  pluginData?: Record<string, any>;
82
88
  };
@@ -4,6 +4,10 @@ const CachePolicy = {
4
4
  NetworkOnly: "NetworkOnly",
5
5
  CacheAndNetwork: "CacheAndNetwork"
6
6
  };
7
+ const PaginateMode = {
8
+ Infinite: "Infinite",
9
+ SinglePage: "SinglePage"
10
+ };
7
11
  const ArtifactKind = {
8
12
  Query: "HoudiniQuery",
9
13
  Subscription: "HoudiniSubscription",
@@ -32,5 +36,6 @@ export {
32
36
  CompiledQueryKind,
33
37
  CompiledSubscriptionKind,
34
38
  DataSource,
39
+ PaginateMode,
35
40
  RefetchUpdateMode
36
41
  };
@@ -37667,14 +37667,18 @@ var require_lib3 = __commonJS({
37667
37667
  }
37668
37668
  });
37669
37669
 
37670
- // ../../node_modules/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.js
37670
+ // ../../node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.js
37671
37671
  var require_tslib = __commonJS({
37672
- "../../node_modules/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.js"(exports, module2) {
37672
+ "../../node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.js"(exports, module2) {
37673
37673
  var __extends;
37674
37674
  var __assign;
37675
37675
  var __rest;
37676
37676
  var __decorate;
37677
37677
  var __param;
37678
+ var __esDecorate;
37679
+ var __runInitializers;
37680
+ var __propKey;
37681
+ var __setFunctionName;
37678
37682
  var __metadata;
37679
37683
  var __awaiter;
37680
37684
  var __generator;
@@ -37771,6 +37775,65 @@ var require_tslib = __commonJS({
37771
37775
  decorator(target, key, paramIndex);
37772
37776
  };
37773
37777
  };
37778
+ __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
37779
+ function accept(f) {
37780
+ if (f !== void 0 && typeof f !== "function")
37781
+ throw new TypeError("Function expected");
37782
+ return f;
37783
+ }
37784
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
37785
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
37786
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
37787
+ var _, done = false;
37788
+ for (var i = decorators.length - 1; i >= 0; i--) {
37789
+ var context = {};
37790
+ for (var p in contextIn)
37791
+ context[p] = p === "access" ? {} : contextIn[p];
37792
+ for (var p in contextIn.access)
37793
+ context.access[p] = contextIn.access[p];
37794
+ context.addInitializer = function(f) {
37795
+ if (done)
37796
+ throw new TypeError("Cannot add initializers after decoration has completed");
37797
+ extraInitializers.push(accept(f || null));
37798
+ };
37799
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
37800
+ if (kind === "accessor") {
37801
+ if (result === void 0)
37802
+ continue;
37803
+ if (result === null || typeof result !== "object")
37804
+ throw new TypeError("Object expected");
37805
+ if (_ = accept(result.get))
37806
+ descriptor.get = _;
37807
+ if (_ = accept(result.set))
37808
+ descriptor.set = _;
37809
+ if (_ = accept(result.init))
37810
+ initializers.push(_);
37811
+ } else if (_ = accept(result)) {
37812
+ if (kind === "field")
37813
+ initializers.push(_);
37814
+ else
37815
+ descriptor[key] = _;
37816
+ }
37817
+ }
37818
+ if (target)
37819
+ Object.defineProperty(target, contextIn.name, descriptor);
37820
+ done = true;
37821
+ };
37822
+ __runInitializers = function(thisArg, initializers, value) {
37823
+ var useValue = arguments.length > 2;
37824
+ for (var i = 0; i < initializers.length; i++) {
37825
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
37826
+ }
37827
+ return useValue ? value : void 0;
37828
+ };
37829
+ __propKey = function(x) {
37830
+ return typeof x === "symbol" ? x : "".concat(x);
37831
+ };
37832
+ __setFunctionName = function(f, name, prefix) {
37833
+ if (typeof name === "symbol")
37834
+ name = name.description ? "[".concat(name.description, "]") : "";
37835
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
37836
+ };
37774
37837
  __metadata = function(metadataKey, metadataValue) {
37775
37838
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
37776
37839
  return Reflect.metadata(metadataKey, metadataValue);
@@ -38005,7 +38068,7 @@ var require_tslib = __commonJS({
38005
38068
  }, i;
38006
38069
  function verb(n, f) {
38007
38070
  i[n] = o[n] ? function(v) {
38008
- return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
38071
+ return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v;
38009
38072
  } : f;
38010
38073
  }
38011
38074
  };
@@ -38083,6 +38146,10 @@ var require_tslib = __commonJS({
38083
38146
  exporter("__rest", __rest);
38084
38147
  exporter("__decorate", __decorate);
38085
38148
  exporter("__param", __param);
38149
+ exporter("__esDecorate", __esDecorate);
38150
+ exporter("__runInitializers", __runInitializers);
38151
+ exporter("__propKey", __propKey);
38152
+ exporter("__setFunctionName", __setFunctionName);
38086
38153
  exporter("__metadata", __metadata);
38087
38154
  exporter("__awaiter", __awaiter);
38088
38155
  exporter("__generator", __generator);
@@ -54207,6 +54274,10 @@ var CachePolicy = {
54207
54274
  NetworkOnly: "NetworkOnly",
54208
54275
  CacheAndNetwork: "CacheAndNetwork"
54209
54276
  };
54277
+ var PaginateMode = {
54278
+ Infinite: "Infinite",
54279
+ SinglePage: "SinglePage"
54280
+ };
54210
54281
  var ArtifactKind = {
54211
54282
  Query: "HoudiniQuery",
54212
54283
  Subscription: "HoudiniSubscription",
@@ -56561,6 +56632,7 @@ var Config = class {
56561
56632
  defaultPartial;
56562
56633
  internalListPosition;
56563
56634
  defaultListTarget = null;
56635
+ defaultPaginateMode;
56564
56636
  definitionsFolder;
56565
56637
  newDocuments = "";
56566
56638
  defaultKeys = ["id"];
@@ -56597,6 +56669,7 @@ var Config = class {
56597
56669
  defaultPartial = false,
56598
56670
  defaultListPosition = "append",
56599
56671
  defaultListTarget = null,
56672
+ defaultPaginateMode = PaginateMode.Infinite,
56600
56673
  defaultKeys,
56601
56674
  types: types14 = {},
56602
56675
  logLevel,
@@ -56630,6 +56703,7 @@ var Config = class {
56630
56703
  this.defaultPartial = defaultPartial;
56631
56704
  this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
56632
56705
  this.defaultListTarget = defaultListTarget;
56706
+ this.defaultPaginateMode = defaultPaginateMode;
56633
56707
  this.definitionsFolder = definitionsPath;
56634
56708
  this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
56635
56709
  this.defaultFragmentMasking = defaultFragmentMasking;
@@ -56893,7 +56967,7 @@ var Config = class {
56893
56967
  get listAllListsDirective() {
56894
56968
  return "allLists";
56895
56969
  }
56896
- get listNameArg() {
56970
+ get listOrPaginateNameArg() {
56897
56971
  return "name";
56898
56972
  }
56899
56973
  get insertFragmentSuffix() {
@@ -56926,8 +57000,8 @@ var Config = class {
56926
57000
  get paginateDirective() {
56927
57001
  return "paginate";
56928
57002
  }
56929
- get paginateNameArg() {
56930
- return "name";
57003
+ get paginateModeArg() {
57004
+ return "mode";
56931
57005
  }
56932
57006
  get cacheDirective() {
56933
57007
  return "cache";
@@ -56969,7 +57043,7 @@ var Config = class {
56969
57043
  return name + this.removeFragmentSuffix;
56970
57044
  }
56971
57045
  isInternalEnum(node) {
56972
- return node.name.value === "CachePolicy";
57046
+ return node.name.value === "CachePolicy" || node.name.value === "PaginateMode";
56973
57047
  }
56974
57048
  isInternalDirective(name) {
56975
57049
  const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
@@ -58329,6 +58403,7 @@ async function paginate(config2, documents) {
58329
58403
  let refetchQueryName = "";
58330
58404
  let nodeQuery = false;
58331
58405
  let fragment = "";
58406
+ let paginateMode = config2.defaultPaginateMode;
58332
58407
  doc.document = graphql8.visit(doc.document, {
58333
58408
  OperationDefinition(node) {
58334
58409
  if (node.operation !== "query") {
@@ -58394,6 +58469,14 @@ async function paginate(config2, documents) {
58394
58469
  }
58395
58470
  },
58396
58471
  Directive(node) {
58472
+ if (node.name.value === config2.paginateDirective) {
58473
+ const paginateModeArg = node?.arguments?.find(
58474
+ (arg) => arg.name.value === config2.paginateModeArg
58475
+ );
58476
+ if (paginateModeArg && paginateModeArg.value.kind === "EnumValue") {
58477
+ paginateMode = paginateModeArg.value.value;
58478
+ }
58479
+ }
58397
58480
  if (node.name.value !== config2.argumentsDirective) {
58398
58481
  return;
58399
58482
  }
@@ -58438,7 +58521,8 @@ async function paginate(config2, documents) {
58438
58521
  targetType,
58439
58522
  paginated: true,
58440
58523
  direction,
58441
- start
58524
+ start,
58525
+ mode: paginateMode
58442
58526
  };
58443
58527
  if (!fragment) {
58444
58528
  continue;
@@ -58787,7 +58871,9 @@ async function addListFragments(config2, documents) {
58787
58871
  doc.document = graphql9.visit(doc.document, {
58788
58872
  Directive(node, key, parent, path2, ancestors) {
58789
58873
  if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
58790
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
58874
+ const nameArg = node.arguments?.find(
58875
+ (arg) => arg.name.value === config2.listOrPaginateNameArg
58876
+ );
58791
58877
  let error = {
58792
58878
  ...new graphql9.GraphQLError(
58793
58879
  "",
@@ -59087,14 +59173,23 @@ function fieldKey(config2, field) {
59087
59173
  const attributeName = field.alias?.value || field.name.value;
59088
59174
  const printed = graphql10.print(field);
59089
59175
  const secondParse = graphql10.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
59090
- const paginated = !!field.directives?.find(
59176
+ let paginateMode = config2.defaultPaginateMode;
59177
+ const paginatedDirective = field.directives?.find(
59091
59178
  (directive) => directive.name.value === config2.paginateDirective
59092
59179
  );
59093
- const paginationArgs = ["first", "after", "last", "before", "limit", "offset"];
59180
+ if (paginatedDirective) {
59181
+ const paginateModeArg = paginatedDirective?.arguments?.find(
59182
+ (arg) => arg.name.value === config2.paginateModeArg
59183
+ );
59184
+ if (paginateModeArg && paginateModeArg.value.kind === "EnumValue") {
59185
+ paginateMode = paginateModeArg.value.value;
59186
+ }
59187
+ }
59188
+ const paginationArgs = paginateMode === "SinglePage" ? [] : ["first", "after", "last", "before", "limit", "offset"];
59094
59189
  const argObj = (secondParse.arguments || []).reduce((acc, arg) => {
59095
59190
  const start = arg.value.loc?.start;
59096
59191
  const end = arg.value.loc?.end;
59097
- if (paginated && paginationArgs.includes(arg.name.value)) {
59192
+ if (paginatedDirective && paginationArgs.includes(arg.name.value)) {
59098
59193
  return acc;
59099
59194
  }
59100
59195
  if (!start || !end) {
@@ -59108,7 +59203,7 @@ function fieldKey(config2, field) {
59108
59203
  const args = Object.keys(argObj);
59109
59204
  args.sort();
59110
59205
  let key = Object.values(argObj).length > 0 ? `${attributeName}(${args.map((key2) => `${key2}: ${argObj[key2]}`).join(", ")})` : attributeName;
59111
- if (paginated) {
59206
+ if (paginatedDirective) {
59112
59207
  key = key + "::paginated";
59113
59208
  }
59114
59209
  return key;
@@ -59248,7 +59343,9 @@ function selection({
59248
59343
  const listDirective = field.directives?.find(
59249
59344
  (directive) => [config2.listDirective, config2.paginateDirective].includes(directive.name.value)
59250
59345
  );
59251
- const nameArg = listDirective?.arguments?.find((arg) => arg.name.value === "name");
59346
+ const nameArg = listDirective?.arguments?.find(
59347
+ (arg) => arg.name.value === config2.listOrPaginateNameArg
59348
+ );
59252
59349
  if (nameArg && nameArg.value.kind === "StringValue") {
59253
59350
  const { connection, type: connectionType } = connectionSelection(
59254
59351
  config2,
@@ -59367,7 +59464,7 @@ function artifactGenerator(stats) {
59367
59464
  return;
59368
59465
  }
59369
59466
  const nameArg = node.arguments?.find(
59370
- (arg) => arg.name.value === config2.listNameArg
59467
+ (arg) => arg.name.value === config2.listOrPaginateNameArg
59371
59468
  );
59372
59469
  if (!nameArg || nameArg.value.kind !== "StringValue") {
59373
59470
  throw new HoudiniError({
@@ -60737,7 +60834,9 @@ function listDefinitions(config2, body, docs) {
60737
60834
  if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
60738
60835
  return;
60739
60836
  }
60740
- const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
60837
+ const nameArg = node.arguments?.find(
60838
+ (arg) => arg.name.value === config2.listOrPaginateNameArg
60839
+ );
60741
60840
  const nameValue = nameArg?.value?.value || "";
60742
60841
  if (!nameValue || visitedLists.has(nameValue)) {
60743
60842
  return;
@@ -61062,17 +61161,22 @@ enum CachePolicy {
61062
61161
  ${CachePolicy.NetworkOnly}
61063
61162
  }
61064
61163
 
61164
+ enum PaginateMode {
61165
+ ${PaginateMode.Infinite}
61166
+ ${PaginateMode.SinglePage}
61167
+ }
61168
+
61065
61169
  """
61066
61170
  @${config2.listDirective} is used to mark a field for the runtime as a place to add or remove
61067
61171
  entities in mutations
61068
61172
  """
61069
- directive @${config2.listDirective}(${config2.listNameArg}: String!, connection: Boolean) on FIELD
61173
+ directive @${config2.listDirective}(${config2.listOrPaginateNameArg}: String!, connection: Boolean) on FIELD
61070
61174
 
61071
61175
  """
61072
61176
  @${config2.paginateDirective} is used to to mark a field for pagination.
61073
61177
  More info in the [doc](${siteURL}/guides/pagination).
61074
61178
  """
61075
- directive @${config2.paginateDirective}(${config2.paginateNameArg}: String) on FIELD
61179
+ directive @${config2.paginateDirective}(${config2.listOrPaginateNameArg}: String, ${config2.paginateModeArg}: PaginateMode) on FIELD
61076
61180
 
61077
61181
  """
61078
61182
  @${config2.listPrependDirective} is used to tell the runtime to add the result to the end of the list
@@ -61338,7 +61442,7 @@ async function typeCheck(config2, docs) {
61338
61442
  }
61339
61443
  needsParent = needsParent || definition.kind === "FragmentDefinition";
61340
61444
  const nameArg = directive.arguments?.find(
61341
- ({ name }) => name.value === config2.listNameArg
61445
+ ({ name }) => name.value === config2.listOrPaginateNameArg
61342
61446
  );
61343
61447
  if (!nameArg) {
61344
61448
  if (directive.name.value === config2.listDirective) {
@@ -61818,7 +61922,14 @@ function paginateArgs(config2, filepath) {
61818
61922
  )
61819
61923
  );
61820
61924
  }
61821
- if (forward && backwards) {
61925
+ const paginateModeArg = node?.arguments?.find(
61926
+ (arg) => arg.name.value === config2.paginateModeArg
61927
+ );
61928
+ let paginateMode = config2.defaultPaginateMode;
61929
+ if (paginateModeArg && paginateModeArg.value.kind === "EnumValue") {
61930
+ paginateMode = paginateModeArg.value.value;
61931
+ }
61932
+ if (forward && backwards && paginateMode === "Infinite") {
61822
61933
  ctx.reportError(
61823
61934
  new graphql23.GraphQLError(
61824
61935
  `A field with cursor pagination cannot go forwards an backwards simultaneously`