scripts: add graphql:codegen script

This commit is contained in:
vchikalkin 2023-02-07 12:29:10 +03:00
parent 751d18889d
commit 576f9092bd
6 changed files with 32 additions and 10 deletions

View File

@ -9,6 +9,7 @@
"lint:fix": "next lint -- --fix",
"start": "next start",
"graphql:update": "node ./scripts/graphql-update.js",
"graphql:codegen": "node ./scripts/graphql-codegen.js",
"test": "jest"
},
"dependencies": {

View File

@ -0,0 +1,3 @@
const { generateTypescript } = require('./lib/graphql');
generateTypescript();

View File

@ -1,10 +1,4 @@
const run = require('tools/scripts');
const { downloadSchema, generateTypescript } = require('./lib/graphql');
const { URL_CRM_GRAPHQL_DIRECT } = process.env;
const PATH_CRM_GRAPHQL_SCHEMA = './graphql/crm.schema.graphql';
const command1 = ['gql-sdl', URL_CRM_GRAPHQL_DIRECT, '-o', PATH_CRM_GRAPHQL_SCHEMA].join(' ');
run(command1, 'Download GraphQL Schema...');
const command2 = ['graphql-codegen,', '--config', '.graphqlrc.yml'].join(' ');
run(command2, 'Generating TypeScript code...');
downloadSchema();
generateTypescript();

View File

@ -0,0 +1,18 @@
const run = require('tools/scripts');
function downloadSchema() {
const { URL_CRM_GRAPHQL_DIRECT } = process.env;
const PATH_CRM_GRAPHQL_SCHEMA = './graphql/crm.schema.graphql';
const command1 = ['gql-sdl', URL_CRM_GRAPHQL_DIRECT, '-o', PATH_CRM_GRAPHQL_SCHEMA].join(' ');
run(command1, 'Download GraphQL Schema...');
}
function generateTypescript() {
const command2 = ['graphql-codegen,', '--config', '.graphqlrc.yml'].join(' ');
run(command2, 'Generating TypeScript code...');
}
module.exports = {
downloadSchema,
generateTypescript,
};

View File

@ -16,7 +16,8 @@
"test": "dotenv -e .env.local turbo run test",
"prepare": "husky install",
"precommit": "yarn format && yarn lint:fix && yarn test",
"graphql:update": "dotenv -e .env.local node ./scripts/graphql-update.js"
"graphql:update": "dotenv -e .env.local node ./scripts/graphql-update.js",
"graphql:codegen": "dotenv -e .env.local node ./scripts/graphql-codegen.js"
},
"dependencies": {},
"devDependencies": {

View File

@ -0,0 +1,5 @@
const run = require('tools/scripts');
const command = ['yarn', 'workspace', 'web', 'graphql:codegen'].join(' ');
run(command, '*** Update GraphQL files ***');