Skip to content

Commit 6cef569

Browse files
authored
Merge pull request #93 from graphql-editor/schema-push
Expand the command scheme and remove unused commands
2 parents e21606c + a5a51fd commit 6cef569

File tree

14 files changed

+2593
-2639
lines changed

14 files changed

+2593
-2639
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/Editor.ts

+13-52
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
Subscription,
3-
Chain,
4-
DeployCodeToCloudEnv,
5-
DeployCodeToCloudURIKind,
6-
GraphQLTypes,
7-
ValueTypes,
8-
} from '@/zeus/index.js';
1+
import { Subscription, Chain, GraphQLTypes, ValueTypes } from '@/zeus/index.js';
92
import { Config } from '@/Configuration/index.js';
103
import fetch from 'node-fetch';
114
import { COMMON_FILES } from '@/gshared/constants/index.js';
@@ -22,8 +15,8 @@ const jolt = () => {
2215
const token = Config.getTokenOptions('token');
2316
const headers: Record<string, string> = token
2417
? {
25-
Authorization: `Bearer ${token}`,
26-
}
18+
Authorization: `Bearer ${token}`,
19+
}
2720
: {};
2821
return Chain('https://api.staging.project.graphqleditor.com/graphql', {
2922
headers,
@@ -34,8 +27,8 @@ const joltSubscription = () => {
3427
const token = Config.getTokenOptions('token');
3528
const headers: Record<string, string> = token
3629
? {
37-
Authorization: `Bearer ${token}`,
38-
}
30+
Authorization: `Bearer ${token}`,
31+
}
3932
: {};
4033
return Subscription('https://api.staging.project.graphqleditor.com/graphql', {
4134
headers,
@@ -184,9 +177,14 @@ export class Editor {
184177
? (await fetch(libraryURL.getUrl!)).text()
185178
: new Promise<string>((resolve) => resolve('')),
186179
]);
187-
const sdlMerge = mergeSDLs(graphqlFile, libraryFile)
188-
if (sdlMerge.__typename === 'error') throw new Error(sdlMerge.errors.map(e => `Conflict on: ${e.conflictingNode}.${e.conflictingField}`).join("\n"))
189-
return sdlMerge.sdl
180+
const sdlMerge = mergeSDLs(graphqlFile, libraryFile);
181+
if (sdlMerge.__typename === 'error')
182+
throw new Error(
183+
sdlMerge.errors
184+
.map((e) => `Conflict on: ${e.conflictingNode}.${e.conflictingField}`)
185+
.join('\n'),
186+
);
187+
return sdlMerge.sdl;
190188
};
191189

192190
public static getSchema = async (resolve: {
@@ -328,12 +326,6 @@ export class Editor {
328326
}),
329327
);
330328
};
331-
public static deployProjectToCloud = async (projectId: string) => {
332-
const response = await jolt()('mutation')({
333-
createCloudDeployment: [{ id: projectId }, true],
334-
});
335-
return response.createCloudDeployment;
336-
};
337329
public static getServerLessMongo = async (projectId: string) => {
338330
const checking = ora(
339331
'Checking if remote mongo serverless configuration exists',
@@ -351,31 +343,6 @@ export class Editor {
351343
else checking.fail();
352344
return result;
353345
};
354-
public static deployRepoToSharedWorker = async (
355-
projectId: string,
356-
zipURI: string,
357-
opts: Pick<ValueTypes['DeployCodeToCloudInput'], 'node14Opts' | 'secrets'>,
358-
) => {
359-
const response = await jolt()('mutation')({
360-
deployCodeToCloud: [
361-
{
362-
id: projectId,
363-
opts: {
364-
codeURI: zipURI,
365-
env: DeployCodeToCloudEnv.NODE14,
366-
kind: DeployCodeToCloudURIKind.ZIP,
367-
...opts,
368-
},
369-
},
370-
true,
371-
],
372-
});
373-
const deploymentId = response.deployCodeToCloud;
374-
if (!deploymentId) {
375-
throw new Error('Cannot deploy project');
376-
}
377-
return deploymentId;
378-
};
379346
public static publishIntegration = async (
380347
projectId: string,
381348
integration: ValueTypes['AddProjectInput'],
@@ -395,12 +362,6 @@ export class Editor {
395362
});
396363
return response.marketplace?.removeProject;
397364
};
398-
public static showDeploymentLogs = async (streamID: string) => {
399-
const response = await joltSubscription()('subscription')({
400-
watchLogs: [{ streamID }, true],
401-
});
402-
return response;
403-
};
404365
public static getDeviceCode = async () => {
405366
const response = await fetch(
406367
'https://auth.graphqleditor.com/oauth/device/code',
-86
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Auth } from '@/Auth/index.js';
2-
import { CommandDeploy } from '@/commands/cloud/deploy.js';
3-
import { CommandDeployRemote } from '@/commands/cloud/deployFromRemote.js';
42
import { CommandInstall } from '@/commands/cloud/install.js';
53
import { CommandPull } from '@/commands/cloud/pull.js';
64
import { CommandPush } from '@/commands/cloud/push.js';
@@ -66,90 +64,6 @@ export default {
6664
argv as Pick<ConfigurationOptions, 'project' | 'namespace'>,
6765
);
6866
},
69-
)
70-
.command(
71-
'deploy:zip',
72-
'Deploy GraphQL backend to GraphQL Editor shared worker from remote zip',
73-
async (yargs) => {
74-
yargs.options({
75-
...confOptions({
76-
namespace: projectOptions.namespace,
77-
project: projectOptions.project,
78-
backendZip: {
79-
type: 'string',
80-
describe:
81-
'Paste your repo zip url, for github it will be https://github.com/account_name/repository/archive/refs/heads/main.zip',
82-
},
83-
}),
84-
env: {
85-
alias: 'e',
86-
array: true,
87-
coerce: (v: Array<string>) => {
88-
return v
89-
.map((e: string) => e.split('='))
90-
.map(([name, ...value]) => ({
91-
name,
92-
value: value.join('='),
93-
}));
94-
},
95-
describe:
96-
'Set environment variables for example "-e URL=$URL" or "-e URL=example.com"',
97-
},
98-
});
99-
},
100-
async (argv) => {
101-
await Auth.login().then(Config.setTokenOptions);
102-
await CommandDeployRemote(
103-
argv as Pick<
104-
ConfigurationOptions,
105-
'project' | 'namespace' | 'backendZip'
106-
> & {
107-
env?: ValueTypes['Secret'][];
108-
},
109-
);
110-
},
111-
)
112-
.command(
113-
'deploy',
114-
'Deploy GraphQL backend to GraphQL Editor shared worker from current repository',
115-
async (yargs) => {
116-
yargs.options({
117-
...confOptions({
118-
namespace: projectOptions.namespace,
119-
project: projectOptions.project,
120-
buildScript: {
121-
type: 'string',
122-
describe: 'Build script as in your package.json',
123-
default: 'build',
124-
},
125-
}),
126-
env: {
127-
alias: 'e',
128-
array: true,
129-
coerce: (v: Array<string>) => {
130-
return v
131-
.map((e: string) => e.split('='))
132-
.map(([name, ...value]) => ({
133-
name,
134-
value: value.join('='),
135-
}));
136-
},
137-
describe:
138-
'Set environment variables for example "-e URL=$URL" or "-e URL=example.com"',
139-
},
140-
});
141-
},
142-
async (argv) => {
143-
await Auth.login().then(Config.setTokenOptions);
144-
await CommandDeploy(
145-
argv as Pick<
146-
ConfigurationOptions,
147-
'project' | 'namespace' | 'backendZip' | 'buildScript'
148-
> & {
149-
env?: ValueTypes['Secret'][];
150-
},
151-
);
152-
},
15367
);
15468
},
15569
} as CommandModule;

packages/cli/src/commands/cloud/deploy.ts

-45
This file was deleted.

packages/cli/src/commands/cloud/deployFromRemote.ts

-36
This file was deleted.

packages/cli/src/commands/common/init.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const initConfiguration = async ({
88
namespace?: string;
99
project?: string;
1010
version?: string;
11+
schemaDir?: string | null;
1112
}): Promise<void> => {
1213
Config.configure(
1314
{
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Auth } from '@/Auth/index.js';
2+
import { projectOptions, confOptions, ConfOptions } from '@/common/promptOptions.js';
3+
import { Config, ConfigurationOptions } from '@/Configuration/index.js';
4+
import { CommandModule } from 'yargs';
5+
import { CommandSchemaPull } from './pull.js';
6+
import { CommandSchemaPush } from './push.js';
7+
8+
const schemaOptions: ConfOptions = {
9+
...projectOptions,
10+
schemaDir: {
11+
type: 'string',
12+
describe: 'location of the schema file'
13+
}
14+
}
15+
16+
export default {
17+
command: 'schema <command>',
18+
describe: 'Generate and modify your GraphQL schema',
19+
builder: (yargs) => {
20+
return yargs
21+
.command(
22+
'pull',
23+
'Generate GraphQL schema from project at given path',
24+
async (yargs) => {
25+
yargs.options(confOptions(schemaOptions));
26+
},
27+
async (argv) => {
28+
await Auth.login().then(Config.setTokenOptions);
29+
await CommandSchemaPull(
30+
argv as Pick<
31+
ConfigurationOptions,
32+
'namespace' | 'project' | 'projectVersion' | 'schemaDir'
33+
>,
34+
);
35+
},
36+
)
37+
.command(
38+
'push',
39+
'Deploy GraphQL schema as latest',
40+
async (yargs) => {
41+
yargs.options(confOptions(schemaOptions));
42+
},
43+
async (argv) => {
44+
await Auth.login().then(Config.setTokenOptions);
45+
await CommandSchemaPush(
46+
argv as Pick<
47+
ConfigurationOptions,
48+
'namespace' | 'project' | 'projectVersion' | 'schemaDir'
49+
>,
50+
);
51+
},
52+
);
53+
},
54+
} as CommandModule;

packages/cli/src/commands/common/schema.ts renamed to packages/cli/src/commands/schema/pull.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HandleTemplates } from '@/common/index.js';
33
import { Editor } from '@/Editor.js';
44
import path from 'path';
55

6-
export const CommandSchema = async ({
6+
export const CommandSchemaPull = async ({
77
schemaDir,
88
namespace,
99
project,

0 commit comments

Comments
 (0)