houdini-svelte 0.17.0-next.0

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 (59) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/package.json +57 -0
  4. package/src/plugin/codegen/adapter.ts +45 -0
  5. package/src/plugin/codegen/components/index.ts +149 -0
  6. package/src/plugin/codegen/index.ts +28 -0
  7. package/src/plugin/codegen/routes/index.ts +307 -0
  8. package/src/plugin/codegen/routes/kit.test.ts +276 -0
  9. package/src/plugin/codegen/stores/fragment.ts +83 -0
  10. package/src/plugin/codegen/stores/index.ts +55 -0
  11. package/src/plugin/codegen/stores/mutation.ts +56 -0
  12. package/src/plugin/codegen/stores/query.test.ts +504 -0
  13. package/src/plugin/codegen/stores/query.ts +97 -0
  14. package/src/plugin/codegen/stores/subscription.ts +57 -0
  15. package/src/plugin/extract.test.ts +290 -0
  16. package/src/plugin/extract.ts +127 -0
  17. package/src/plugin/extractLoadFunction.test.ts +247 -0
  18. package/src/plugin/extractLoadFunction.ts +249 -0
  19. package/src/plugin/fsPatch.ts +238 -0
  20. package/src/plugin/imports.ts +28 -0
  21. package/src/plugin/index.ts +165 -0
  22. package/src/plugin/kit.ts +382 -0
  23. package/src/plugin/transforms/index.ts +90 -0
  24. package/src/plugin/transforms/kit/index.ts +20 -0
  25. package/src/plugin/transforms/kit/init.test.ts +28 -0
  26. package/src/plugin/transforms/kit/init.ts +75 -0
  27. package/src/plugin/transforms/kit/load.test.ts +1234 -0
  28. package/src/plugin/transforms/kit/load.ts +506 -0
  29. package/src/plugin/transforms/kit/session.test.ts +268 -0
  30. package/src/plugin/transforms/kit/session.ts +161 -0
  31. package/src/plugin/transforms/query.test.ts +99 -0
  32. package/src/plugin/transforms/query.ts +263 -0
  33. package/src/plugin/transforms/reactive.ts +126 -0
  34. package/src/plugin/transforms/tags.ts +20 -0
  35. package/src/plugin/transforms/types.ts +9 -0
  36. package/src/plugin/validate.test.ts +95 -0
  37. package/src/plugin/validate.ts +50 -0
  38. package/src/preprocess/index.ts +33 -0
  39. package/src/runtime/adapter.ts +21 -0
  40. package/src/runtime/fragments.ts +86 -0
  41. package/src/runtime/index.ts +72 -0
  42. package/src/runtime/network.ts +6 -0
  43. package/src/runtime/session.ts +187 -0
  44. package/src/runtime/stores/fragment.ts +48 -0
  45. package/src/runtime/stores/index.ts +5 -0
  46. package/src/runtime/stores/mutation.ts +185 -0
  47. package/src/runtime/stores/pagination/cursor.ts +265 -0
  48. package/src/runtime/stores/pagination/fetch.ts +7 -0
  49. package/src/runtime/stores/pagination/fragment.ts +236 -0
  50. package/src/runtime/stores/pagination/index.ts +7 -0
  51. package/src/runtime/stores/pagination/offset.ts +162 -0
  52. package/src/runtime/stores/pagination/pageInfo.test.ts +39 -0
  53. package/src/runtime/stores/pagination/pageInfo.ts +67 -0
  54. package/src/runtime/stores/pagination/query.ts +132 -0
  55. package/src/runtime/stores/query.ts +524 -0
  56. package/src/runtime/stores/store.ts +13 -0
  57. package/src/runtime/stores/subscription.ts +107 -0
  58. package/src/runtime/types.ts +40 -0
  59. package/src/test/index.ts +208 -0
@@ -0,0 +1,208 @@
1
+ import { CollectedGraphQLDocument, Config, ConfigFile, fs, parseJS, Script, path } from 'houdini'
2
+ import { runPipeline } from 'houdini/codegen'
3
+ import { mockCollectedDoc, testConfig } from 'houdini/test'
4
+
5
+ import plugin from '../plugin'
6
+ import { parseSvelte } from '../plugin/extract'
7
+ import { Framework, layout_query_path, page_query_path, route_data_path } from '../plugin/kit'
8
+ import runTransforms from '../plugin/transforms'
9
+
10
+ const schema = `
11
+ type User {
12
+ id: ID!
13
+ }
14
+
15
+ type Query {
16
+ viewer: User
17
+ }
18
+
19
+ type Mutation {
20
+ addUser: User
21
+ }
22
+ `
23
+
24
+ export async function test_config(extraConfig: Partial<ConfigFile> = {}) {
25
+ const config = testConfig(extraConfig)
26
+ const svelte_plugin = await plugin()
27
+ config.plugins.push({
28
+ ...svelte_plugin,
29
+ include_runtime: true,
30
+ name: 'houdini-svelte',
31
+ version: 'test',
32
+ directory: process.cwd(),
33
+ })
34
+ return config
35
+ }
36
+
37
+ export async function pipeline_test(
38
+ documents: string[],
39
+ extra_config?: Partial<ConfigFile>
40
+ ): Promise<{
41
+ plugin_root: string
42
+ docs: CollectedGraphQLDocument[]
43
+ config: Config
44
+ }> {
45
+ const config = await test_config(extra_config)
46
+
47
+ // the first thing to do is to create the list of collected documents
48
+ const docs: CollectedGraphQLDocument[] = documents.map(mockCollectedDoc)
49
+
50
+ // apply the transforms
51
+ await runPipeline(config, docs)
52
+
53
+ return {
54
+ plugin_root: config.pluginDirectory('houdini-svelte'),
55
+ docs,
56
+ config,
57
+ }
58
+ }
59
+
60
+ export async function route_test({
61
+ component = '',
62
+ script = '',
63
+ page_query = '',
64
+ layout_query = '',
65
+ layout = '',
66
+ layout_script = '',
67
+ config: extra,
68
+ framework = 'kit',
69
+ }: {
70
+ component?: string
71
+ script?: string
72
+ page_query?: string
73
+ layout_query?: string
74
+ layout?: string
75
+ layout_script?: string
76
+ config?: Partial<ConfigFile>
77
+ framework?: Framework
78
+ }): Promise<{
79
+ component: Script | null
80
+ script: Script | null
81
+ layout: Script | null
82
+ layout_script: Script | null
83
+ }> {
84
+ // build up the document we'll pass to the processor
85
+ const config = await test_config({ schema, ...extra })
86
+
87
+ // scripts live in src/routes/+page.svelte
88
+ const page_path = path.join(process.cwd(), 'src/routes', '+page.svelte')
89
+ const layout_path = path.join(process.cwd(), 'src/routes', '+layout.svelte')
90
+ const layout_script_path = route_data_path(config, layout_path)
91
+
92
+ await fs.mkdirp(path.dirname(page_path))
93
+
94
+ // write the content
95
+ await Promise.all([
96
+ fs.writeFile(page_path, component),
97
+ fs.writeFile(route_data_path(config, page_path), script),
98
+ fs.writeFile(page_query_path(config, page_path), page_query),
99
+ fs.writeFile(layout_query_path(config, page_path), layout_query),
100
+ fs.writeFile(layout_path, layout),
101
+ fs.writeFile(layout_script_path, layout_script),
102
+ ])
103
+
104
+ // we want to run the transformer on both the component and script paths
105
+ const [component_result, script_result, layout_result, layout_script_result] =
106
+ await Promise.all([
107
+ runTransforms(framework, {
108
+ content: component,
109
+ config,
110
+ filepath: page_path,
111
+ watch_file: () => {},
112
+ }),
113
+ runTransforms(framework, {
114
+ config,
115
+ filepath: route_data_path(config, page_path),
116
+ watch_file: () => {},
117
+ content: script,
118
+ }),
119
+ runTransforms(framework, {
120
+ config,
121
+ filepath: layout_path,
122
+ watch_file: () => {},
123
+ content: layout,
124
+ }),
125
+ runTransforms(framework, {
126
+ config,
127
+ filepath: layout_script_path,
128
+ watch_file: () => {},
129
+ content: layout_script,
130
+ }),
131
+ ])
132
+
133
+ // return both
134
+ return {
135
+ component: (await parseSvelte(component_result.code))?.script ?? null,
136
+ script: (await parseJS(script_result.code))?.script ?? null,
137
+ layout: (await parseSvelte(layout_result.code))?.script ?? null,
138
+ layout_script: (await parseJS(layout_script_result.code))?.script ?? null,
139
+ }
140
+ }
141
+
142
+ export async function component_test(
143
+ content: string,
144
+ extra?: Partial<ConfigFile>
145
+ ): Promise<Script | null> {
146
+ // build up the document we'll pass to the processor
147
+ const config = await test_config({ schema, ...extra })
148
+
149
+ // routes live in src/routes/+page.svelte
150
+ const filepath = path.join(process.cwd(), 'src/lib', 'component.svelte')
151
+
152
+ // write the content
153
+ await fs.mkdirp(path.dirname(filepath))
154
+ await fs.writeFile(filepath, `<script>${content}</script>`)
155
+
156
+ // we want to run the transformer on both the component and script paths
157
+ const result = await runTransforms('kit', {
158
+ config,
159
+ filepath,
160
+ watch_file: () => {},
161
+ content: `<script>${content}</script>`,
162
+ })
163
+
164
+ // return both
165
+ return (await parseSvelte(result.code))?.script ?? null
166
+ }
167
+
168
+ export async function test_transform_svelte(filepath: string, content: string) {
169
+ // build up the document we'll pass to the processor
170
+ const config = await test_config({ schema })
171
+
172
+ // write the content
173
+ filepath = path.join(config.projectRoot, filepath)
174
+ await fs.mkdirp(path.dirname(filepath))
175
+ await fs.writeFile(filepath, content)
176
+
177
+ // we want to run the transformer on both the component and script paths
178
+ const result = await runTransforms('kit', {
179
+ config,
180
+ filepath,
181
+ watch_file: () => {},
182
+ content,
183
+ })
184
+
185
+ // return both
186
+ return (await parseSvelte(result.code))?.script ?? null
187
+ }
188
+
189
+ export async function test_transform_js(filepath: string, content: string) {
190
+ // build up the document we'll pass to the processor
191
+ const config = await test_config({ schema })
192
+
193
+ // write the content
194
+ filepath = path.join(config.projectRoot, filepath)
195
+ await fs.mkdirp(path.dirname(filepath))
196
+ await fs.writeFile(filepath, content)
197
+
198
+ // we want to run the transformer on both the component and script paths
199
+ const result = await runTransforms('kit', {
200
+ config,
201
+ filepath,
202
+ watch_file: () => {},
203
+ content,
204
+ })
205
+
206
+ // return both
207
+ return (await parseJS(result.code))?.script ?? null
208
+ }