houdini 0.16.0 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +32 -8
  2. package/build/cmd/generators/typescript/index.js +0 -2
  3. package/build/cmd/init.js +80 -26
  4. package/build/cmd/transforms/schema.js +12 -3
  5. package/build/cmd/utils/flattenSelections.d.ts +1 -2
  6. package/build/cmd/utils/flattenSelections.js +9 -6
  7. package/build/cmd/utils/introspection.d.ts +1 -2
  8. package/build/cmd/utils/introspection.js +3 -4
  9. package/build/cmd.js +145 -48
  10. package/build/common/config.d.ts +2 -0
  11. package/build/common/config.js +33 -6
  12. package/build/common/fs.d.ts +1 -0
  13. package/build/common/fs.js +9 -1
  14. package/build/preprocess-cjs/index.js +97 -40
  15. package/build/preprocess-esm/index.js +97 -40
  16. package/build/runtime/lib/config.d.ts +1 -1
  17. package/build/runtime/lib/network.js +5 -0
  18. package/build/runtime-cjs/lib/config.d.ts +1 -1
  19. package/build/runtime-cjs/lib/network.js +5 -0
  20. package/build/runtime-cjs/meta.json +1 -1
  21. package/build/runtime-esm/lib/config.d.ts +1 -1
  22. package/build/runtime-esm/lib/network.js +5 -0
  23. package/build/runtime-esm/meta.json +1 -1
  24. package/build/vite/fsPatch.js +7 -4
  25. package/build/vite/schema.js +10 -6
  26. package/build/vite/transforms/kit/index.js +5 -1
  27. package/build/vite/transforms/kit/session.js +50 -30
  28. package/build/vite-cjs/index.js +135 -61
  29. package/build/vite-esm/index.js +135 -61
  30. package/package.json +1 -1
  31. package/site/src/routes/api/config.svx +1 -1
  32. package/site/src/routes/api/fragments.svx +20 -0
  33. package/site/src/routes/index.svelte +7 -7
  34. package/site/src/routes/intro/fetching-data.svx +5 -3
  35. package/site/src/routes/intro/fragments.svx +6 -4
  36. package/site/src/routes/intro/mutations.svx +14 -4
  37. package/site/src/routes/intro/pagination.svx +3 -3
  38. package/src/cmd/generators/typescript/index.ts +0 -2
  39. package/src/cmd/init.ts +83 -26
  40. package/src/cmd/transforms/schema.ts +27 -8
  41. package/src/cmd/utils/flattenSelections.ts +13 -8
  42. package/src/cmd/utils/introspection.ts +4 -5
  43. package/src/common/config.ts +44 -6
  44. package/src/common/fs.ts +9 -0
  45. package/src/runtime/lib/config.ts +1 -1
  46. package/src/runtime/lib/network.ts +5 -0
  47. package/src/vite/fsPatch.ts +8 -6
  48. package/src/vite/schema.ts +12 -6
  49. package/src/vite/transforms/kit/index.ts +6 -1
  50. package/src/vite/transforms/kit/load.ts +0 -1
  51. package/src/vite/transforms/kit/session.ts +79 -41
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # houdini
2
2
 
3
+ ## 0.16.2
4
+
5
+ ### ✨ Features
6
+
7
+ - [#534](https://github.com/HoudiniGraphql/houdini/pull/534) [`599fc3c`](https://github.com/HoudiniGraphql/houdini/commit/599fc3c9dc7843c40ab25b4c4763e1b3ed9df6c7) Thanks [@fehnomenal](https://github.com/fehnomenal)! - Add ability to control masking for a specific fragment
8
+
9
+ ### 🐛 Fixes
10
+
11
+ - [#540](https://github.com/HoudiniGraphql/houdini/pull/540) [`8addece`](https://github.com/HoudiniGraphql/houdini/commit/8addecef1063dfe7d48f539d1c9f6b72949d7fd2) Thanks [@jycouet](https://github.com/jycouet)! - Warn users when endpoint is not present in dev instead of crashing
12
+
13
+ * [#542](https://github.com/HoudiniGraphql/houdini/pull/542) [`3697e33`](https://github.com/HoudiniGraphql/houdini/commit/3697e33ec644f87f13878b74413b507843d90325) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Fix bug when loading queries in a layout file
14
+
15
+ - [#539](https://github.com/HoudiniGraphql/houdini/pull/539) [`a7d4c2e`](https://github.com/HoudiniGraphql/houdini/commit/a7d4c2e9f650b86f8e19833079c286a64f807d2a) Thanks [@jycouet](https://github.com/jycouet)! - mono repo support
16
+
17
+ - [#537](https://github.com/HoudiniGraphql/houdini/pull/537) [`191c775`](https://github.com/HoudiniGraphql/houdini/commit/191c7750a33b11cdbc8f5e7b9719641d5b0a21c5) Thanks [@jycouet](https://github.com/jycouet)! - init cmd, vite.config.ts generated file
18
+
19
+ ## 0.16.1
20
+
21
+ ### 🐛 Fixes
22
+
23
+ - [#527](https://github.com/HoudiniGraphql/houdini/pull/527) [`9b87678`](https://github.com/HoudiniGraphql/houdini/commit/9b876789140978c0726ed9a708677c7c75f3e19b) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Update init command to work with latest file template
24
+
3
25
  ## 0.16.0
4
26
 
5
27
  ### ⚠️ Breaking Changes
@@ -26,24 +48,26 @@
26
48
 
27
49
  * [#449](https://github.com/HoudiniGraphql/houdini/pull/449) [`59257d1`](https://github.com/HoudiniGraphql/houdini/commit/59257d1dffa6c1d9d250ba0964c6f1f0c35da048) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - You can now define the prefix of your global stores with globalStorePrefix param in the config.
28
50
 
29
- - [#485](https://github.com/HoudiniGraphql/houdini/pull/485) [`c21942c`](https://github.com/HoudiniGraphql/houdini/commit/c21942c4a364dbaca4008dc0ad8263fdc940da84) Thanks [@jycouet](https://github.com/jycouet)! - fix peerDependencies of houdini, graphql needs to be <16
30
-
31
- * [#490](https://github.com/HoudiniGraphql/houdini/pull/490) [`71caba7`](https://github.com/HoudiniGraphql/houdini/commit/71caba7c6b23e73754934fd604030f3cd1a9b74b) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - fix generated types for optimistic responses
32
-
33
- - [#487](https://github.com/HoudiniGraphql/houdini/pull/487) [`0544a28`](https://github.com/HoudiniGraphql/houdini/commit/0544a2846125673f2f0e67cb02135554458edfb0) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Fix issues when rendering kit applications with framework set to "svelte"
34
-
35
51
  * [#508](https://github.com/HoudiniGraphql/houdini/pull/508) [`60ecb33`](https://github.com/HoudiniGraphql/houdini/commit/60ecb333a1396f9aa7244eac2f38741a58e7281f) Thanks [@fehnomenal](https://github.com/fehnomenal)! - added support for sessions
36
52
 
37
53
  * [#449](https://github.com/HoudiniGraphql/houdini/pull/449) [`59257d1`](https://github.com/HoudiniGraphql/houdini/commit/59257d1dffa6c1d9d250ba0964c6f1f0c35da048) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - graphql tags return store references
38
54
 
39
55
  * [#449](https://github.com/HoudiniGraphql/houdini/pull/449) [`59257d1`](https://github.com/HoudiniGraphql/houdini/commit/59257d1dffa6c1d9d250ba0964c6f1f0c35da048) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - add generated typedefs for route functions
40
56
 
41
- - [#523](https://github.com/HoudiniGraphql/houdini/pull/523) [`2c5174c`](https://github.com/HoudiniGraphql/houdini/commit/2c5174c248bf2ae5ee3a8d3a7e910213e859ae2a) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - fix circular import with HoudiniClient
42
-
43
57
  - [#494](https://github.com/HoudiniGraphql/houdini/pull/494) [`5573cfa`](https://github.com/HoudiniGraphql/houdini/commit/5573cfa184d2da322030695044997f5fbf6542bd) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - add onError hook
44
58
 
45
59
  - [#494](https://github.com/HoudiniGraphql/houdini/pull/494) [`5573cfa`](https://github.com/HoudiniGraphql/houdini/commit/5573cfa184d2da322030695044997f5fbf6542bd) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - add `quietQueryError` config value to suppress all query errors
46
60
 
61
+ ### 🐛 Fixes
62
+
63
+ - [#485](https://github.com/HoudiniGraphql/houdini/pull/485) [`c21942c`](https://github.com/HoudiniGraphql/houdini/commit/c21942c4a364dbaca4008dc0ad8263fdc940da84) Thanks [@jycouet](https://github.com/jycouet)! - fix peerDependencies of houdini, graphql needs to be <16
64
+
65
+ - [#523](https://github.com/HoudiniGraphql/houdini/pull/523) [`2c5174c`](https://github.com/HoudiniGraphql/houdini/commit/2c5174c248bf2ae5ee3a8d3a7e910213e859ae2a) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - fix circular import with HoudiniClient
66
+
67
+ - [#490](https://github.com/HoudiniGraphql/houdini/pull/490) [`71caba7`](https://github.com/HoudiniGraphql/houdini/commit/71caba7c6b23e73754934fd604030f3cd1a9b74b) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - fix generated types for optimistic responses
68
+
69
+ - [#487](https://github.com/HoudiniGraphql/houdini/pull/487) [`0544a28`](https://github.com/HoudiniGraphql/houdini/commit/0544a2846125673f2f0e67cb02135554458edfb0) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Fix issues when rendering kit applications with framework set to "svelte"
70
+
47
71
  ## 0.15.9
48
72
 
49
73
  ### Patch Changes
@@ -71,8 +71,6 @@ async function typescriptGenerator(config, docs) {
71
71
  config,
72
72
  filepath: filename,
73
73
  selections: definition.selectionSet.selections,
74
- // only globally include internal fragment values if masking is disabled
75
- includeFragments: config.disableMasking,
76
74
  fragmentDefinitions,
77
75
  });
78
76
  if (definition?.kind === 'OperationDefinition') {
package/build/cmd/init.js CHANGED
@@ -158,7 +158,7 @@ async function init(_path, args, withRunningCheck = true) {
158
158
  else if (framework === 'svelte') {
159
159
  await updateSvelteMainJs(targetPath);
160
160
  }
161
- await updateViteConfig(targetPath, framework);
161
+ await updateViteConfig(targetPath, framework, typescript);
162
162
  await tjsConfig(targetPath, framework);
163
163
  // we're done!
164
164
  console.log();
@@ -275,8 +275,8 @@ async function tjsConfig(targetPath, framework) {
275
275
  catch { }
276
276
  return false;
277
277
  }
278
- async function updateViteConfig(targetPath, framework) {
279
- const viteConfigPath = path_1.default.join(targetPath, 'vite.config.js');
278
+ async function updateViteConfig(targetPath, framework, typescript) {
279
+ const viteConfigPath = path_1.default.join(targetPath, `vite.config${typescript ? '.ts' : '.js'}`);
280
280
  const oldViteConfig1 = `import { sveltekit } from '@sveltejs/kit/vite';
281
281
 
282
282
  /** @type {import('vite').UserConfig} */
@@ -286,13 +286,15 @@ const config = {
286
286
 
287
287
  export default config;
288
288
  `;
289
- const oldViteConfig2 = `import { defineConfig } from 'vite'
290
- import { svelte } from '@sveltejs/vite-plugin-svelte'
289
+ const oldViteConfig2 = `import { sveltekit } from '@sveltejs/kit/vite';
290
+ import type { UserConfig } from 'vite';
291
+
292
+ const config: UserConfig = {
293
+ plugins: [sveltekit()]
294
+ };
295
+
296
+ export default config;
291
297
 
292
- // https://vitejs.dev/config/
293
- export default defineConfig({
294
- plugins: [svelte()]
295
- })
296
298
  `;
297
299
  const viteConfigKit = `import { sveltekit } from '@sveltejs/kit/vite';
298
300
  import houdini from 'houdini/vite';
@@ -302,6 +304,16 @@ const config = {
302
304
  plugins: [houdini(), sveltekit()],
303
305
  }
304
306
 
307
+ export default config;
308
+ `;
309
+ const viteConfigKitTs = `import { sveltekit } from '@sveltejs/kit/vite';
310
+ import houdini from 'houdini/vite';
311
+ import type { UserConfig } from "vite";
312
+
313
+ const config: UserConfig = {
314
+ plugins: [houdini(), sveltekit()],
315
+ }
316
+
305
317
  export default config;
306
318
  `;
307
319
  const viteConfigSvelte = `import { svelte } from '@sveltejs/vite-plugin-svelte';
@@ -314,34 +326,76 @@ const config = {
314
326
 
315
327
  export default config;
316
328
  `;
329
+ const viteConfigSvelteTs = `import { svelte } from '@sveltejs/vite-plugin-svelte';
330
+ import houdini from 'houdini/vite';
331
+ import type { UserConfig } from "vite";
332
+
333
+ const config: UserConfig = {
334
+ plugins: [houdini(), svelte()],
335
+ }
336
+
337
+ export default config;
338
+ `;
339
+ let content = 'NOTHING!';
340
+ if (framework === 'kit' && typescript) {
341
+ content = viteConfigKitTs;
342
+ }
343
+ else if (framework === 'kit' && !typescript) {
344
+ content = viteConfigKit;
345
+ }
346
+ else if (framework === 'svelte' && typescript) {
347
+ content = viteConfigSvelteTs;
348
+ }
349
+ else if (framework === 'svelte' && !typescript) {
350
+ content = viteConfigSvelte;
351
+ }
352
+ else {
353
+ throw new Error('Unknown updateViteConfig()');
354
+ }
317
355
  // write the vite config file
318
356
  await updateFile({
319
357
  projectPath: targetPath,
320
358
  filepath: viteConfigPath,
321
- content: framework === 'kit' ? viteConfigKit : viteConfigSvelte,
359
+ content,
322
360
  old: [oldViteConfig1, oldViteConfig2],
323
361
  });
362
+ if (typescript) {
363
+ await updateFile({
364
+ projectPath: targetPath,
365
+ filepath: viteConfigPath,
366
+ content: framework === 'kit' ? viteConfigKitTs : viteConfigSvelteTs,
367
+ old: [oldViteConfig1, oldViteConfig2],
368
+ });
369
+ }
370
+ else {
371
+ await updateFile({
372
+ projectPath: targetPath,
373
+ filepath: viteConfigPath,
374
+ content: framework === 'kit' ? viteConfigKit : viteConfigSvelte,
375
+ old: [oldViteConfig1, oldViteConfig2],
376
+ });
377
+ }
324
378
  }
325
379
  async function updateSvelteConfig(targetPath) {
326
380
  const svelteConfigPath = path_1.default.join(targetPath, 'svelte.config.js');
327
381
  const newContent = `import adapter from '@sveltejs/adapter-auto';
328
- import preprocess from 'svelte-preprocess';
329
-
330
- /** @type {import('@sveltejs/kit').Config} */
331
- const config = {
332
- // Consult https://github.com/sveltejs/svelte-preprocess
333
- // for more information about preprocessors
334
- preprocess: preprocess(),
335
-
336
- kit: {
337
- adapter: adapter(),
338
- alias: {
339
- $houdini: './$houdini',
340
- }
382
+ import preprocess from 'svelte-preprocess';
383
+
384
+ /** @type {import('@sveltejs/kit').Config} */
385
+ const config = {
386
+ // Consult https://github.com/sveltejs/svelte-preprocess
387
+ // for more information about preprocessors
388
+ preprocess: preprocess(),
389
+
390
+ kit: {
391
+ adapter: adapter(),
392
+ alias: {
393
+ $houdini: './$houdini',
341
394
  }
342
- };
343
-
344
- export default config;
395
+ }
396
+ };
397
+
398
+ export default config;
345
399
  `;
346
400
  const oldSvelteConfig1 = `import adapter from '@sveltejs/adapter-auto';
347
401
  import preprocess from 'svelte-preprocess';
@@ -88,9 +88,18 @@ directive @${config.argumentsDirective} on FRAGMENT_DEFINITION
88
88
  directive @${config.cacheDirective}(${config.cachePolicyArg}: CachePolicy, ${config.cachePartialArg}: Boolean) on QUERY
89
89
 
90
90
  """
91
- @${config.houdiniDirective} is used to configure houdini's internal behavior such as opting-in an automatic load
92
- """
93
- directive @${config.houdiniDirective}(load: Boolean = true) on QUERY
91
+ @${config.houdiniDirective} is used to configure houdini's internal behavior
92
+ """
93
+ directive @${config.houdiniDirective}(
94
+ """
95
+ Opt-in to an automatic load function (only valid when used at queries)
96
+ """
97
+ load: Boolean! = true
98
+ """
99
+ Mask fragment fields (only valid when used at a fragment spread)
100
+ """
101
+ mask: Boolean! = ${config.disableMasking ? 'false' : 'true'}
102
+ ) on QUERY | FRAGMENT_SPREAD
94
103
  `;
95
104
  // if the config does not have the cache directive, then we need to add it
96
105
  let currentSchema = graphql.printSchema(config.schema);
@@ -1,10 +1,9 @@
1
1
  import * as graphql from 'graphql';
2
2
  import { Config } from '../../common';
3
- export declare function flattenSelections({ config, filepath, selections, includeFragments, fragmentDefinitions, }: {
3
+ export declare function flattenSelections({ config, filepath, selections, fragmentDefinitions, }: {
4
4
  config: Config;
5
5
  filepath: string;
6
6
  selections: readonly graphql.SelectionNode[];
7
- includeFragments: boolean;
8
7
  fragmentDefinitions: {
9
8
  [name: string]: graphql.FragmentDefinitionNode;
10
9
  };
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flattenSelections = void 0;
4
4
  const common_1 = require("../../common");
5
- function flattenSelections({ config, filepath, selections, includeFragments, fragmentDefinitions, }) {
5
+ function flattenSelections({ config, filepath, selections, fragmentDefinitions, }) {
6
6
  // collect all of the fields together
7
7
  const fields = new FieldCollection({
8
8
  config,
9
9
  filepath,
10
10
  selections,
11
- includeFragments,
12
11
  fragmentDefinitions,
13
12
  });
14
13
  // convert the flat fields into a selection set
@@ -17,9 +16,7 @@ function flattenSelections({ config, filepath, selections, includeFragments, fra
17
16
  exports.flattenSelections = flattenSelections;
18
17
  class FieldCollection {
19
18
  constructor(args) {
20
- this.includeFragments = false;
21
19
  this.config = args.config;
22
- this.includeFragments = args.includeFragments;
23
20
  this.fragmentDefinitions = args.fragmentDefinitions;
24
21
  this.fields = {};
25
22
  this.inlineFragments = {};
@@ -80,8 +77,15 @@ class FieldCollection {
80
77
  // the application of the fragment has been validated already so track it
81
78
  // so we can recreate
82
79
  this.fragmentSpreads[selection.name.value] = selection;
80
+ // find whether to include fragment fields
81
+ const houdiniDirective = selection.directives?.find(({ name }) => name.value === this.config.houdiniDirective);
82
+ const maskArgument = houdiniDirective?.arguments?.find(({ name }) => name.value === 'mask');
83
+ let includeFragments = this.config.disableMasking;
84
+ if (maskArgument?.value.kind === 'BooleanValue') {
85
+ includeFragments = !maskArgument.value.value;
86
+ }
83
87
  // we're finished if we're not supposed to include fragments in the selection
84
- if (!this.includeFragments) {
88
+ if (!includeFragments) {
85
89
  return;
86
90
  }
87
91
  const definition = this.fragmentDefinitions[selection.name.value];
@@ -113,7 +117,6 @@ class FieldCollection {
113
117
  empty() {
114
118
  return new FieldCollection({
115
119
  config: this.config,
116
- includeFragments: this.includeFragments,
117
120
  fragmentDefinitions: this.fragmentDefinitions,
118
121
  selections: [],
119
122
  filepath: this.filepath,
@@ -1,2 +1 @@
1
- import * as graphql from 'graphql';
2
- export declare function pullSchema(url: string, schemaPath: string, headers?: Record<string, string>): Promise<graphql.GraphQLSchema>;
1
+ export declare function pullSchema(url: string, schemaPath: string, headers?: Record<string, string>): Promise<boolean>;
@@ -52,12 +52,11 @@ async function pullSchema(url, schemaPath, headers) {
52
52
  else {
53
53
  await (0, fs_1.writeFile)(schemaPath, JSON.stringify(jsonSchema));
54
54
  }
55
- // return the schema for usage in --pull-schema
56
- return schema;
55
+ return true;
57
56
  }
58
57
  catch (e) {
59
- console.log(`❌ Encountered error when pulling your latest schema: ` + e.message);
60
- process.exit(0);
58
+ console.warn(`⚠️ Couldn't pull your latest schema: ` + e.message);
61
59
  }
60
+ return false;
62
61
  }
63
62
  exports.pullSchema = pullSchema;