houdini 0.13.3-alpha.0 → 0.13.6

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 (47) hide show
  1. package/build/cmd/generate.js +6 -1
  2. package/build/cmd/generators/index.d.ts +1 -0
  3. package/build/cmd/generators/index.js +2 -0
  4. package/build/cmd/generators/schema/index.d.ts +3 -0
  5. package/build/cmd/generators/schema/index.js +63 -0
  6. package/build/cmd/generators/typescript/index.js +8 -1
  7. package/build/cmd/transforms/list.js +9 -7
  8. package/build/cmd/transforms/schema.js +4 -4
  9. package/build/cmd.js +60 -37
  10. package/build/runtime/network.d.ts +9 -4
  11. package/build/runtime/network.js +4 -4
  12. package/build/runtime/pagination.js +17 -14
  13. package/build/runtime/query.js +2 -0
  14. package/build/runtime/utils.js +18 -1
  15. package/build/runtime-cjs/network.d.ts +9 -4
  16. package/build/runtime-cjs/network.js +4 -4
  17. package/build/runtime-cjs/pagination.js +17 -14
  18. package/build/runtime-cjs/query.js +2 -0
  19. package/build/runtime-cjs/utils.js +18 -1
  20. package/build/runtime-esm/network.d.ts +9 -4
  21. package/build/runtime-esm/network.js +4 -4
  22. package/build/runtime-esm/pagination.js +19 -12
  23. package/build/runtime-esm/query.js +2 -0
  24. package/build/runtime-esm/utils.js +18 -1
  25. package/cmd/generate.ts +4 -0
  26. package/cmd/generators/artifacts/artifacts.test.ts +4 -4
  27. package/cmd/generators/artifacts/indexFile.test.ts +3 -3
  28. package/cmd/generators/index.ts +1 -0
  29. package/cmd/generators/runtime/copyRuntime.test.ts +2 -2
  30. package/cmd/generators/runtime/indexFile.test.ts +3 -3
  31. package/cmd/generators/schema/index.ts +19 -0
  32. package/cmd/generators/schema/schema.test.ts +186 -0
  33. package/cmd/generators/typescript/index.ts +29 -0
  34. package/cmd/generators/typescript/typescript.test.ts +84 -0
  35. package/cmd/transforms/list.ts +8 -7
  36. package/cmd/transforms/schema.ts +51 -49
  37. package/package.json +3 -3
  38. package/runtime/cache/tests/readwrite.test.ts +0 -1
  39. package/runtime/network.ts +8 -6
  40. package/runtime/pagination.ts +22 -18
  41. package/runtime/query.ts +5 -2
  42. package/runtime/scalars.test.ts +10 -10
  43. package/runtime/utils.ts +20 -1
  44. package/build/runtime-esm/cache/list.d.ts +0 -35
  45. package/build/runtime-esm/cache/list.js +0 -203
  46. package/build/runtime-esm/cache/record.d.ts +0 -40
  47. package/build/runtime-esm/cache/record.js +0 -195
@@ -102,10 +102,14 @@ exports.runPipeline = function (config, docs) { return __awaiter(void 0, void 0,
102
102
  switch (_a.label) {
103
103
  case 0:
104
104
  // we need to create the runtime folder structure
105
- return [4 /*yield*/, config.createDirectories()];
105
+ return [4 /*yield*/, config.createDirectories()
106
+ // reset the newSchema accumulator
107
+ ];
106
108
  case 1:
107
109
  // we need to create the runtime folder structure
108
110
  _a.sent();
111
+ // reset the newSchema accumulator
112
+ config.newSchema = '';
109
113
  return [4 /*yield*/, houdini_common_1.runPipeline(config, [
110
114
  validators.typeCheck,
111
115
  validators.uniqueNames,
@@ -125,6 +129,7 @@ exports.runPipeline = function (config, docs) { return __awaiter(void 0, void 0,
125
129
  generators.runtime,
126
130
  generators.typescript,
127
131
  generators.persistOutput,
132
+ generators.schema,
128
133
  ], docs)];
129
134
  case 2:
130
135
  _a.sent();
@@ -2,3 +2,4 @@ export { default as artifacts } from './artifacts';
2
2
  export { default as runtime } from './runtime';
3
3
  export { default as typescript } from './typescript';
4
4
  export { default as persistOutput } from './persistedQueries';
5
+ export { default as schema } from './schema';
@@ -8,3 +8,5 @@ var typescript_1 = require("./typescript");
8
8
  Object.defineProperty(exports, "typescript", { enumerable: true, get: function () { return typescript_1.default; } });
9
9
  var persistedQueries_1 = require("./persistedQueries");
10
10
  Object.defineProperty(exports, "persistOutput", { enumerable: true, get: function () { return persistedQueries_1.default; } });
11
+ var schema_1 = require("./schema");
12
+ Object.defineProperty(exports, "schema", { enumerable: true, get: function () { return schema_1.default; } });
@@ -0,0 +1,3 @@
1
+ import { Config } from 'houdini-common';
2
+ import { CollectedGraphQLDocument } from '../../types';
3
+ export default function schemaGenerator(config: Config, docs: CollectedGraphQLDocument[]): Promise<void>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var promises_1 = __importDefault(require("fs/promises"));
43
+ // schemaGenerator updates the schema file to contain all of the generated
44
+ // definitions
45
+ function schemaGenerator(config, docs) {
46
+ return __awaiter(this, void 0, void 0, function () {
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ if (!config.newSchema) {
51
+ return [2 /*return*/];
52
+ }
53
+ // print the updated version of the schema over the existing one
54
+ return [4 /*yield*/, promises_1.default.writeFile(config.definitionsPath, config.newSchema, 'utf-8')];
55
+ case 1:
56
+ // print the updated version of the schema over the existing one
57
+ _a.sent();
58
+ return [2 /*return*/];
59
+ }
60
+ });
61
+ });
62
+ }
63
+ exports.default = schemaGenerator;
@@ -166,11 +166,12 @@ function typescriptGenerator(config, docs) {
166
166
  exports.default = typescriptGenerator;
167
167
  function generateOperationTypeDefs(config, body, definition, selections, visitedTypes) {
168
168
  return __awaiter(this, void 0, void 0, function () {
169
- var inputTypeName, shapeTypeName, type, hasInputs, _a, _b, variableDefinition;
169
+ var inputTypeName, shapeTypeName, afterLoadTypeName, type, hasInputs, _a, _b, variableDefinition;
170
170
  var e_1, _c;
171
171
  return __generator(this, function (_d) {
172
172
  inputTypeName = definition.name.value + "$input";
173
173
  shapeTypeName = definition.name.value + "$result";
174
+ afterLoadTypeName = definition.name.value + "$afterLoad";
174
175
  if (definition.operation === 'query') {
175
176
  type = config.schema.getQueryType();
176
177
  }
@@ -206,6 +207,12 @@ function generateOperationTypeDefs(config, body, definition, selections, visited
206
207
  visitedTypes: visitedTypes,
207
208
  body: body,
208
209
  }))));
210
+ // generate type for the afterload function
211
+ body.push(AST.exportNamedDeclaration(AST.tsTypeAliasDeclaration(AST.identifier(afterLoadTypeName), AST.tsTypeLiteral([
212
+ types_1.readonlyProperty(AST.tsPropertySignature(AST.stringLiteral('data'), AST.tsTypeAnnotation(AST.tsTypeLiteral([
213
+ types_1.readonlyProperty(AST.tsPropertySignature(AST.stringLiteral(definition.name.value), AST.tsTypeAnnotation(AST.tsTypeReference(AST.identifier(shapeTypeName))))),
214
+ ])))),
215
+ ]))));
209
216
  // if there are variables in this query
210
217
  if (hasInputs && definition.variableDefinitions && definition.variableDefinitions.length > 0) {
211
218
  try {
@@ -110,8 +110,8 @@ var paginate_1 = require("./paginate");
110
110
  function addListFragments(config, documents) {
111
111
  return __awaiter(this, void 0, void 0, function () {
112
112
  var lists, errors, _loop_1, documents_1, documents_1_1, doc, listTargets, generatedDoc;
113
- var e_1, _a;
114
- return __generator(this, function (_b) {
113
+ var e_1, _a, _b;
114
+ return __generator(this, function (_c) {
115
115
  lists = {};
116
116
  errors = [];
117
117
  _loop_1 = function (doc) {
@@ -231,7 +231,9 @@ function addListFragments(config, documents) {
231
231
  if (Object.keys(lists).length === 0) {
232
232
  return [2 /*return*/];
233
233
  }
234
- generatedDoc = __assign({ kind: 'Document', definitions: Object.entries(lists).flatMap(function (_a) {
234
+ generatedDoc = {
235
+ kind: 'Document',
236
+ definitions: (_b = Object.entries(lists).flatMap(function (_a) {
235
237
  var _b = __read(_a, 2), name = _b[0], _c = _b[1], selection = _c.selection, type = _c.type;
236
238
  // look up the type
237
239
  var schemaType = config.schema.getType(type.name);
@@ -334,8 +336,7 @@ function addListFragments(config, documents) {
334
336
  },
335
337
  },
336
338
  ];
337
- }) }, listTargets.flatMap(function (typeName) { return [
338
- {
339
+ })).concat.apply(_b, __spread(listTargets.map(function (typeName) { return ({
339
340
  kind: 'DirectiveDefinition',
340
341
  name: {
341
342
  kind: 'Name',
@@ -350,8 +351,9 @@ function addListFragments(config, documents) {
350
351
  },
351
352
  ],
352
353
  repeatable: true,
353
- },
354
- ]; }));
354
+ }); }))),
355
+ };
356
+ config.newSchema += '\n' + generatedDoc.definitions.map(graphql.print).join('\n');
355
357
  documents.push({
356
358
  name: 'generated::lists',
357
359
  kind: types_2.ArtifactKind.Fragment,
@@ -61,13 +61,13 @@ var types_1 = require("../../runtime/types");
61
61
  // graphqlExtensions adds a few different things to the graphql schema
62
62
  function graphqlExtensions(config, documents) {
63
63
  return __awaiter(this, void 0, void 0, function () {
64
+ var internalSchema;
64
65
  return __generator(this, function (_a) {
66
+ internalSchema = "\nenum CachePolicy {\n\t" + types_1.CachePolicy.CacheAndNetwork + "\n\t" + types_1.CachePolicy.CacheOnly + "\n\t" + types_1.CachePolicy.CacheOrNetwork + "\n\t" + types_1.CachePolicy.NetworkOnly + "\n}\n\n\"\"\"\n\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\tentities in mutations\n\"\"\"\ndirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\"\"\"\n\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\"\"\"\ndirective @" + config.listPrependDirective + "(\n\t" + config.listDirectiveParentIDArg + ": ID\n) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\"\"\"\ndirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\twhere it doesn't make sense (eg when deleting a node.)\n\"\"\"\ndirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.whenDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\"\"\"\ndirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.whenNotDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\"\"\"\ndirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\"\"\"\ndirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\"\"\"\n\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\"\"\"\ndirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy, " + config.cachePartialArg + ": Boolean) on QUERY\n";
67
+ config.newSchema += internalSchema;
65
68
  // add the static extra bits that will be used by other transforms
66
69
  config.schema = merge_1.mergeSchemas({
67
- schemas: [
68
- config.schema,
69
- graphql.buildSchema("\n\t\t\tenum CachePolicy {\n\t\t\t\t" + types_1.CachePolicy.CacheAndNetwork + "\n\t\t\t\t" + types_1.CachePolicy.CacheOnly + "\n\t\t\t\t" + types_1.CachePolicy.CacheOrNetwork + "\n\t\t\t\t" + types_1.CachePolicy.NetworkOnly + "\n\t\t\t}\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\t\t\t\tentities in mutations\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listPrependDirective + "(\n\t\t\t\t" + config.listDirectiveParentIDArg + ": ID\n\t\t\t) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\t\t\t\twhere it doesn't make sense (eg when deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.whenDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.whenNotDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy, " + config.cachePartialArg + ": Boolean) on QUERY\n\n\t\t"),
70
- ],
70
+ schemas: [config.schema, graphql.buildSchema(internalSchema)],
71
71
  });
72
72
  return [2 /*return*/];
73
73
  });
package/build/cmd.js CHANGED
@@ -665,9 +665,10 @@ var CachePolicy$1;
665
665
  // a place to hold conventions and magic strings
666
666
  var Config = /** @class */ (function () {
667
667
  function Config(_a) {
668
- var schema = _a.schema, schemaPath = _a.schemaPath, sourceGlob = _a.sourceGlob, apiUrl = _a.apiUrl, _b = _a.quiet, quiet = _b === void 0 ? false : _b, filepath = _a.filepath, _c = _a.framework, framework = _c === void 0 ? 'sapper' : _c, _d = _a.module, module = _d === void 0 ? 'commonjs' : _d, staticSite = _a.static, mode = _a.mode, scalars = _a.scalars, cacheBufferSize = _a.cacheBufferSize, _e = _a.defaultCachePolicy, defaultCachePolicy = _e === void 0 ? CachePolicy$1.NetworkOnly : _e, _f = _a.defaultPartial, defaultPartial = _f === void 0 ? false : _f;
668
+ var schema = _a.schema, schemaPath = _a.schemaPath, sourceGlob = _a.sourceGlob, apiUrl = _a.apiUrl, _b = _a.quiet, quiet = _b === void 0 ? false : _b, filepath = _a.filepath, _c = _a.framework, framework = _c === void 0 ? 'sapper' : _c, _d = _a.module, module = _d === void 0 ? 'commonjs' : _d, staticSite = _a.static, scalars = _a.scalars, cacheBufferSize = _a.cacheBufferSize, definitionsPath = _a.definitionsPath, _e = _a.defaultCachePolicy, defaultCachePolicy = _e === void 0 ? CachePolicy$1.NetworkOnly : _e, _f = _a.defaultPartial, defaultPartial = _f === void 0 ? false : _f;
669
669
  this.framework = 'sapper';
670
670
  this.module = 'commonjs';
671
+ this.newSchema = '';
671
672
  // make sure we got some kind of schema
672
673
  if (!schema && !schemaPath) {
673
674
  throw new Error('Please provide one of schema or schema path');
@@ -704,29 +705,6 @@ var Config = /** @class */ (function () {
704
705
  this.schema = graphql.buildClientSchema(JSON.parse(fs$2$1.readFileSync(localSchemaPath, 'utf-8')));
705
706
  }
706
707
  }
707
- // if we were given a mode instead of framework/module
708
- if (mode) {
709
- if (!quiet) {
710
- // warn the user
711
- console.warn('Encountered deprecated config value: mode');
712
- console.warn('This parameter will be removed in a future version. Please update your config with the ' +
713
- 'following values:');
714
- }
715
- if (mode === 'sapper') {
716
- if (!quiet) {
717
- console.warn(JSON.stringify({ framework: 'sapper', module: 'commonjs' }));
718
- }
719
- framework = 'sapper';
720
- module = 'commonjs';
721
- }
722
- else {
723
- if (!quiet) {
724
- console.warn(JSON.stringify({ framework: 'kit', module: 'esm' }));
725
- }
726
- framework = 'kit';
727
- module = 'esm';
728
- }
729
- }
730
708
  // save the values we were given
731
709
  this.schemaPath = schemaPath;
732
710
  this.apiUrl = apiUrl;
@@ -741,6 +719,7 @@ var Config = /** @class */ (function () {
741
719
  this.cacheBufferSize = cacheBufferSize;
742
720
  this.defaultCachePolicy = defaultCachePolicy;
743
721
  this.defaultPartial = defaultPartial;
722
+ this.definitionsFile = definitionsPath;
744
723
  // if we are building a sapper project, we want to put the runtime in
745
724
  // src/node_modules so that we can access @sapper/app and interact
746
725
  // with the application stores directly
@@ -785,6 +764,15 @@ var Config = /** @class */ (function () {
785
764
  enumerable: false,
786
765
  configurable: true
787
766
  });
767
+ Object.defineProperty(Config.prototype, "definitionsPath", {
768
+ get: function () {
769
+ return this.definitionsFile
770
+ ? path$6.join(this.projectRoot, this.definitionsFile)
771
+ : path$6.join(this.rootDir, 'definitions.gql');
772
+ },
773
+ enumerable: false,
774
+ configurable: true
775
+ });
788
776
  Object.defineProperty(Config.prototype, "typeIndexPath", {
789
777
  get: function () {
790
778
  return path$6.join(this.rootDir, 'index.d.ts');
@@ -54464,13 +54452,13 @@ function makeSchema({ resolvers, typeDefs, extensions, }, config) {
54464
54452
  // graphqlExtensions adds a few different things to the graphql schema
54465
54453
  function graphqlExtensions(config, documents) {
54466
54454
  return __awaiter$1(this, void 0, void 0, function () {
54455
+ var internalSchema;
54467
54456
  return __generator$1(this, function (_a) {
54457
+ internalSchema = "\nenum CachePolicy {\n\t" + CachePolicy.CacheAndNetwork + "\n\t" + CachePolicy.CacheOnly + "\n\t" + CachePolicy.CacheOrNetwork + "\n\t" + CachePolicy.NetworkOnly + "\n}\n\n\"\"\"\n\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\tentities in mutations\n\"\"\"\ndirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\"\"\"\n\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\"\"\"\ndirective @" + config.listPrependDirective + "(\n\t" + config.listDirectiveParentIDArg + ": ID\n) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\"\"\"\ndirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\twhere it doesn't make sense (eg when deleting a node.)\n\"\"\"\ndirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.whenDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\"\"\"\ndirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.whenNotDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\"\"\"\ndirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\"\"\"\n\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\"\"\"\ndirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\"\"\"\n\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\"\"\"\ndirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy, " + config.cachePartialArg + ": Boolean) on QUERY\n";
54458
+ config.newSchema += internalSchema;
54468
54459
  // add the static extra bits that will be used by other transforms
54469
54460
  config.schema = mergeSchemas({
54470
- schemas: [
54471
- config.schema,
54472
- graphql.buildSchema("\n\t\t\tenum CachePolicy {\n\t\t\t\t" + CachePolicy.CacheAndNetwork + "\n\t\t\t\t" + CachePolicy.CacheOnly + "\n\t\t\t\t" + CachePolicy.CacheOrNetwork + "\n\t\t\t\t" + CachePolicy.NetworkOnly + "\n\t\t\t}\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\t\t\t\tentities in mutations\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listPrependDirective + "(\n\t\t\t\t" + config.listDirectiveParentIDArg + ": ID\n\t\t\t) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\t\t\t\twhere it doesn't make sense (eg when deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.whenDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.whenNotDirective + " is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\t\t\t\"\"\"\n\t\t\t\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\t\t\t\"\"\"\n\t\t\tdirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy, " + config.cachePartialArg + ": Boolean) on QUERY\n\n\t\t"),
54473
- ],
54461
+ schemas: [config.schema, graphql.buildSchema(internalSchema)],
54474
54462
  });
54475
54463
  return [2 /*return*/];
54476
54464
  });
@@ -76289,8 +76277,8 @@ var pageInfoSelection = [
76289
76277
  function addListFragments(config, documents) {
76290
76278
  return __awaiter$1(this, void 0, void 0, function () {
76291
76279
  var lists, errors, _loop_1, documents_1, documents_1_1, doc, listTargets, generatedDoc;
76292
- var e_1, _a;
76293
- return __generator$1(this, function (_b) {
76280
+ var e_1, _a, _b;
76281
+ return __generator$1(this, function (_c) {
76294
76282
  lists = {};
76295
76283
  errors = [];
76296
76284
  _loop_1 = function (doc) {
@@ -76410,7 +76398,9 @@ function addListFragments(config, documents) {
76410
76398
  if (Object.keys(lists).length === 0) {
76411
76399
  return [2 /*return*/];
76412
76400
  }
76413
- generatedDoc = __assign$1({ kind: 'Document', definitions: Object.entries(lists).flatMap(function (_a) {
76401
+ generatedDoc = {
76402
+ kind: 'Document',
76403
+ definitions: (_b = Object.entries(lists).flatMap(function (_a) {
76414
76404
  var _b = __read$1(_a, 2), name = _b[0], _c = _b[1], selection = _c.selection, type = _c.type;
76415
76405
  // look up the type
76416
76406
  var schemaType = config.schema.getType(type.name);
@@ -76513,8 +76503,7 @@ function addListFragments(config, documents) {
76513
76503
  },
76514
76504
  },
76515
76505
  ];
76516
- }) }, listTargets.flatMap(function (typeName) { return [
76517
- {
76506
+ })).concat.apply(_b, __spread$1(listTargets.map(function (typeName) { return ({
76518
76507
  kind: 'DirectiveDefinition',
76519
76508
  name: {
76520
76509
  kind: 'Name',
@@ -76529,8 +76518,9 @@ function addListFragments(config, documents) {
76529
76518
  },
76530
76519
  ],
76531
76520
  repeatable: true,
76532
- },
76533
- ]; }));
76521
+ }); }))),
76522
+ };
76523
+ config.newSchema += '\n' + generatedDoc.definitions.map(graphql.print).join('\n');
76534
76524
  documents.push({
76535
76525
  name: 'generated::lists',
76536
76526
  kind: ArtifactKind.Fragment,
@@ -78528,11 +78518,12 @@ function typescriptGenerator(config, docs) {
78528
78518
  }
78529
78519
  function generateOperationTypeDefs(config, body, definition, selections, visitedTypes) {
78530
78520
  return __awaiter$1(this, void 0, void 0, function () {
78531
- var inputTypeName, shapeTypeName, type, hasInputs, _a, _b, variableDefinition;
78521
+ var inputTypeName, shapeTypeName, afterLoadTypeName, type, hasInputs, _a, _b, variableDefinition;
78532
78522
  var e_1, _c;
78533
78523
  return __generator$1(this, function (_d) {
78534
78524
  inputTypeName = definition.name.value + "$input";
78535
78525
  shapeTypeName = definition.name.value + "$result";
78526
+ afterLoadTypeName = definition.name.value + "$afterLoad";
78536
78527
  if (definition.operation === 'query') {
78537
78528
  type = config.schema.getQueryType();
78538
78529
  }
@@ -78568,6 +78559,12 @@ function generateOperationTypeDefs(config, body, definition, selections, visited
78568
78559
  visitedTypes: visitedTypes,
78569
78560
  body: body,
78570
78561
  }))));
78562
+ // generate type for the afterload function
78563
+ body.push(AST.exportNamedDeclaration(AST.tsTypeAliasDeclaration(AST.identifier(afterLoadTypeName), AST.tsTypeLiteral([
78564
+ readonlyProperty(AST.tsPropertySignature(AST.stringLiteral('data'), AST.tsTypeAnnotation(AST.tsTypeLiteral([
78565
+ readonlyProperty(AST.tsPropertySignature(AST.stringLiteral(definition.name.value), AST.tsTypeAnnotation(AST.tsTypeReference(AST.identifier(shapeTypeName))))),
78566
+ ])))),
78567
+ ]))));
78571
78568
  // if there are variables in this query
78572
78569
  if (hasInputs && definition.variableDefinitions && definition.variableDefinitions.length > 0) {
78573
78570
  try {
@@ -78699,6 +78696,27 @@ function persistOutputGenerator(config, docs) {
78699
78696
  });
78700
78697
  }
78701
78698
 
78699
+ // schemaGenerator updates the schema file to contain all of the generated
78700
+ // definitions
78701
+ function schemaGenerator(config, docs) {
78702
+ return __awaiter$1(this, void 0, void 0, function () {
78703
+ return __generator$1(this, function (_a) {
78704
+ switch (_a.label) {
78705
+ case 0:
78706
+ if (!config.newSchema) {
78707
+ return [2 /*return*/];
78708
+ }
78709
+ // print the updated version of the schema over the existing one
78710
+ return [4 /*yield*/, fs$7.writeFile(config.definitionsPath, config.newSchema, 'utf-8')];
78711
+ case 1:
78712
+ // print the updated version of the schema over the existing one
78713
+ _a.sent();
78714
+ return [2 /*return*/];
78715
+ }
78716
+ });
78717
+ });
78718
+ }
78719
+
78702
78720
  // typeCheck verifies that the documents are valid instead of waiting
78703
78721
  // for the compiler to fail later down the line.
78704
78722
  function typeCheck(config, docs) {
@@ -79493,10 +79511,14 @@ var runPipeline = function (config, docs) { return __awaiter$1(void 0, void 0, v
79493
79511
  switch (_a.label) {
79494
79512
  case 0:
79495
79513
  // we need to create the runtime folder structure
79496
- return [4 /*yield*/, config.createDirectories()];
79514
+ return [4 /*yield*/, config.createDirectories()
79515
+ // reset the newSchema accumulator
79516
+ ];
79497
79517
  case 1:
79498
79518
  // we need to create the runtime folder structure
79499
79519
  _a.sent();
79520
+ // reset the newSchema accumulator
79521
+ config.newSchema = '';
79500
79522
  return [4 /*yield*/, runPipeline$1(config, [
79501
79523
  typeCheck,
79502
79524
  uniqueDocumentNames,
@@ -79516,6 +79538,7 @@ var runPipeline = function (config, docs) { return __awaiter$1(void 0, void 0, v
79516
79538
  runtimeGenerator,
79517
79539
  typescriptGenerator,
79518
79540
  persistOutputGenerator,
79541
+ schemaGenerator,
79519
79542
  ], docs)];
79520
79543
  case 2:
79521
79544
  _a.sent();
@@ -75,6 +75,11 @@ export declare type FetchQueryResult<_Data> = {
75
75
  source: DataSource | null;
76
76
  partial: boolean;
77
77
  };
78
+ export declare type QueryInputs<_Data> = FetchQueryResult<_Data> & {
79
+ variables: {
80
+ [key: string]: any;
81
+ };
82
+ };
78
83
  export declare function fetchQuery<_Data extends GraphQLObject>({ context, artifact, variables, session, cached, }: {
79
84
  context: FetchContext;
80
85
  artifact: QueryArtifact | MutationArtifact;
@@ -93,14 +98,14 @@ export declare class RequestContext {
93
98
  graphqlErrors(payload: {
94
99
  errors?: GraphQLError[];
95
100
  }): any;
96
- invokeLoadHook({ variant, mode, hookFn, data, }: {
101
+ invokeLoadHook({ variant, framework, hookFn, data, }: {
97
102
  variant: 'before' | 'after';
98
- mode: 'kit' | 'sapper';
103
+ framework: 'kit' | 'sapper';
99
104
  hookFn: KitBeforeLoad | KitAfterLoad | SapperBeforeLoad | SapperAfterLoad;
100
105
  data: Record<string, any>;
101
106
  }): Promise<void>;
102
- computeInput({ config, mode, variableFunction, artifact, }: {
103
- mode: 'kit' | 'sapper';
107
+ computeInput({ config, framework, variableFunction, artifact, }: {
108
+ framework: 'kit' | 'sapper';
104
109
  variableFunction: SapperBeforeLoad | KitBeforeLoad;
105
110
  artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact;
106
111
  config: Config;
@@ -265,13 +265,13 @@ var RequestContext = /** @class */ (function () {
265
265
  // This hook fires before executing any queries, it allows to redirect/error based on session state for example
266
266
  // It also allows to return custom props that should be returned from the corresponding load function.
267
267
  RequestContext.prototype.invokeLoadHook = function (_a) {
268
- var variant = _a.variant, mode = _a.mode, hookFn = _a.hookFn, data = _a.data;
268
+ var variant = _a.variant, framework = _a.framework, hookFn = _a.hookFn, data = _a.data;
269
269
  return __awaiter(this, void 0, void 0, function () {
270
270
  var hookCall, result;
271
271
  return __generator(this, function (_b) {
272
272
  switch (_b.label) {
273
273
  case 0:
274
- if (mode === 'kit') {
274
+ if (framework === 'kit') {
275
275
  if (variant === 'before') {
276
276
  hookCall = hookFn.call(this, this.context);
277
277
  }
@@ -311,9 +311,9 @@ var RequestContext = /** @class */ (function () {
311
311
  // in sapper, this means preparing a `this` for the function. for kit, we can just pass
312
312
  // the context
313
313
  RequestContext.prototype.computeInput = function (_a) {
314
- var config = _a.config, mode = _a.mode, variableFunction = _a.variableFunction, artifact = _a.artifact;
314
+ var config = _a.config, framework = _a.framework, variableFunction = _a.variableFunction, artifact = _a.artifact;
315
315
  // call the variable function to match the framework
316
- var input = mode === 'kit'
316
+ var input = framework === 'kit'
317
317
  ? // in kit just pass the context directly
318
318
  variableFunction.call(this, this.context)
319
319
  : // we are in sapper mode, so we need to prepare the function context
@@ -105,13 +105,16 @@ function paginatedQuery(document) {
105
105
  throw new Error('paginatedQuery must be passed a query with @paginate.');
106
106
  }
107
107
  // pass the artifact to the base query operation
108
- var _a = query_1.query(document), data = _a.data, loading = _a.loading, refetch = _a.refetch, partial = _a.partial, restOfQueryResponse = __rest(_a, ["data", "loading", "refetch", "partial"]);
108
+ var _a = query_1.query(document), data = _a.data, loading = _a.loading, refetch = _a.refetch, partial = _a.partial, onLoad = _a.onLoad, restOfQueryResponse = __rest(_a, ["data", "loading", "refetch", "partial", "onLoad"]);
109
109
  var paginationPartial = store_1.writable(false);
110
- var partialStore = store_1.derived([partial, paginationPartial], function (_a) {
111
- var _b = __read(_a, 2), $partial = _b[0], $paginationPartial = _b[1];
112
- return $partial || $paginationPartial;
110
+ partial.subscribe(function (val) {
111
+ paginationPartial.set(val);
113
112
  });
114
- return __assign(__assign({ data: data, partial: partialStore }, paginationHandlers({
113
+ return __assign(__assign({ data: data, partial: { subscribe: paginationPartial.subscribe }, onLoad: function (newValue) {
114
+ onLoad.call(this, newValue);
115
+ // keep the partial store in sync
116
+ paginationPartial.set(newValue.partial);
117
+ } }, paginationHandlers({
115
118
  initialValue: document.initialValue.data,
116
119
  store: data,
117
120
  artifact: artifact,
@@ -216,19 +219,18 @@ function paginationHandlers(_a) {
216
219
  }
217
220
  function cursorHandlers(_a) {
218
221
  var _this = this;
222
+ var _b;
219
223
  var initialValue = _a.initialValue, artifact = _a.artifact, store = _a.store, extraVariables = _a.queryVariables, loading = _a.loading, refetch = _a.refetch, partial = _a.partial;
220
224
  // pull out the context accessors
221
225
  var variables = context_1.getVariables();
222
226
  var sessionStore = adapter_mjs_1.getSession();
223
227
  // track the current page info in an easy-to-reach store
224
- var initialPageInfo = initialValue
225
- ? utils_1.extractPageInfo(initialValue, artifact.refetch.path)
226
- : {
227
- startCursor: null,
228
- endCursor: null,
229
- hasNextPage: false,
230
- hasPreviousPage: false,
231
- };
228
+ var initialPageInfo = (_b = utils_1.extractPageInfo(initialValue, artifact.refetch.path)) !== null && _b !== void 0 ? _b : {
229
+ startCursor: null,
230
+ endCursor: null,
231
+ hasNextPage: false,
232
+ hasPreviousPage: false,
233
+ };
232
234
  var pageInfo = store_1.writable(initialPageInfo);
233
235
  // hold onto the current value
234
236
  var value = initialValue;
@@ -347,7 +349,8 @@ function cursorHandlers(_a) {
347
349
  if (input && JSON.stringify(variables()) !== JSON.stringify(input)) {
348
350
  return [2 /*return*/, refetch(input)];
349
351
  }
350
- count = utils_1.countPage(artifact.refetch.path.concat('edges'), value);
352
+ count = utils_1.countPage(artifact.refetch.path.concat('edges'), value) ||
353
+ artifact.refetch.pageSize;
351
354
  queryVariables = __assign(__assign(__assign({}, variables()), extraVariables), (_b = {}, _b[artifact.refetch.update === 'prepend' ? 'last' : 'first'] = count, _b));
352
355
  // set the loading state to true
353
356
  loading.set(true);
@@ -188,6 +188,8 @@ function query(document) {
188
188
  onLoad: function (newValue) {
189
189
  // we got new data from mounting, write it
190
190
  writeData(newValue.result, newValue.variables);
191
+ // keep the partial store in sync
192
+ partial.set(newValue.partial);
191
193
  // if we are mounting on a browser we might need to perform an additional network request
192
194
  if (adapter_mjs_1.isBrowser) {
193
195
  // if the data was loaded from a cached value, and the document cache policy wants a
@@ -33,13 +33,30 @@ var __values = (this && this.__values) || function(o) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.countPage = exports.extractPageInfo = void 0;
35
35
  function extractPageInfo(data, path) {
36
+ var _a;
37
+ if (data === null) {
38
+ return {
39
+ startCursor: null,
40
+ endCursor: null,
41
+ hasNextPage: false,
42
+ hasPreviousPage: false,
43
+ };
44
+ }
36
45
  var localPath = __spread(path);
37
46
  // walk down the object until we get to the end
38
47
  var current = data;
39
48
  while (localPath.length > 0) {
49
+ if (current === null) {
50
+ break;
51
+ }
40
52
  current = current[localPath.shift()];
41
53
  }
42
- return current.pageInfo;
54
+ return ((_a = current === null || current === void 0 ? void 0 : current.pageInfo) !== null && _a !== void 0 ? _a : {
55
+ startCursor: null,
56
+ endCursor: null,
57
+ hasNextPage: false,
58
+ hasPreviousPage: false,
59
+ });
43
60
  }
44
61
  exports.extractPageInfo = extractPageInfo;
45
62
  function countPage(source, value) {
@@ -75,6 +75,11 @@ export declare type FetchQueryResult<_Data> = {
75
75
  source: DataSource | null;
76
76
  partial: boolean;
77
77
  };
78
+ export declare type QueryInputs<_Data> = FetchQueryResult<_Data> & {
79
+ variables: {
80
+ [key: string]: any;
81
+ };
82
+ };
78
83
  export declare function fetchQuery<_Data extends GraphQLObject>({ context, artifact, variables, session, cached, }: {
79
84
  context: FetchContext;
80
85
  artifact: QueryArtifact | MutationArtifact;
@@ -93,14 +98,14 @@ export declare class RequestContext {
93
98
  graphqlErrors(payload: {
94
99
  errors?: GraphQLError[];
95
100
  }): any;
96
- invokeLoadHook({ variant, mode, hookFn, data, }: {
101
+ invokeLoadHook({ variant, framework, hookFn, data, }: {
97
102
  variant: 'before' | 'after';
98
- mode: 'kit' | 'sapper';
103
+ framework: 'kit' | 'sapper';
99
104
  hookFn: KitBeforeLoad | KitAfterLoad | SapperBeforeLoad | SapperAfterLoad;
100
105
  data: Record<string, any>;
101
106
  }): Promise<void>;
102
- computeInput({ config, mode, variableFunction, artifact, }: {
103
- mode: 'kit' | 'sapper';
107
+ computeInput({ config, framework, variableFunction, artifact, }: {
108
+ framework: 'kit' | 'sapper';
104
109
  variableFunction: SapperBeforeLoad | KitBeforeLoad;
105
110
  artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact;
106
111
  config: Config;