create-sprint 0.0.78 → 0.0.82

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/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { join } from "path";
5
5
  import color from "picocolors";
6
6
  import * as p from "@clack/prompts";
7
7
  import { validateProjectName } from "./validators.js";
8
- import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
8
+ import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob, getGraphQLFiles } from "./generators.js";
9
9
  export async function writeFile(path, content, options) {
10
10
  if (typeof content === "string")
11
11
  content = content.trimEnd();
@@ -175,6 +175,9 @@ async function createProject(projectName, language, telemetry, swagger, graphql,
175
175
  await mkdir(join(srcDir, "cronjobs"), { recursive: true });
176
176
  await mkdir(join(srcDir, "config"), { recursive: true });
177
177
  await mkdir(join(srcDir, "services"), { recursive: true });
178
+ if (graphql) {
179
+ await mkdir(join(srcDir, "graphql"), { recursive: true });
180
+ }
178
181
  if (language === "typescript") {
179
182
  await writeFile(join(srcDir, "config", "index.ts"), "");
180
183
  await writeFile(join(srcDir, "config", "clients.ts"), "");
@@ -194,6 +197,13 @@ async function createProject(projectName, language, telemetry, swagger, graphql,
194
197
  await writeFile(join(srcDir, "schemas", "home." + (language === "typescript" ? "ts" : "js")), getHomeSchema(language));
195
198
  await writeFile(join(srcDir, "schemas", "admin." + (language === "typescript" ? "ts" : "js")), getAdminSchema(language));
196
199
  await writeFile(join(srcDir, "cronjobs", "example." + (language === "typescript" ? "ts" : "js")), getExampleCronJob(language));
200
+ if (graphql) {
201
+ const graphqlFiles = getGraphQLFiles(language);
202
+ const ext = language === "typescript" ? "ts" : "js";
203
+ await writeFile(join(srcDir, "graphql", `types.${ext}`), graphqlFiles["types.ts"]);
204
+ await writeFile(join(srcDir, "graphql", `resolvers.${ext}`), graphqlFiles["resolvers.ts"]);
205
+ await writeFile(join(srcDir, "graphql", `schema.${ext}`), graphqlFiles["schema.ts"]);
206
+ }
197
207
  await writeFile(join(targetDir, ".env.development.example"), getEnvExample(telemetry));
198
208
  await writeFile(join(targetDir, ".env.production.example"), getEnvExample(telemetry));
199
209
  await writeFile(join(targetDir, ".env.development"), getEnvDevelopment(telemetry));
@@ -53,21 +53,24 @@ export default defineConfig({
53
53
  }
54
54
  ;
55
55
  export function getSprintConfigFile(language, telemetry, swagger, graphql) {
56
+ const swaggerEnabled = swagger ? "true" : "false";
57
+ const graphqlEnabled = graphql ? "true" : "false";
58
+ const graphiqlEnabled = graphql ? '["development"]' : "false";
56
59
  if (language === "typescript") {
57
60
  let config = `import type { SprintOptions } from "sprint-es";
58
61
 
59
62
  export const config: SprintOptions = {
60
63
  openapi: {
61
- enabled: ${swagger},
62
- generateOnBuild: ${swagger},
64
+ enabled: ${swaggerEnabled},
65
+ generateOnBuild: ${swaggerEnabled},
63
66
  swaggerUi: {
64
- enabled: ${swagger}
67
+ enabled: ${swaggerEnabled}
65
68
  }
66
69
  },
67
70
  graphql: {
68
- enabled: ${graphql},
71
+ enabled: ${graphqlEnabled},
69
72
  graphiql: {
70
- enabled: ${graphql}
73
+ enabled: ${graphiqlEnabled}
71
74
  }
72
75
  }
73
76
  };
@@ -99,16 +102,16 @@ initTelemetry({
99
102
  }
100
103
  let config = `export const config = {
101
104
  openapi: {
102
- enabled: ${swagger},
103
- generateOnBuild: ${swagger},
105
+ enabled: ${swaggerEnabled},
106
+ generateOnBuild: ${swaggerEnabled},
104
107
  swaggerUi: {
105
- enabled: ${swagger}
108
+ enabled: ${swaggerEnabled}
106
109
  }
107
110
  },
108
111
  graphql: {
109
- enabled: ${graphql},
112
+ enabled: ${graphqlEnabled},
110
113
  graphiql: {
111
- enabled: ${graphql}
114
+ enabled: ${graphiqlEnabled}
112
115
  }
113
116
  }
114
117
  };
@@ -0,0 +1,73 @@
1
+ export function getGraphQLFiles(language) {
2
+ const isTs = language === "typescript";
3
+ const ext = isTs ? "" : ".js";
4
+ return {
5
+ "types.ts": `import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
6
+
7
+ export const UserType = new GraphQLObjectType({
8
+ name: "User",
9
+ fields: {
10
+ id: { type: new GraphQLNonNull(GraphQLString) },
11
+ name: { type: GraphQLString },
12
+ email: { type: GraphQLString }
13
+ }
14
+ });
15
+ `,
16
+ "resolvers.ts": `import { GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
17
+ import { UserType } from "./types${ext}";
18
+
19
+ export const users = [
20
+ { id: "1", name: "John Doe", email: "john@example.com" },
21
+ { id: "2", name: "Jane Smith", email: "jane@example.com" }
22
+ ];
23
+
24
+ export const queries = {
25
+ hello: {
26
+ type: GraphQLString,
27
+ resolve: () => "Hello, GraphQL!"
28
+ },
29
+ users: {
30
+ type: new GraphQLList(UserType),
31
+ resolve: () => users
32
+ },
33
+ user: {
34
+ type: UserType,
35
+ args: {
36
+ id: { type: new GraphQLNonNull(GraphQLString) }
37
+ },
38
+ resolve: (_, args) => users.find(u => u.id === args.id)
39
+ }
40
+ };
41
+
42
+ export const mutations = {
43
+ createUser: {
44
+ type: UserType,
45
+ args: {
46
+ name: { type: new GraphQLNonNull(GraphQLString) },
47
+ email: { type: new GraphQLNonNull(GraphQLString) }
48
+ },
49
+ resolve: (_, args) => {
50
+ const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
51
+ users.push(newUser);
52
+ return newUser;
53
+ }
54
+ }
55
+ };
56
+ `,
57
+ "schema.ts": `import { GraphQLSchema, GraphQLObjectType } from "graphql";
58
+ import { queries, mutations } from "./resolvers${ext}";
59
+
60
+ const Query = new GraphQLObjectType({
61
+ name: "Query",
62
+ fields: queries
63
+ });
64
+
65
+ const Mutation = new GraphQLObjectType({
66
+ name: "Mutation",
67
+ fields: mutations
68
+ });
69
+
70
+ export const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
71
+ `
72
+ };
73
+ }
@@ -16,5 +16,7 @@ export { getHomeSchema, getAdminSchema } from "./schemas.js";
16
16
  export { getExampleCronJob } from "./cronjobs.js";
17
17
  // Docker
18
18
  export { getDockerfile, getDockerCompose } from "./docker.js";
19
+ // GraphQL
20
+ export { getGraphQLFiles } from "./graphql.js";
19
21
  // Misc
20
22
  export { getGitignore, getDockerIgnore } from "./misc.js";
@@ -10,7 +10,7 @@ export function generateJWTKeys() {
10
10
  ;
11
11
  export function getTypeScriptPackageJson(name, telemetry, swagger, graphql) {
12
12
  const deps = {
13
- "sprint-es": "^0.0.82"
13
+ "sprint-es": "^0.0.84"
14
14
  };
15
15
  const devDeps = {
16
16
  "@types/node": "^22.0.0",
@@ -49,7 +49,7 @@ export function getTypeScriptPackageJson(name, telemetry, swagger, graphql) {
49
49
  ;
50
50
  export function getJavaScriptPackageJson(name, telemetry, swagger, graphql) {
51
51
  const deps = {
52
- "sprint-es": "^0.0.82"
52
+ "sprint-es": "^0.0.84"
53
53
  };
54
54
  if (telemetry === "sentry" || telemetry === "glitchtip")
55
55
  deps["@sentry/node"] = "^8.0.0";
@@ -1,66 +1,12 @@
1
1
  export function getMainFile(language, graphql = false) {
2
- if (language === "typescript") {
2
+ const isTs = language === "typescript";
3
+ const ext = isTs ? "" : ".js";
4
+ if (isTs) {
3
5
  if (graphql) {
4
6
  return `import Sprint from "sprint-es";
5
- import { config } from "./sprint.config.js";
6
- import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
7
-
8
- const users = [
9
- { id: "1", name: "John Doe", email: "john@example.com" },
10
- { id: "2", name: "Jane Smith", email: "jane@example.com" }
11
- ];
12
-
13
- const UserType = new GraphQLObjectType({
14
- name: "User",
15
- fields: {
16
- id: { type: new GraphQLNonNull(GraphQLString) },
17
- name: { type: GraphQLString },
18
- email: { type: GraphQLString }
19
- }
20
- });
21
-
22
- const Query = new GraphQLObjectType({
23
- name: "Query",
24
- fields: {
25
- hello: {
26
- type: GraphQLString,
27
- resolve: () => "Hello, GraphQL!"
28
- },
29
- users: {
30
- type: new GraphQLList(UserType),
31
- resolve: () => users
32
- },
33
- user: {
34
- type: UserType,
35
- args: {
36
- id: { type: new GraphQLNonNull(GraphQLString) }
37
- },
38
- resolve: (_, args) => users.find(u => u.id === args.id)
39
- }
40
- }
41
- });
42
-
43
- const Mutation = new GraphQLObjectType({
44
- name: "Mutation",
45
- fields: {
46
- createUser: {
47
- type: UserType,
48
- args: {
49
- name: { type: new GraphQLNonNull(GraphQLString) },
50
- email: { type: new GraphQLNonNull(GraphQLString) }
51
- },
52
- resolve: (_, args) => {
53
- const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
54
- users.push(newUser);
55
- return newUser;
56
- }
57
- }
58
- }
59
- });
7
+ import { graphqlSchema } from "./graphql/schema";
60
8
 
61
- const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
62
-
63
- const app = new Sprint(config);
9
+ const app = new Sprint();
64
10
  app.setGraphQLSchema(graphqlSchema);
65
11
  `;
66
12
  }
@@ -71,65 +17,9 @@ const app = new Sprint();
71
17
  }
72
18
  if (graphql) {
73
19
  return `import Sprint from "sprint-es";
74
- import { config } from "./sprint.config.js";
75
- import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
76
-
77
- const users = [
78
- { id: "1", name: "John Doe", email: "john@example.com" },
79
- { id: "2", name: "Jane Smith", email: "jane@example.com" }
80
- ];
81
-
82
- const UserType = new GraphQLObjectType({
83
- name: "User",
84
- fields: {
85
- id: { type: new GraphQLNonNull(GraphQLString) },
86
- name: { type: GraphQLString },
87
- email: { type: GraphQLString }
88
- }
89
- });
90
-
91
- const Query = new GraphQLObjectType({
92
- name: "Query",
93
- fields: {
94
- hello: {
95
- type: GraphQLString,
96
- resolve: () => "Hello, GraphQL!"
97
- },
98
- users: {
99
- type: new GraphQLList(UserType),
100
- resolve: () => users
101
- },
102
- user: {
103
- type: UserType,
104
- args: {
105
- id: { type: new GraphQLNonNull(GraphQLString) }
106
- },
107
- resolve: (_, args) => users.find(u => u.id === args.id)
108
- }
109
- }
110
- });
111
-
112
- const Mutation = new GraphQLObjectType({
113
- name: "Mutation",
114
- fields: {
115
- createUser: {
116
- type: UserType,
117
- args: {
118
- name: { type: new GraphQLNonNull(GraphQLString) },
119
- email: { type: new GraphQLNonNull(GraphQLString) }
120
- },
121
- resolve: (_, args) => {
122
- const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
123
- users.push(newUser);
124
- return newUser;
125
- }
126
- }
127
- }
128
- });
129
-
130
- const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
20
+ import { graphqlSchema } from "./graphql/schema.js";
131
21
 
132
- const app = new Sprint(config);
22
+ const app = new Sprint();
133
23
  app.setGraphQLSchema(graphqlSchema);
134
24
  `;
135
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sprint",
3
- "version": "0.0.78",
3
+ "version": "0.0.82",
4
4
  "description": "Create a new Sprint API project",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import { join } from "path";
5
5
  import color from "picocolors";
6
6
  import * as p from "@clack/prompts";
7
7
  import { validateProjectName } from "./validators.js";
8
- import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
8
+ import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob, getGraphQLFiles } from "./generators.js";
9
9
 
10
10
  export interface CLIOptions {
11
11
  projectName?: string;
@@ -224,6 +224,10 @@ async function createProject(
224
224
  await mkdir(join(srcDir, "cronjobs"), { recursive: true });
225
225
  await mkdir(join(srcDir, "config"), { recursive: true });
226
226
  await mkdir(join(srcDir, "services"), { recursive: true });
227
+
228
+ if (graphql) {
229
+ await mkdir(join(srcDir, "graphql"), { recursive: true });
230
+ }
227
231
 
228
232
  if (language === "typescript") {
229
233
  await writeFile(join(srcDir, "config", "index.ts"), "");
@@ -251,6 +255,15 @@ async function createProject(
251
255
 
252
256
  await writeFile(join(srcDir, "cronjobs", "example." + (language === "typescript" ? "ts" : "js")), getExampleCronJob(language));
253
257
 
258
+ if (graphql) {
259
+ const graphqlFiles = getGraphQLFiles(language);
260
+ const ext = language === "typescript" ? "ts" : "js";
261
+
262
+ await writeFile(join(srcDir, "graphql", `types.${ext}`), graphqlFiles["types.ts"]);
263
+ await writeFile(join(srcDir, "graphql", `resolvers.${ext}`), graphqlFiles["resolvers.ts"]);
264
+ await writeFile(join(srcDir, "graphql", `schema.${ext}`), graphqlFiles["schema.ts"]);
265
+ }
266
+
254
267
  await writeFile(join(targetDir, ".env.development.example"), getEnvExample(telemetry));
255
268
  await writeFile(join(targetDir, ".env.production.example"), getEnvExample(telemetry));
256
269
 
@@ -53,21 +53,25 @@ export default defineConfig({
53
53
  };
54
54
 
55
55
  export function getSprintConfigFile(language: string, telemetry: string, swagger: boolean, graphql: boolean) {
56
+ const swaggerEnabled = swagger ? "true" : "false";
57
+ const graphqlEnabled = graphql ? "true" : "false";
58
+ const graphiqlEnabled = graphql ? '["development"]' : "false";
59
+
56
60
  if (language === "typescript") {
57
61
  let config = `import type { SprintOptions } from "sprint-es";
58
62
 
59
63
  export const config: SprintOptions = {
60
64
  openapi: {
61
- enabled: ${swagger},
62
- generateOnBuild: ${swagger},
65
+ enabled: ${swaggerEnabled},
66
+ generateOnBuild: ${swaggerEnabled},
63
67
  swaggerUi: {
64
- enabled: ${swagger}
68
+ enabled: ${swaggerEnabled}
65
69
  }
66
70
  },
67
71
  graphql: {
68
- enabled: ${graphql},
72
+ enabled: ${graphqlEnabled},
69
73
  graphiql: {
70
- enabled: ${graphql}
74
+ enabled: ${graphiqlEnabled}
71
75
  }
72
76
  }
73
77
  };
@@ -101,16 +105,16 @@ initTelemetry({
101
105
 
102
106
  let config = `export const config = {
103
107
  openapi: {
104
- enabled: ${swagger},
105
- generateOnBuild: ${swagger},
108
+ enabled: ${swaggerEnabled},
109
+ generateOnBuild: ${swaggerEnabled},
106
110
  swaggerUi: {
107
- enabled: ${swagger}
111
+ enabled: ${swaggerEnabled}
108
112
  }
109
113
  },
110
114
  graphql: {
111
- enabled: ${graphql},
115
+ enabled: ${graphqlEnabled},
112
116
  graphiql: {
113
- enabled: ${graphql}
117
+ enabled: ${graphiqlEnabled}
114
118
  }
115
119
  }
116
120
  };
@@ -0,0 +1,74 @@
1
+ export function getGraphQLFiles(language: string) {
2
+ const isTs = language === "typescript";
3
+ const ext = isTs ? "" : ".js";
4
+
5
+ return {
6
+ "types.ts": `import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
7
+
8
+ export const UserType = new GraphQLObjectType({
9
+ name: "User",
10
+ fields: {
11
+ id: { type: new GraphQLNonNull(GraphQLString) },
12
+ name: { type: GraphQLString },
13
+ email: { type: GraphQLString }
14
+ }
15
+ });
16
+ `,
17
+ "resolvers.ts": `import { GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
18
+ import { UserType } from "./types${ext}";
19
+
20
+ export const users = [
21
+ { id: "1", name: "John Doe", email: "john@example.com" },
22
+ { id: "2", name: "Jane Smith", email: "jane@example.com" }
23
+ ];
24
+
25
+ export const queries = {
26
+ hello: {
27
+ type: GraphQLString,
28
+ resolve: () => "Hello, GraphQL!"
29
+ },
30
+ users: {
31
+ type: new GraphQLList(UserType),
32
+ resolve: () => users
33
+ },
34
+ user: {
35
+ type: UserType,
36
+ args: {
37
+ id: { type: new GraphQLNonNull(GraphQLString) }
38
+ },
39
+ resolve: (_, args) => users.find(u => u.id === args.id)
40
+ }
41
+ };
42
+
43
+ export const mutations = {
44
+ createUser: {
45
+ type: UserType,
46
+ args: {
47
+ name: { type: new GraphQLNonNull(GraphQLString) },
48
+ email: { type: new GraphQLNonNull(GraphQLString) }
49
+ },
50
+ resolve: (_, args) => {
51
+ const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
52
+ users.push(newUser);
53
+ return newUser;
54
+ }
55
+ }
56
+ };
57
+ `,
58
+ "schema.ts": `import { GraphQLSchema, GraphQLObjectType } from "graphql";
59
+ import { queries, mutations } from "./resolvers${ext}";
60
+
61
+ const Query = new GraphQLObjectType({
62
+ name: "Query",
63
+ fields: queries
64
+ });
65
+
66
+ const Mutation = new GraphQLObjectType({
67
+ name: "Mutation",
68
+ fields: mutations
69
+ });
70
+
71
+ export const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
72
+ `
73
+ };
74
+ }
@@ -25,5 +25,8 @@ export { getExampleCronJob } from "./cronjobs.js";
25
25
  // Docker
26
26
  export { getDockerfile, getDockerCompose } from "./docker.js";
27
27
 
28
+ // GraphQL
29
+ export { getGraphQLFiles } from "./graphql.js";
30
+
28
31
  // Misc
29
32
  export { getGitignore, getDockerIgnore } from "./misc.js";
@@ -16,7 +16,7 @@ export function generateJWTKeys(): JWTKeys {
16
16
 
17
17
  export function getTypeScriptPackageJson(name: string, telemetry: string, swagger: boolean, graphql: boolean) {
18
18
  const deps: Record<string, string> = {
19
- "sprint-es": "^0.0.82"
19
+ "sprint-es": "^0.0.84"
20
20
  };
21
21
 
22
22
  const devDeps: Record<string, string> = {
@@ -56,7 +56,7 @@ export function getTypeScriptPackageJson(name: string, telemetry: string, swagge
56
56
 
57
57
  export function getJavaScriptPackageJson(name: string, telemetry: string, swagger: boolean, graphql: boolean) {
58
58
  const deps: Record<string, string> = {
59
- "sprint-es": "^0.0.82"
59
+ "sprint-es": "^0.0.84"
60
60
  };
61
61
 
62
62
  if (telemetry === "sentry" || telemetry === "glitchtip") deps["@sentry/node"] = "^8.0.0";
@@ -1,66 +1,13 @@
1
1
  export function getMainFile(language: string, graphql: boolean = false) {
2
- if (language === "typescript") {
2
+ const isTs = language === "typescript";
3
+ const ext = isTs ? "" : ".js";
4
+
5
+ if (isTs) {
3
6
  if (graphql) {
4
7
  return `import Sprint from "sprint-es";
5
- import { config } from "./sprint.config.js";
6
- import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
7
-
8
- const users = [
9
- { id: "1", name: "John Doe", email: "john@example.com" },
10
- { id: "2", name: "Jane Smith", email: "jane@example.com" }
11
- ];
12
-
13
- const UserType = new GraphQLObjectType({
14
- name: "User",
15
- fields: {
16
- id: { type: new GraphQLNonNull(GraphQLString) },
17
- name: { type: GraphQLString },
18
- email: { type: GraphQLString }
19
- }
20
- });
21
-
22
- const Query = new GraphQLObjectType({
23
- name: "Query",
24
- fields: {
25
- hello: {
26
- type: GraphQLString,
27
- resolve: () => "Hello, GraphQL!"
28
- },
29
- users: {
30
- type: new GraphQLList(UserType),
31
- resolve: () => users
32
- },
33
- user: {
34
- type: UserType,
35
- args: {
36
- id: { type: new GraphQLNonNull(GraphQLString) }
37
- },
38
- resolve: (_, args) => users.find(u => u.id === args.id)
39
- }
40
- }
41
- });
42
-
43
- const Mutation = new GraphQLObjectType({
44
- name: "Mutation",
45
- fields: {
46
- createUser: {
47
- type: UserType,
48
- args: {
49
- name: { type: new GraphQLNonNull(GraphQLString) },
50
- email: { type: new GraphQLNonNull(GraphQLString) }
51
- },
52
- resolve: (_, args) => {
53
- const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
54
- users.push(newUser);
55
- return newUser;
56
- }
57
- }
58
- }
59
- });
8
+ import { graphqlSchema } from "./graphql/schema";
60
9
 
61
- const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
62
-
63
- const app = new Sprint(config);
10
+ const app = new Sprint();
64
11
  app.setGraphQLSchema(graphqlSchema);
65
12
  `;
66
13
  }
@@ -72,65 +19,9 @@ const app = new Sprint();
72
19
 
73
20
  if (graphql) {
74
21
  return `import Sprint from "sprint-es";
75
- import { config } from "./sprint.config.js";
76
- import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
77
-
78
- const users = [
79
- { id: "1", name: "John Doe", email: "john@example.com" },
80
- { id: "2", name: "Jane Smith", email: "jane@example.com" }
81
- ];
82
-
83
- const UserType = new GraphQLObjectType({
84
- name: "User",
85
- fields: {
86
- id: { type: new GraphQLNonNull(GraphQLString) },
87
- name: { type: GraphQLString },
88
- email: { type: GraphQLString }
89
- }
90
- });
91
-
92
- const Query = new GraphQLObjectType({
93
- name: "Query",
94
- fields: {
95
- hello: {
96
- type: GraphQLString,
97
- resolve: () => "Hello, GraphQL!"
98
- },
99
- users: {
100
- type: new GraphQLList(UserType),
101
- resolve: () => users
102
- },
103
- user: {
104
- type: UserType,
105
- args: {
106
- id: { type: new GraphQLNonNull(GraphQLString) }
107
- },
108
- resolve: (_, args) => users.find(u => u.id === args.id)
109
- }
110
- }
111
- });
112
-
113
- const Mutation = new GraphQLObjectType({
114
- name: "Mutation",
115
- fields: {
116
- createUser: {
117
- type: UserType,
118
- args: {
119
- name: { type: new GraphQLNonNull(GraphQLString) },
120
- email: { type: new GraphQLNonNull(GraphQLString) }
121
- },
122
- resolve: (_, args) => {
123
- const newUser = { id: String(users.length + 1), name: args.name, email: args.email };
124
- users.push(newUser);
125
- return newUser;
126
- }
127
- }
128
- }
129
- });
130
-
131
- const graphqlSchema = new GraphQLSchema({ query: Query, mutation: Mutation });
22
+ import { graphqlSchema } from "./graphql/schema.js";
132
23
 
133
- const app = new Sprint(config);
24
+ const app = new Sprint();
134
25
  app.setGraphQLSchema(graphqlSchema);
135
26
  `;
136
27
  }