houdini 0.13.3-alpha.0 → 0.13.3

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 (80) hide show
  1. package/build/cmd/generate.js +6 -1
  2. package/build/cmd/generators/artifacts/index.js +2 -14
  3. package/build/cmd/generators/artifacts/selection.js +1 -7
  4. package/build/cmd/generators/index.d.ts +1 -0
  5. package/build/cmd/generators/index.js +2 -0
  6. package/build/cmd/generators/schema/index.d.ts +3 -0
  7. package/build/cmd/generators/schema/index.js +63 -0
  8. package/build/cmd/generators/typescript/addReferencedInputTypes.js +1 -2
  9. package/build/cmd/generators/typescript/index.js +9 -2
  10. package/build/cmd/transforms/list.js +9 -7
  11. package/build/cmd/transforms/schema.js +4 -4
  12. package/build/cmd.js +65 -69
  13. package/build/runtime/cache/cache.d.ts +4 -14
  14. package/build/runtime/cache/cache.js +160 -209
  15. package/build/runtime/cache/lists.js +12 -1
  16. package/build/runtime/mutation.js +3 -1
  17. package/build/runtime/network.d.ts +6 -14
  18. package/build/runtime/network.js +61 -48
  19. package/build/runtime/pagination.js +36 -41
  20. package/build/runtime/query.d.ts +1 -5
  21. package/build/runtime/query.js +26 -39
  22. package/build/runtime/types.d.ts +0 -3
  23. package/build/runtime-cjs/cache/cache.d.ts +4 -14
  24. package/build/runtime-cjs/cache/cache.js +160 -209
  25. package/build/runtime-cjs/cache/lists.js +12 -1
  26. package/build/runtime-cjs/mutation.js +3 -1
  27. package/build/runtime-cjs/network.d.ts +6 -14
  28. package/build/runtime-cjs/network.js +61 -48
  29. package/build/runtime-cjs/pagination.js +36 -41
  30. package/build/runtime-cjs/query.d.ts +1 -5
  31. package/build/runtime-cjs/query.js +26 -39
  32. package/build/runtime-cjs/types.d.ts +0 -3
  33. package/build/runtime-esm/cache/cache.d.ts +4 -14
  34. package/build/runtime-esm/cache/cache.js +88 -139
  35. package/build/runtime-esm/cache/lists.js +12 -1
  36. package/build/runtime-esm/mutation.js +3 -1
  37. package/build/runtime-esm/network.d.ts +6 -14
  38. package/build/runtime-esm/network.js +39 -45
  39. package/build/runtime-esm/pagination.js +8 -20
  40. package/build/runtime-esm/query.d.ts +1 -5
  41. package/build/runtime-esm/query.js +14 -26
  42. package/build/runtime-esm/types.d.ts +0 -3
  43. package/cmd/generate.ts +4 -0
  44. package/cmd/generators/artifacts/artifacts.test.ts +18 -34
  45. package/cmd/generators/artifacts/index.ts +4 -20
  46. package/cmd/generators/artifacts/indexFile.test.ts +3 -3
  47. package/cmd/generators/artifacts/pagination.test.ts +0 -5
  48. package/cmd/generators/artifacts/policy.test.ts +2 -145
  49. package/cmd/generators/artifacts/selection.ts +1 -8
  50. package/cmd/generators/index.ts +1 -0
  51. package/cmd/generators/runtime/copyRuntime.test.ts +2 -2
  52. package/cmd/generators/runtime/indexFile.test.ts +3 -3
  53. package/cmd/generators/schema/index.ts +19 -0
  54. package/cmd/generators/schema/schema.test.ts +186 -0
  55. package/cmd/generators/typescript/addReferencedInputTypes.ts +1 -4
  56. package/cmd/generators/typescript/index.ts +32 -5
  57. package/cmd/generators/typescript/typescript.test.ts +103 -19
  58. package/cmd/transforms/fragmentVariables.test.ts +8 -16
  59. package/cmd/transforms/list.ts +8 -7
  60. package/cmd/transforms/paginate.test.ts +2 -7
  61. package/cmd/transforms/schema.ts +51 -49
  62. package/package.json +3 -3
  63. package/runtime/cache/cache.ts +103 -170
  64. package/runtime/cache/lists.ts +14 -1
  65. package/runtime/cache/tests/availability.test.ts +29 -84
  66. package/runtime/cache/tests/gc.test.ts +10 -15
  67. package/runtime/cache/tests/list.test.ts +12 -12
  68. package/runtime/cache/tests/scalars.test.ts +5 -5
  69. package/runtime/cache/tests/subscriptions.test.ts +745 -235
  70. package/runtime/mutation.ts +3 -1
  71. package/runtime/network.ts +44 -59
  72. package/runtime/pagination.ts +5 -30
  73. package/runtime/query.ts +23 -43
  74. package/runtime/scalars.test.ts +10 -10
  75. package/runtime/types.ts +0 -3
  76. package/build/runtime-esm/cache/list.d.ts +0 -35
  77. package/build/runtime-esm/cache/list.js +0 -203
  78. package/build/runtime-esm/cache/record.d.ts +0 -40
  79. package/build/runtime-esm/cache/record.js +0 -195
  80. package/runtime/cache/tests/readwrite.test.ts +0 -1124
@@ -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();
@@ -185,7 +185,7 @@ function artifactGenerator(config, docs) {
185
185
  ].concat(
186
186
  // and an artifact for every document
187
187
  docs.map(function (doc) { return __awaiter(_this, void 0, void 0, function () {
188
- var document, name, generate, rawString, docKind, operations, fragments, rootType, selectionSet, operation, matchingFragment, inputs, artifact, cacheDirective, args, policy, partial, file;
188
+ var document, name, generate, rawString, docKind, operations, fragments, rootType, selectionSet, operation, matchingFragment, inputs, artifact, cacheDirective, policy, file;
189
189
  var _a, _b, _c, _d, _e, _f;
190
190
  return __generator(this, function (_g) {
191
191
  switch (_g.label) {
@@ -271,28 +271,16 @@ function artifactGenerator(config, docs) {
271
271
  if (docKind === 'HoudiniQuery') {
272
272
  cacheDirective = (_e = operations[0].directives) === null || _e === void 0 ? void 0 : _e.find(function (directive) { return directive.name.value === config.cacheDirective; });
273
273
  if (cacheDirective) {
274
- args = ((_f = cacheDirective.arguments) === null || _f === void 0 ? void 0 : _f.reduce(function (acc, arg) {
275
- var _a;
276
- return (__assign(__assign({}, acc), (_a = {}, _a[arg.name.value] = arg, _a)));
277
- }, {})) || {};
278
- policy = args[config.cachePolicyArg];
274
+ policy = (_f = cacheDirective.arguments) === null || _f === void 0 ? void 0 : _f.find(function (arg) { return arg.name.value === config.cachePolicyArg; });
279
275
  if (policy && policy.value.kind === 'EnumValue') {
280
276
  artifact.policy = policy.value.value;
281
277
  }
282
278
  else {
283
279
  artifact.policy = config.defaultCachePolicy;
284
280
  }
285
- partial = args[config.cachePartialArg];
286
- if (partial && partial.value.kind === 'BooleanValue') {
287
- artifact.partial = partial.value.value;
288
- }
289
- else {
290
- artifact.partial = config.defaultPartial;
291
- }
292
281
  }
293
282
  else {
294
283
  artifact.policy = config.defaultCachePolicy;
295
- artifact.partial = config.defaultPartial;
296
284
  }
297
285
  }
298
286
  file = AST.program([
@@ -100,14 +100,11 @@ function selection(_a) {
100
100
  var attributeName = ((_d = field.alias) === null || _d === void 0 ? void 0 : _d.value) || field.name.value;
101
101
  // if we are looking at __typename, its a string (not defined in the schema)
102
102
  var fieldType = void 0;
103
- var nullable = false;
104
103
  if (field.name.value === '__typename') {
105
104
  fieldType = config.schema.getType('String');
106
105
  }
107
106
  else {
108
- var typeRef = type.getFields()[field.name.value].type;
109
- fieldType = houdini_common_1.getRootType(typeRef);
110
- nullable = !graphql.isNonNullType(typeRef);
107
+ fieldType = houdini_common_1.getRootType(type.getFields()[field.name.value].type);
111
108
  }
112
109
  var typeName = fieldType.toString();
113
110
  // make sure we include the attribute in the path
@@ -117,9 +114,6 @@ function selection(_a) {
117
114
  type: typeName,
118
115
  keyRaw: fieldKey_1.default(config, field),
119
116
  };
120
- if (nullable) {
121
- fieldObj.nullable = true;
122
- }
123
117
  // is there an operation for this field
124
118
  var operationKey = pathSoFar.join(',');
125
119
  if (operations[operationKey]) {
@@ -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;
@@ -74,8 +74,7 @@ function addReferencedInputTypes(config, body, visitedTypes, rootType) {
74
74
  var field = _c.value;
75
75
  // walk down the referenced fields and build stuff back up
76
76
  addReferencedInputTypes(config, body, visitedTypes, field.type);
77
- // check if the type is optional so we can label the value as omitable
78
- members.push(AST.tsPropertySignature(AST.identifier(field.name), AST.tsTypeAnnotation(typeReference_1.tsTypeReference(config, field)), graphql.isNullableType(field.type)));
77
+ members.push(AST.tsPropertySignature(AST.identifier(field.name), AST.tsTypeAnnotation(typeReference_1.tsTypeReference(config, field))));
79
78
  }
80
79
  }
81
80
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -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 {
@@ -224,7 +231,7 @@ function generateOperationTypeDefs(config, body, definition, selections, visited
224
231
  // merge all of the variables into a single object
225
232
  body.push(AST.exportNamedDeclaration(AST.tsTypeAliasDeclaration(AST.identifier(inputTypeName), AST.tsTypeLiteral((definition.variableDefinitions || []).map(function (definition) {
226
233
  // add a property describing the variable to the root object
227
- return AST.tsPropertySignature(AST.identifier(definition.variable.name.value), AST.tsTypeAnnotation(typeReference_1.tsTypeReference(config, definition)), definition.type.kind !== 'NonNullType');
234
+ return AST.tsPropertySignature(AST.identifier(definition.variable.name.value), AST.tsTypeAnnotation(typeReference_1.tsTypeReference(config, definition)));
228
235
  })))));
229
236
  }
230
237
  return [2 /*return*/];
@@ -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 = "\n\tenum CachePolicy {\n\t\t" + types_1.CachePolicy.CacheAndNetwork + "\n\t\t" + types_1.CachePolicy.CacheOnly + "\n\t\t" + types_1.CachePolicy.CacheOrNetwork + "\n\t\t" + types_1.CachePolicy.NetworkOnly + "\n\t}\n\n\t\"\"\"\n\t\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\t\tentities in mutations\n\t\"\"\"\n\tdirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\t\"\"\"\n\t\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\t\"\"\"\n\tdirective @" + config.listPrependDirective + "(\n\t\t" + config.listDirectiveParentIDArg + ": ID\n\t) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\t\"\"\"\n\tdirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\t\twhere it doesn't make sense (eg when deleting a node.)\n\t\"\"\"\n\tdirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\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\"\"\"\n\tdirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\t\"\"\"\n\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\"\"\"\n\tdirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\t\"\"\"\n\tdirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\t\"\"\"\n\t\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\t\"\"\"\n\tdirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy) 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;
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;
@@ -740,7 +718,7 @@ var Config = /** @class */ (function () {
740
718
  this.scalars = scalars;
741
719
  this.cacheBufferSize = cacheBufferSize;
742
720
  this.defaultCachePolicy = defaultCachePolicy;
743
- this.defaultPartial = defaultPartial;
721
+ this.definitionsFile = definitionsPath;
744
722
  // if we are building a sapper project, we want to put the runtime in
745
723
  // src/node_modules so that we can access @sapper/app and interact
746
724
  // with the application stores directly
@@ -785,6 +763,15 @@ var Config = /** @class */ (function () {
785
763
  enumerable: false,
786
764
  configurable: true
787
765
  });
766
+ Object.defineProperty(Config.prototype, "definitionsPath", {
767
+ get: function () {
768
+ return this.definitionsFile
769
+ ? path$6.join(this.projectRoot, this.definitionsFile)
770
+ : path$6.join(this.rootDir, 'definitions.gql');
771
+ },
772
+ enumerable: false,
773
+ configurable: true
774
+ });
788
775
  Object.defineProperty(Config.prototype, "typeIndexPath", {
789
776
  get: function () {
790
777
  return path$6.join(this.rootDir, 'index.d.ts');
@@ -971,13 +958,6 @@ var Config = /** @class */ (function () {
971
958
  enumerable: false,
972
959
  configurable: true
973
960
  });
974
- Object.defineProperty(Config.prototype, "cachePartialArg", {
975
- get: function () {
976
- return 'partial';
977
- },
978
- enumerable: false,
979
- configurable: true
980
- });
981
961
  Object.defineProperty(Config.prototype, "cachePolicyArg", {
982
962
  get: function () {
983
963
  return 'policy';
@@ -54464,13 +54444,13 @@ function makeSchema({ resolvers, typeDefs, extensions, }, config) {
54464
54444
  // graphqlExtensions adds a few different things to the graphql schema
54465
54445
  function graphqlExtensions(config, documents) {
54466
54446
  return __awaiter$1(this, void 0, void 0, function () {
54447
+ var internalSchema;
54467
54448
  return __generator$1(this, function (_a) {
54449
+ internalSchema = "\n\tenum CachePolicy {\n\t\t" + CachePolicy.CacheAndNetwork + "\n\t\t" + CachePolicy.CacheOnly + "\n\t\t" + CachePolicy.CacheOrNetwork + "\n\t\t" + CachePolicy.NetworkOnly + "\n\t}\n\n\t\"\"\"\n\t\t@" + config.listDirective + " is used to mark a field for the runtime as a place to add or remove\n\t\tentities in mutations\n\t\"\"\"\n\tdirective @" + config.listDirective + "(" + config.listNameArg + ": String!, connection: Boolean) on FIELD\n\n\t\"\"\"\n\t\t@" + config.listPrependDirective + " is used to tell the runtime to add the result to the end of the list\n\t\"\"\"\n\tdirective @" + config.listPrependDirective + "(\n\t\t" + config.listDirectiveParentIDArg + ": ID\n\t) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.listAppendDirective + " is used to tell the runtime to add the result to the start of the list\n\t\"\"\"\n\tdirective @" + config.listAppendDirective + "(" + config.listDirectiveParentIDArg + ": ID) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.listParentDirective + " is used to provide a parentID without specifying position or in situations\n\t\twhere it doesn't make sense (eg when deleting a node.)\n\t\"\"\"\n\tdirective @" + config.listParentDirective + "(value: ID!) on FRAGMENT_SPREAD\n\n\t\"\"\"\n\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\"\"\"\n\tdirective @" + config.whenDirective + " on FRAGMENT_SPREAD\n\n\t\"\"\"\n\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\"\"\"\n\tdirective @" + config.whenNotDirective + " on FRAGMENT_SPREAD\n\n\t\"\"\"\n\t\t@" + config.argumentsDirective + " is used to define the arguments of a fragment\n\t\"\"\"\n\tdirective @" + config.argumentsDirective + " on FRAGMENT_DEFINITION\n\n\t\"\"\"\n\t\t@" + config.cacheDirective + " is used to specify cache rules for a query\n\t\"\"\"\n\tdirective @" + config.cacheDirective + "(" + config.cachePolicyArg + ": CachePolicy) on QUERY\n";
54450
+ config.newSchema += internalSchema;
54468
54451
  // add the static extra bits that will be used by other transforms
54469
54452
  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
- ],
54453
+ schemas: [config.schema, graphql.buildSchema(internalSchema)],
54474
54454
  });
54475
54455
  return [2 /*return*/];
54476
54456
  });
@@ -76289,8 +76269,8 @@ var pageInfoSelection = [
76289
76269
  function addListFragments(config, documents) {
76290
76270
  return __awaiter$1(this, void 0, void 0, function () {
76291
76271
  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) {
76272
+ var e_1, _a, _b;
76273
+ return __generator$1(this, function (_c) {
76294
76274
  lists = {};
76295
76275
  errors = [];
76296
76276
  _loop_1 = function (doc) {
@@ -76410,7 +76390,9 @@ function addListFragments(config, documents) {
76410
76390
  if (Object.keys(lists).length === 0) {
76411
76391
  return [2 /*return*/];
76412
76392
  }
76413
- generatedDoc = __assign$1({ kind: 'Document', definitions: Object.entries(lists).flatMap(function (_a) {
76393
+ generatedDoc = {
76394
+ kind: 'Document',
76395
+ definitions: (_b = Object.entries(lists).flatMap(function (_a) {
76414
76396
  var _b = __read$1(_a, 2), name = _b[0], _c = _b[1], selection = _c.selection, type = _c.type;
76415
76397
  // look up the type
76416
76398
  var schemaType = config.schema.getType(type.name);
@@ -76513,8 +76495,7 @@ function addListFragments(config, documents) {
76513
76495
  },
76514
76496
  },
76515
76497
  ];
76516
- }) }, listTargets.flatMap(function (typeName) { return [
76517
- {
76498
+ })).concat.apply(_b, __spread$1(listTargets.map(function (typeName) { return ({
76518
76499
  kind: 'DirectiveDefinition',
76519
76500
  name: {
76520
76501
  kind: 'Name',
@@ -76529,8 +76510,9 @@ function addListFragments(config, documents) {
76529
76510
  },
76530
76511
  ],
76531
76512
  repeatable: true,
76532
- },
76533
- ]; }));
76513
+ }); }))),
76514
+ };
76515
+ config.newSchema += '\n' + generatedDoc.definitions.map(graphql.print).join('\n');
76534
76516
  documents.push({
76535
76517
  name: 'generated::lists',
76536
76518
  kind: ArtifactKind.Fragment,
@@ -77238,14 +77220,11 @@ function selection(_a) {
77238
77220
  var attributeName = ((_d = field.alias) === null || _d === void 0 ? void 0 : _d.value) || field.name.value;
77239
77221
  // if we are looking at __typename, its a string (not defined in the schema)
77240
77222
  var fieldType = void 0;
77241
- var nullable = false;
77242
77223
  if (field.name.value === '__typename') {
77243
77224
  fieldType = config.schema.getType('String');
77244
77225
  }
77245
77226
  else {
77246
- var typeRef = type.getFields()[field.name.value].type;
77247
- fieldType = getRootType(typeRef);
77248
- nullable = !graphql.isNonNullType(typeRef);
77227
+ fieldType = getRootType(type.getFields()[field.name.value].type);
77249
77228
  }
77250
77229
  var typeName = fieldType.toString();
77251
77230
  // make sure we include the attribute in the path
@@ -77255,9 +77234,6 @@ function selection(_a) {
77255
77234
  type: typeName,
77256
77235
  keyRaw: fieldKey(config, field),
77257
77236
  };
77258
- if (nullable) {
77259
- fieldObj.nullable = true;
77260
- }
77261
77237
  // is there an operation for this field
77262
77238
  var operationKey = pathSoFar.join(',');
77263
77239
  if (operations[operationKey]) {
@@ -77719,7 +77695,7 @@ function artifactGenerator(config, docs) {
77719
77695
  ].concat(
77720
77696
  // and an artifact for every document
77721
77697
  docs.map(function (doc) { return __awaiter$1(_this, void 0, void 0, function () {
77722
- var document, name, generate, rawString, docKind, operations, fragments, rootType, selectionSet, operation, matchingFragment, inputs, artifact, cacheDirective, args, policy, partial, file;
77698
+ var document, name, generate, rawString, docKind, operations, fragments, rootType, selectionSet, operation, matchingFragment, inputs, artifact, cacheDirective, policy, file;
77723
77699
  var _a, _b, _c, _d, _e, _f;
77724
77700
  return __generator$1(this, function (_g) {
77725
77701
  switch (_g.label) {
@@ -77805,28 +77781,16 @@ function artifactGenerator(config, docs) {
77805
77781
  if (docKind === 'HoudiniQuery') {
77806
77782
  cacheDirective = (_e = operations[0].directives) === null || _e === void 0 ? void 0 : _e.find(function (directive) { return directive.name.value === config.cacheDirective; });
77807
77783
  if (cacheDirective) {
77808
- args = ((_f = cacheDirective.arguments) === null || _f === void 0 ? void 0 : _f.reduce(function (acc, arg) {
77809
- var _a;
77810
- return (__assign$1(__assign$1({}, acc), (_a = {}, _a[arg.name.value] = arg, _a)));
77811
- }, {})) || {};
77812
- policy = args[config.cachePolicyArg];
77784
+ policy = (_f = cacheDirective.arguments) === null || _f === void 0 ? void 0 : _f.find(function (arg) { return arg.name.value === config.cachePolicyArg; });
77813
77785
  if (policy && policy.value.kind === 'EnumValue') {
77814
77786
  artifact.policy = policy.value.value;
77815
77787
  }
77816
77788
  else {
77817
77789
  artifact.policy = config.defaultCachePolicy;
77818
77790
  }
77819
- partial = args[config.cachePartialArg];
77820
- if (partial && partial.value.kind === 'BooleanValue') {
77821
- artifact.partial = partial.value.value;
77822
- }
77823
- else {
77824
- artifact.partial = config.defaultPartial;
77825
- }
77826
77791
  }
77827
77792
  else {
77828
77793
  artifact.policy = config.defaultCachePolicy;
77829
- artifact.partial = config.defaultPartial;
77830
77794
  }
77831
77795
  }
77832
77796
  file = AST$5.program([
@@ -78183,8 +78147,7 @@ function addReferencedInputTypes(config, body, visitedTypes, rootType) {
78183
78147
  var field = _c.value;
78184
78148
  // walk down the referenced fields and build stuff back up
78185
78149
  addReferencedInputTypes(config, body, visitedTypes, field.type);
78186
- // check if the type is optional so we can label the value as omitable
78187
- members.push(AST$2.tsPropertySignature(AST$2.identifier(field.name), AST$2.tsTypeAnnotation(tsTypeReference(config, field)), graphql.isNullableType(field.type)));
78150
+ members.push(AST$2.tsPropertySignature(AST$2.identifier(field.name), AST$2.tsTypeAnnotation(tsTypeReference(config, field))));
78188
78151
  }
78189
78152
  }
78190
78153
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -78528,11 +78491,12 @@ function typescriptGenerator(config, docs) {
78528
78491
  }
78529
78492
  function generateOperationTypeDefs(config, body, definition, selections, visitedTypes) {
78530
78493
  return __awaiter$1(this, void 0, void 0, function () {
78531
- var inputTypeName, shapeTypeName, type, hasInputs, _a, _b, variableDefinition;
78494
+ var inputTypeName, shapeTypeName, afterLoadTypeName, type, hasInputs, _a, _b, variableDefinition;
78532
78495
  var e_1, _c;
78533
78496
  return __generator$1(this, function (_d) {
78534
78497
  inputTypeName = definition.name.value + "$input";
78535
78498
  shapeTypeName = definition.name.value + "$result";
78499
+ afterLoadTypeName = definition.name.value + "$afterLoad";
78536
78500
  if (definition.operation === 'query') {
78537
78501
  type = config.schema.getQueryType();
78538
78502
  }
@@ -78568,6 +78532,12 @@ function generateOperationTypeDefs(config, body, definition, selections, visited
78568
78532
  visitedTypes: visitedTypes,
78569
78533
  body: body,
78570
78534
  }))));
78535
+ // generate type for the afterload function
78536
+ body.push(AST.exportNamedDeclaration(AST.tsTypeAliasDeclaration(AST.identifier(afterLoadTypeName), AST.tsTypeLiteral([
78537
+ readonlyProperty(AST.tsPropertySignature(AST.stringLiteral('data'), AST.tsTypeAnnotation(AST.tsTypeLiteral([
78538
+ readonlyProperty(AST.tsPropertySignature(AST.stringLiteral(definition.name.value), AST.tsTypeAnnotation(AST.tsTypeReference(AST.identifier(shapeTypeName))))),
78539
+ ])))),
78540
+ ]))));
78571
78541
  // if there are variables in this query
78572
78542
  if (hasInputs && definition.variableDefinitions && definition.variableDefinitions.length > 0) {
78573
78543
  try {
@@ -78586,7 +78556,7 @@ function generateOperationTypeDefs(config, body, definition, selections, visited
78586
78556
  // merge all of the variables into a single object
78587
78557
  body.push(AST.exportNamedDeclaration(AST.tsTypeAliasDeclaration(AST.identifier(inputTypeName), AST.tsTypeLiteral((definition.variableDefinitions || []).map(function (definition) {
78588
78558
  // add a property describing the variable to the root object
78589
- return AST.tsPropertySignature(AST.identifier(definition.variable.name.value), AST.tsTypeAnnotation(tsTypeReference(config, definition)), definition.type.kind !== 'NonNullType');
78559
+ return AST.tsPropertySignature(AST.identifier(definition.variable.name.value), AST.tsTypeAnnotation(tsTypeReference(config, definition)));
78590
78560
  })))));
78591
78561
  }
78592
78562
  return [2 /*return*/];
@@ -78699,6 +78669,27 @@ function persistOutputGenerator(config, docs) {
78699
78669
  });
78700
78670
  }
78701
78671
 
78672
+ // schemaGenerator updates the schema file to contain all of the generated
78673
+ // definitions
78674
+ function schemaGenerator(config, docs) {
78675
+ return __awaiter$1(this, void 0, void 0, function () {
78676
+ return __generator$1(this, function (_a) {
78677
+ switch (_a.label) {
78678
+ case 0:
78679
+ if (!config.newSchema) {
78680
+ return [2 /*return*/];
78681
+ }
78682
+ // print the updated version of the schema over the existing one
78683
+ return [4 /*yield*/, fs$7.writeFile(config.definitionsPath, config.newSchema, 'utf-8')];
78684
+ case 1:
78685
+ // print the updated version of the schema over the existing one
78686
+ _a.sent();
78687
+ return [2 /*return*/];
78688
+ }
78689
+ });
78690
+ });
78691
+ }
78692
+
78702
78693
  // typeCheck verifies that the documents are valid instead of waiting
78703
78694
  // for the compiler to fail later down the line.
78704
78695
  function typeCheck(config, docs) {
@@ -79493,10 +79484,14 @@ var runPipeline = function (config, docs) { return __awaiter$1(void 0, void 0, v
79493
79484
  switch (_a.label) {
79494
79485
  case 0:
79495
79486
  // we need to create the runtime folder structure
79496
- return [4 /*yield*/, config.createDirectories()];
79487
+ return [4 /*yield*/, config.createDirectories()
79488
+ // reset the newSchema accumulator
79489
+ ];
79497
79490
  case 1:
79498
79491
  // we need to create the runtime folder structure
79499
79492
  _a.sent();
79493
+ // reset the newSchema accumulator
79494
+ config.newSchema = '';
79500
79495
  return [4 /*yield*/, runPipeline$1(config, [
79501
79496
  typeCheck,
79502
79497
  uniqueDocumentNames,
@@ -79516,6 +79511,7 @@ var runPipeline = function (config, docs) { return __awaiter$1(void 0, void 0, v
79516
79511
  runtimeGenerator,
79517
79512
  typescriptGenerator,
79518
79513
  persistOutputGenerator,
79514
+ schemaGenerator,
79519
79515
  ], docs)];
79520
79516
  case 2:
79521
79517
  _a.sent();