houdini 2.0.0-next.27 → 2.0.0-next.28

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.
package/build/cmd/init.js CHANGED
@@ -72,62 +72,104 @@ async function init(_path, args) {
72
72
  let schemaPath = is_remote_endpoint ? "./schema.graphql" : "path/to/src/lib/**/*.graphql";
73
73
  let pullSchema_content = null;
74
74
  if (is_remote_endpoint && !args.yes) {
75
- let number_of_round = 0;
76
- let url_and_headers = "";
77
- while (pullSchema_content === null && number_of_round < 10) {
78
- number_of_round++;
79
- const answer = await p.group(
80
- {
81
- url_and_headers: async () => p.text({
82
- message: `What's the URL for your api? ${number_of_round === 1 ? "" : `(attempt ${number_of_round})`}`,
83
- placeholder: `http://localhost:4000/graphql ${number_of_round === 1 ? "" : "Authorization=Bearer MyToken"}`,
84
- validate: (value) => {
85
- if (value === "") {
86
- return;
87
- }
88
- if (!value.startsWith("http")) {
89
- return "Please enter a valid URL";
75
+ const { api_running } = await p.group(
76
+ {
77
+ api_running: () => p.confirm({
78
+ message: "Is your API currently running?",
79
+ initialValue: true
80
+ })
81
+ },
82
+ { onCancel: () => pCancel() }
83
+ );
84
+ if (api_running) {
85
+ let number_of_round = 0;
86
+ let url_and_headers = "";
87
+ while (pullSchema_content === null && number_of_round < 10) {
88
+ number_of_round++;
89
+ const answer = await p.group(
90
+ {
91
+ url_and_headers: async () => p.text({
92
+ message: `What's the URL for your api? ${number_of_round === 1 ? "" : `(attempt ${number_of_round})`}`,
93
+ placeholder: `http://localhost:4000/graphql ${number_of_round === 1 ? "" : "Authorization=Bearer MyToken"}`,
94
+ validate: (value) => {
95
+ if (value === "") {
96
+ return;
97
+ }
98
+ if (!value.startsWith("http")) {
99
+ return "Please enter a valid URL";
100
+ }
90
101
  }
91
- }
102
+ })
103
+ },
104
+ {
105
+ onCancel: () => pCancel()
106
+ }
107
+ );
108
+ url_and_headers = answer.url_and_headers;
109
+ const value_splited = url_and_headers.split(" ");
110
+ const local_url = value_splited[0];
111
+ const local_headers = value_splited.length > 1 ? extractHeadersStr(value_splited.slice(1).join(" ")) : headers;
112
+ const fetchTimeout = 3e4;
113
+ pullSchema_content = await pull_schema(
114
+ local_url,
115
+ fetchTimeout,
116
+ schemaPath,
117
+ local_headers,
118
+ true
119
+ );
120
+ if (pullSchema_content === null) {
121
+ const msg = `If you need to pass headers, add them after the URL (eg: '${green(
122
+ `http://myurl.com/graphql Authorization=Bearer MyToken`
123
+ )}')`;
124
+ p.log.error(msg);
125
+ }
126
+ url = url_and_headers === "" ? "http://localhost:4000/graphql" : local_url;
127
+ }
128
+ if (pullSchema_content === null) {
129
+ pCancel("We couldn't pull the schema. Please check your URL/headers and try again.");
130
+ }
131
+ } else {
132
+ const { has_schema_file } = await p.group(
133
+ {
134
+ has_schema_file: () => p.confirm({
135
+ message: "Do you have a schema file on disk we can use?",
136
+ initialValue: false
92
137
  })
93
138
  },
94
- {
95
- onCancel: () => pCancel()
96
- }
97
- );
98
- url_and_headers = answer.url_and_headers;
99
- const value_splited = url_and_headers.split(" ");
100
- const local_url = value_splited[0];
101
- const local_headers = value_splited.length > 1 ? extractHeadersStr(value_splited.slice(1).join(" ")) : headers;
102
- const fetchTimeout = 3e4;
103
- pullSchema_content = await pull_schema(
104
- local_url,
105
- fetchTimeout,
106
- schemaPath,
107
- local_headers,
108
- true
139
+ { onCancel: () => pCancel() }
109
140
  );
110
- if (pullSchema_content === null) {
111
- const msg = `If you need to pass headers, add them after the URL (eg: '${green(
112
- `http://myurl.com/graphql Authorization=Bearer MyToken`
113
- )}')`;
114
- p.log.error(msg);
141
+ if (has_schema_file) {
142
+ const { schema_file_path } = await p.group(
143
+ {
144
+ schema_file_path: () => p.path({
145
+ message: "Where is the schema file?",
146
+ initialValue: "./schema.graphql",
147
+ validate: (value) => {
148
+ if (!value)
149
+ return "Please enter a valid path";
150
+ try {
151
+ fs.statSync(path.resolve(value));
152
+ } catch {
153
+ return "File not found";
154
+ }
155
+ }
156
+ })
157
+ },
158
+ { onCancel: () => pCancel() }
159
+ );
160
+ pullSchema_content = await fs.readFile(path.resolve(schema_file_path)) ?? null;
115
161
  }
116
- url = url_and_headers === "" ? "http://localhost:4000/graphql" : local_url;
117
- }
118
- if (pullSchema_content === null) {
119
- pCancel("We couldn't pull the schema. Please check your URL/headers and try again.");
162
+ url = "API_URL";
120
163
  }
121
164
  } else if (!args.yes) {
122
165
  const answers = await p.group(
123
166
  {
124
- schema_path: () => p.text({
167
+ schema_path: () => p.path({
125
168
  message: "Where is your schema located?",
126
- placeholder: schemaPath,
169
+ initialValue: schemaPath,
127
170
  validate: (value) => {
128
- if (value === "") {
171
+ if (!value)
129
172
  return "Please enter a valid schemaPath";
130
- }
131
173
  }
132
174
  })
133
175
  },
@@ -173,17 +215,13 @@ async function init(_path, args) {
173
215
  is_remote_endpoint ? url : null,
174
216
  runtimeDir
175
217
  );
176
- await houdiniClient(sourceDir, typescript, frameworkInfo, url);
218
+ await houdiniClient(sourceDir, typescript, frameworkInfo, is_remote_endpoint ? url : null);
177
219
  if (frameworkInfo.framework === "svelte") {
178
220
  await svelteKitConfig(targetPath, typescript);
179
221
  } else if (frameworkInfo.framework === "kit") {
180
222
  await svelteConfig(targetPath, typescript);
181
223
  }
182
- await gitIgnore({
183
- targetPath,
184
- runtimeDir,
185
- schemaPath: is_remote_endpoint ? schemaPath : void 0
186
- });
224
+ await gitIgnore({ targetPath, runtimeDir });
187
225
  await graphqlRC(targetPath, runtimeDir);
188
226
  await viteConfig(targetPath, frameworkInfo, typescript);
189
227
  await tjsConfig(targetPath, frameworkInfo);
@@ -225,7 +263,7 @@ async function houdiniConfig(configPath, schemaPath, module, frameworkInfo, url,
225
263
  };
226
264
  }
227
265
  config.runtimeDir = runtimeDir;
228
- if (schemaPath !== "./schema.graphql") {
266
+ if (url !== null) {
229
267
  config.schemaPath = schemaPath;
230
268
  }
231
269
  if (module !== "esm") {
@@ -260,11 +298,7 @@ module.exports = config
260
298
  async function houdiniClient(targetPath, typescript, _frameworkInfo, url) {
261
299
  const houdiniClientExt = typescript ? `ts` : `js`;
262
300
  const houdiniClientPath = path.join(targetPath, `client.${houdiniClientExt}`);
263
- const content = `import { HoudiniClient } from '$houdini';
264
-
265
- export default new HoudiniClient({
266
- url: '${url}'
267
-
301
+ const comment = `
268
302
  // uncomment this to configure the network call (for things like authentication)
269
303
  // for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
270
304
  // fetchParams({ session }) {
@@ -273,8 +307,14 @@ export default new HoudiniClient({
273
307
  // Authorization: \`Bearer \${session.token}\`,
274
308
  // }
275
309
  // }
276
- // }
277
- })
310
+ // }`;
311
+ const urlLine = url ? `{
312
+ url: '${url}',${comment}
313
+ }` : `{${comment}
314
+ }`;
315
+ const content = `import { HoudiniClient } from '$houdini';
316
+
317
+ export default new HoudiniClient(${urlLine})
278
318
  `;
279
319
  await fs.writeFile(houdiniClientPath, content);
280
320
  }
@@ -329,29 +369,15 @@ export default config;
329
369
  `;
330
370
  await fs.writeFile(svelteConfigPath, typescript ? newContentTs : newContentJs);
331
371
  }
332
- async function gitIgnore({
333
- targetPath,
334
- runtimeDir,
335
- schemaPath
336
- }) {
372
+ async function gitIgnore({ targetPath, runtimeDir }) {
337
373
  const filepath = path.join(targetPath, ".gitignore");
338
374
  const existing = await fs.readFile(filepath) || "";
339
- let newIgnores = "";
340
375
  if (!existing.includes(`
341
376
  ${runtimeDir}
342
377
  `)) {
343
- newIgnores += `${runtimeDir}
344
- `;
345
- }
346
- if (schemaPath && !existing.includes(`
347
- ${schemaPath}
348
- `)) {
349
- newIgnores += `${schemaPath}
350
- `;
351
- }
352
- if (newIgnores) {
353
378
  await fs.writeFile(filepath, `${existing}
354
- ${newIgnores}`);
379
+ ${runtimeDir}
380
+ `);
355
381
  }
356
382
  }
357
383
  async function graphqlRC(targetPath, runtimeDir) {
@@ -445,12 +471,12 @@ async function packageJSON(targetPath, frameworkInfo) {
445
471
  }
446
472
  packageJSON2.devDependencies = {
447
473
  ...packageJSON2.devDependencies,
448
- houdini: "^2.0.0-next.27"
474
+ houdini: "^2.0.0-next.28"
449
475
  };
450
476
  if (frameworkInfo.framework === "svelte" || frameworkInfo.framework === "kit") {
451
477
  packageJSON2.devDependencies = {
452
478
  ...packageJSON2.devDependencies,
453
- "houdini-svelte": "^3.0.0-next.28"
479
+ "houdini-svelte": "^3.0.0-next.29"
454
480
  };
455
481
  } else {
456
482
  throw new Error(`Unmanaged framework: "${JSON.stringify(frameworkInfo)}"`);
@@ -1,6 +1,5 @@
1
1
  import * as graphql from "graphql";
2
2
  import colors from "kleur";
3
- import fetch from "node-fetch";
4
3
  import * as fs from "node:fs/promises";
5
4
  async function pull_schema(url, fetchTimeout, schemaPath, headers, skipWriting) {
6
5
  let content = "";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.27",
3
+ "version": "2.0.0-next.28",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@babel/parser": "^7.24.6",
39
- "@clack/prompts": "^0.6.3",
39
+ "@clack/prompts": "^1.5.1",
40
40
  "@graphql-tools/merge": "^9.0.0",
41
41
  "@graphql-tools/schema": "^9.0.4",
42
42
  "@types/estree": "^1.0.0",
@@ -56,7 +56,6 @@
56
56
  "kleur": "^4.1.5",
57
57
  "micromatch": "^4.0.5",
58
58
  "minimatch": "^5.1.0",
59
- "node-fetch": "^3.2.10",
60
59
  "npx-import": "^1.1.3",
61
60
  "recast": "^0.23.1",
62
61
  "ws": "^8.18.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "2.0.0-next.27",
3
+ "version": "2.0.0-next.28",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/parser": "^7.24.6",
34
- "@clack/prompts": "^0.6.3",
34
+ "@clack/prompts": "^1.5.1",
35
35
  "@graphql-tools/merge": "^9.0.0",
36
36
  "@graphql-tools/schema": "^9.0.4",
37
37
  "@types/estree": "^1.0.0",
@@ -50,7 +50,6 @@
50
50
  "kleur": "^4.1.5",
51
51
  "micromatch": "^4.0.5",
52
52
  "minimatch": "^5.1.0",
53
- "node-fetch": "^3.2.10",
54
53
  "npx-import": "^1.1.3",
55
54
  "recast": "^0.23.1",
56
55
  "ws": "^8.18.0",