@genql/cli
Advanced tools
Comparing version 2.3.3 to 2.4.0
@@ -108,3 +108,3 @@ #!/usr/bin/env node | ||
useYarn: false, | ||
dependencies: [`@genql/runtime@${version_1.version}`], | ||
dependencies: [`@genql/runtime@${version_1.version}`, 'graphql'], | ||
}); | ||
@@ -111,0 +111,0 @@ }); |
@@ -20,3 +20,3 @@ "use strict"; | ||
const rimraf_1 = __importDefault(require("rimraf")); | ||
exports.ensurePath = (path, clear = false) => __awaiter(void 0, void 0, void 0, function* () { | ||
const ensurePath = (path, clear = false) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (clear) | ||
@@ -28,3 +28,3 @@ yield new Promise((rs, rj) => { | ||
else | ||
rs(); | ||
rs(undefined); | ||
}); | ||
@@ -37,10 +37,15 @@ }); | ||
else | ||
rs(); | ||
rs(undefined); | ||
}); | ||
}); | ||
}); | ||
exports.requireModuleFromPath = (path) => require(path_1.resolve(...path)); | ||
exports.readFileFromPath = (path) => fs_1.promises.readFile(path_1.resolve(...path)).then((b) => b.toString()); | ||
exports.writeFileToPath = (path, content) => fs_1.promises.writeFile(path_1.resolve(...path), content); | ||
exports.readFilesAndConcat = (files) => Promise.all(files.map((file) => exports.readFileFromPath([file]))).then((contents) => contents.join('\n')); | ||
exports.ensurePath = ensurePath; | ||
const requireModuleFromPath = (path) => require(path_1.resolve(...path)); | ||
exports.requireModuleFromPath = requireModuleFromPath; | ||
const readFileFromPath = (path) => fs_1.promises.readFile(path_1.resolve(...path)).then((b) => b.toString()); | ||
exports.readFileFromPath = readFileFromPath; | ||
const writeFileToPath = (path, content) => fs_1.promises.writeFile(path_1.resolve(...path), content); | ||
exports.writeFileToPath = writeFileToPath; | ||
const readFilesAndConcat = (files) => Promise.all(files.map((file) => exports.readFileFromPath([file]))).then((contents) => contents.join('\n')); | ||
exports.readFilesAndConcat = readFilesAndConcat; | ||
//# sourceMappingURL=files.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const parser_typescript_1 = __importDefault(require("prettier/parser-typescript")); | ||
exports.prettify = (code, parser) => { | ||
const prettify = (code, parser) => { | ||
// return code | ||
@@ -22,2 +22,3 @@ return standalone_1.default.format(code, { | ||
}; | ||
exports.prettify = prettify; | ||
//# sourceMappingURL=prettify.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const schemaTask_1 = require("./tasks/schemaTask"); | ||
exports.generate = (config) => { | ||
const generate = (config) => { | ||
if (!config.output) { | ||
@@ -28,2 +28,3 @@ throw new Error('`output` must be defined in the config'); | ||
}; | ||
exports.generate = generate; | ||
//# sourceMappingURL=main.js.map |
@@ -11,6 +11,7 @@ "use strict"; | ||
const support_1 = require("../common/support"); | ||
exports.chainTypeName = (type, wrapper) => { | ||
const chainTypeName = (type, wrapper) => { | ||
return `${type.name}${wrapper}Chain`; | ||
}; | ||
exports.objectType = (type, ctx, wrapper) => { | ||
exports.chainTypeName = chainTypeName; | ||
const objectType = (type, ctx, wrapper) => { | ||
var _a; | ||
@@ -60,2 +61,3 @@ // console.log(Object.keys(type.getFields())) | ||
}; | ||
exports.objectType = objectType; | ||
//# sourceMappingURL=objectType.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
const support_1 = require("../common/support"); | ||
exports.renderChainTypes = (schema, ctx) => { | ||
const renderChainTypes = (schema, ctx) => { | ||
var _a; | ||
@@ -24,2 +24,3 @@ const typeMap = ((_a = ctx.config) === null || _a === void 0 ? void 0 : _a.sortProperties) ? support_1.sortKeys(schema.getTypeMap()) | ||
}; | ||
exports.renderChainTypes = renderChainTypes; | ||
//# sourceMappingURL=renderChainTypes.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const config_1 = require("../../config"); | ||
const version_1 = require("../../version"); | ||
const { version } = require('../../../package.json'); | ||
const renderClientCode = (ctx) => { | ||
@@ -25,3 +25,3 @@ var _a; | ||
}; | ||
exports.renderClientCjs = (_, ctx) => { | ||
const renderClientCjs = (_, ctx) => { | ||
ctx.addCodeBlock(` | ||
@@ -36,3 +36,3 @@ const { | ||
var version = '${version_1.version}' | ||
var version = '${version}' | ||
assertSameVersion(version) | ||
@@ -63,3 +63,4 @@ | ||
}; | ||
exports.renderClientEsm = (_, ctx) => { | ||
exports.renderClientCjs = renderClientCjs; | ||
const renderClientEsm = (_, ctx) => { | ||
ctx.addCodeBlock(` | ||
@@ -76,3 +77,3 @@ import { | ||
export var version = '${version_1.version}' | ||
export var version = ${JSON.stringify(version)} | ||
assertSameVersion(version) | ||
@@ -96,2 +97,3 @@ | ||
}; | ||
exports.renderClientEsm = renderClientEsm; | ||
//# sourceMappingURL=renderClient.js.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
const config_1 = require("../../config"); | ||
exports.renderClientDefinition = (schema, ctx) => { | ||
const renderClientDefinition = (schema, ctx) => { | ||
const queryType = schema.getQueryType(); | ||
@@ -30,2 +30,3 @@ const mutationType = schema.getMutationType(); | ||
}; | ||
exports.renderClientDefinition = renderClientDefinition; | ||
function renderClientTypesImports({ queryType, mutationType, subscriptionType, }) { | ||
@@ -32,0 +33,0 @@ const imports = []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.argumentComment = exports.fieldComment = exports.typeComment = exports.comment = void 0; | ||
exports.comment = (comment) => { | ||
const comment = (comment) => { | ||
const lines = []; | ||
@@ -18,12 +18,16 @@ if (comment.deprecated) { | ||
}; | ||
exports.typeComment = (type) => exports.comment({ | ||
exports.comment = comment; | ||
const typeComment = (type) => exports.comment({ | ||
text: type.description, | ||
}); | ||
exports.fieldComment = (field) => exports.comment({ | ||
exports.typeComment = typeComment; | ||
const fieldComment = (field) => exports.comment({ | ||
deprecated: field.deprecationReason, | ||
text: field.description, | ||
}); | ||
exports.argumentComment = (arg) => exports.comment({ | ||
exports.fieldComment = fieldComment; | ||
const argumentComment = (arg) => exports.comment({ | ||
text: arg.description, | ||
}); | ||
exports.argumentComment = argumentComment; | ||
//# sourceMappingURL=comment.js.map |
@@ -8,6 +8,7 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
exports.relativeImportPath = (from, to) => { | ||
const relativeImportPath = (from, to) => { | ||
const fromResolved = path_1.default.relative(from, to); | ||
return fromResolved[0] === '.' ? fromResolved : `./${fromResolved}`; | ||
}; | ||
exports.relativeImportPath = relativeImportPath; | ||
//# sourceMappingURL=relativeImportPath.js.map |
@@ -45,3 +45,4 @@ "use strict"; | ||
}; | ||
exports.renderTyping = (type, undefinableValues, undefinableFields, root = true, wrap = undefined) => render(type, false, root, undefinableValues, undefinableFields, wrap); | ||
const renderTyping = (type, undefinableValues, undefinableFields, root = true, wrap = undefined) => render(type, false, root, undefinableValues, undefinableFields, wrap); | ||
exports.renderTyping = renderTyping; | ||
//# sourceMappingURL=renderTyping.js.map |
export declare function sortKeys(obj: Record<any, any>): Record<any, any>; | ||
export declare function intersection<T>(a: T[][]): T[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sortKeys = void 0; | ||
exports.intersection = exports.sortKeys = void 0; | ||
function sortKeys(obj) { | ||
@@ -16,2 +16,6 @@ obj = obj || {}; | ||
exports.sortKeys = sortKeys; | ||
function intersection(a) { | ||
return a.reduce((p, c) => p.filter((e) => c.includes(e))); | ||
} | ||
exports.intersection = intersection; | ||
//# sourceMappingURL=support.js.map |
@@ -6,5 +6,6 @@ "use strict"; | ||
const renderTyping_1 = require("./renderTyping"); | ||
exports.toArgsString = (field) => { | ||
const toArgsString = (field) => { | ||
return `{${field.args.map(a => `${comment_1.argumentComment(a)}${a.name}${renderTyping_1.renderTyping(a.type, false, true)}`).join(',')}}`; | ||
}; | ||
exports.toArgsString = toArgsString; | ||
//# sourceMappingURL=toArgsString.js.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
const support_1 = require("../common/support"); | ||
exports.inputObjectType = (type, ctx) => { | ||
const inputObjectType = (type, ctx) => { | ||
var _a; | ||
@@ -20,2 +20,3 @@ let fields = type.getFields(); | ||
}; | ||
exports.inputObjectType = inputObjectType; | ||
//# sourceMappingURL=inputObjectType.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const INDENTATION = ' '; | ||
exports.objectType = (type, ctx) => { | ||
const objectType = (type, ctx) => { | ||
var _a, _b; | ||
@@ -62,2 +62,3 @@ let fields = type.getFields(); | ||
}; | ||
exports.objectType = objectType; | ||
//# sourceMappingURL=objectType.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const support_1 = require("../common/support"); | ||
exports.renderRequestTypes = (schema, ctx) => { | ||
const renderRequestTypes = (schema, ctx) => { | ||
var _a; | ||
@@ -38,2 +38,3 @@ let typeMap = schema.getTypeMap(); | ||
}; | ||
exports.renderRequestTypes = renderRequestTypes; | ||
function renderAlias({ type, name, }) { | ||
@@ -40,0 +41,0 @@ if (type && type.name + 'Request' !== name) { // TODO make the camel case or kebab case an option |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.requestTypeName = void 0; | ||
exports.requestTypeName = (type) => `${type.name}Request`; | ||
const requestTypeName = (type) => `${type.name}Request`; | ||
exports.requestTypeName = requestTypeName; | ||
//# sourceMappingURL=requestTypeName.js.map |
@@ -5,4 +5,5 @@ "use strict"; | ||
const comment_1 = require("../common/comment"); | ||
const support_1 = require("../common/support"); | ||
const requestTypeName_1 = require("./requestTypeName"); | ||
exports.unionType = (type, ctx) => { | ||
const unionType = (type, ctx) => { | ||
var _a; | ||
@@ -13,6 +14,11 @@ let types = type.getTypes(); | ||
} | ||
const fieldStrings = types.map(t => `on_${t.name}?:${requestTypeName_1.requestTypeName(t)}`); | ||
fieldStrings.push('__typename?:boolean | number'); | ||
ctx.addCodeBlock(`${comment_1.typeComment(type)}export interface ${requestTypeName_1.requestTypeName(type)}{${fieldStrings.join(',')}}`); | ||
const fieldStrings = types.map((t) => `on_${t.name}?:${requestTypeName_1.requestTypeName(t)}`); | ||
const commonInterfaces = support_1.intersection(types.map((x) => x.getInterfaces())); | ||
fieldStrings.push(...commonInterfaces.map((type) => { | ||
return `on_${type.name}?: ${requestTypeName_1.requestTypeName(type)}`; | ||
})); | ||
fieldStrings.push('__typename?: boolean | number'); | ||
ctx.addCodeBlock(`${comment_1.typeComment(type)}export interface ${requestTypeName_1.requestTypeName(type)}{\n${fieldStrings.map((x) => ' ' + x).join(',\n')}\n}`); | ||
}; | ||
exports.unionType = unionType; | ||
//# sourceMappingURL=unionType.js.map |
@@ -5,6 +5,7 @@ "use strict"; | ||
const comment_1 = require("../common/comment"); | ||
exports.enumType = (type, ctx) => { | ||
const enumType = (type, ctx) => { | ||
const values = type.getValues().map(v => `'${v.name}'`); | ||
ctx.addCodeBlock(`${comment_1.typeComment(type)}export type ${type.name} = ${values.join(' | ')}`); | ||
}; | ||
exports.enumType = enumType; | ||
//# sourceMappingURL=enumType.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const comment_1 = require("../common/comment"); | ||
exports.interfaceType = (type, ctx) => { | ||
const interfaceType = (type, ctx) => { | ||
if (!ctx.schema) { | ||
@@ -13,2 +13,3 @@ throw new Error('schema is required to render unionType'); | ||
}; | ||
exports.interfaceType = interfaceType; | ||
// interface should produce an object like | ||
@@ -15,0 +16,0 @@ // export type Nameable = { |
@@ -9,3 +9,3 @@ "use strict"; | ||
const INDENTATION = ' '; | ||
exports.objectType = (type, ctx) => { | ||
const objectType = (type, ctx) => { | ||
var _a; | ||
@@ -45,2 +45,3 @@ let fieldsMap = type.getFields(); | ||
}; | ||
exports.objectType = objectType; | ||
//# sourceMappingURL=objectType.js.map |
@@ -12,3 +12,3 @@ "use strict"; | ||
const support_1 = require("../common/support"); | ||
exports.renderResponseTypes = (schema, ctx) => { | ||
const renderResponseTypes = (schema, ctx) => { | ||
var _a; | ||
@@ -43,2 +43,3 @@ let typeMap = schema.getTypeMap(); | ||
}; | ||
exports.renderResponseTypes = renderResponseTypes; | ||
function renderAlias({ type, name, }) { | ||
@@ -45,0 +46,0 @@ if (type && type.name !== name) { |
@@ -11,3 +11,3 @@ "use strict"; | ||
}; | ||
exports.getTypeMappedAlias = (type, ctx) => { | ||
const getTypeMappedAlias = (type, ctx) => { | ||
var _a; | ||
@@ -17,2 +17,3 @@ const map = Object.assign(Object.assign({}, knownTypes), (((_a = ctx === null || ctx === void 0 ? void 0 : ctx.config) === null || _a === void 0 ? void 0 : _a.scalarTypes) || {})); | ||
}; | ||
exports.getTypeMappedAlias = getTypeMappedAlias; | ||
// export const renderTypeMappedAlias = ( | ||
@@ -19,0 +20,0 @@ // type: GraphQLNamedType, |
@@ -13,3 +13,3 @@ "use strict"; | ||
// } | ||
exports.unionType = (type, ctx) => { | ||
const unionType = (type, ctx) => { | ||
var _a; | ||
@@ -22,2 +22,3 @@ let typeNames = type.getTypes().map((t) => t.name); | ||
}; | ||
exports.unionType = unionType; | ||
// export const unionType = (type: GraphQLUnionType, ctx: RenderContext) => { | ||
@@ -24,0 +25,0 @@ // const typeNames = type.getTypes().map((t) => t.name) |
@@ -5,5 +5,6 @@ "use strict"; | ||
const graphql_1 = require("graphql"); | ||
exports.renderSchema = (schema, ctx) => { | ||
const renderSchema = (schema, ctx) => { | ||
ctx.addCodeBlock(graphql_1.printSchema(schema)); | ||
}; | ||
exports.renderSchema = renderSchema; | ||
//# sourceMappingURL=renderSchema.js.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
`; | ||
exports.renderTypeGuards = (schema, ctx, isJs = 'ts') => { | ||
const renderTypeGuards = (schema, ctx, isJs = 'ts') => { | ||
const typeMap = schema.getTypeMap(); | ||
@@ -41,2 +41,3 @@ for (const name in typeMap) { | ||
}; | ||
exports.renderTypeGuards = renderTypeGuards; | ||
//# sourceMappingURL=renderTypeGuards.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
const support_1 = require("./support"); | ||
exports.objectType = (type, ctx) => { | ||
const objectType = (type, ctx) => { | ||
const typeObj = Object.keys(type.getFields()).reduce((r, f) => { | ||
@@ -45,2 +45,3 @@ const field = type.getFields()[f]; | ||
}; | ||
exports.objectType = objectType; | ||
//# sourceMappingURL=objectType.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
const unionType_1 = require("./unionType"); | ||
exports.renderTypeMap = (schema, ctx) => { | ||
const renderTypeMap = (schema, ctx) => { | ||
// remove fields key, | ||
@@ -52,2 +52,3 @@ // remove the Type.type and Type.args, replace with [type, args] | ||
}; | ||
exports.renderTypeMap = renderTypeMap; | ||
function replaceTypeNamesWithIndexes(typeMap) { | ||
@@ -54,0 +55,0 @@ const nameToIndex = Object.assign({}, ...Object.keys(typeMap.types).map((k, i) => ({ [k]: i }))); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.scalarType = void 0; | ||
exports.scalarType = (type, _) => ({}); | ||
const scalarType = (type, _) => ({}); | ||
exports.scalarType = scalarType; | ||
//# sourceMappingURL=scalarType.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unionType = void 0; | ||
exports.unionType = (type, _) => { | ||
const typeObj = type | ||
.getTypes() | ||
.reduce((r, t) => { | ||
const support_1 = require("../common/support"); | ||
const unionType = (type, _) => { | ||
const types = type.getTypes(); | ||
const typeObj = types.reduce((r, t) => { | ||
r[`on_${t.name}`] = { type: t.name }; | ||
return r; | ||
}, {}); | ||
const commonInterfaces = support_1.intersection(types.map((x) => x.getInterfaces())); | ||
commonInterfaces.forEach((t) => { | ||
typeObj[`on_${t.name}`] = { type: t.name }; | ||
}); | ||
typeObj.__typename = { type: 'String' }; | ||
return typeObj; | ||
}; | ||
exports.unionType = unionType; | ||
//# sourceMappingURL=unionType.js.map |
@@ -19,3 +19,3 @@ "use strict"; | ||
const qs_1 = __importDefault(require("qs")); | ||
exports.fetchSchema = ({ endpoint, usePost = false, headers, options, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const fetchSchema = ({ endpoint, usePost = false, headers, options, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const response = yield isomorphic_unfetch_1.default(usePost | ||
@@ -47,3 +47,4 @@ ? endpoint | ||
}); | ||
exports.customFetchSchema = (fetcher, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.fetchSchema = fetchSchema; | ||
const customFetchSchema = (fetcher, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield fetcher(graphql_1.getIntrospectionQuery(), isomorphic_unfetch_1.default, qs_1.default); | ||
@@ -55,2 +56,3 @@ if (!result.data) { | ||
}); | ||
exports.customFetchSchema = customFetchSchema; | ||
//# sourceMappingURL=fetchSchema.js.map |
@@ -35,3 +35,3 @@ "use strict"; | ||
const clientTypesFile = 'index.d.ts'; | ||
exports.clientTasks = (config) => { | ||
const clientTasks = (config) => { | ||
const clientFileEsm = config.onlyEsModules ? 'index.js' : 'index.esm.js'; | ||
@@ -126,2 +126,3 @@ if (!config.output) | ||
}; | ||
exports.clientTasks = clientTasks; | ||
//# sourceMappingURL=clientTasks.js.map |
@@ -18,3 +18,3 @@ "use strict"; | ||
const load_1 = require("@graphql-tools/load"); | ||
exports.schemaTask = (config) => { | ||
const schemaTask = (config) => { | ||
const processSchema = (schema) => { | ||
@@ -64,2 +64,3 @@ if (config.sortProperties) { | ||
}; | ||
exports.schemaTask = schemaTask; | ||
//# sourceMappingURL=schemaTask.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
exports.validateConfigs = (configs) => { | ||
const validateConfigs = (configs) => { | ||
const errors = []; | ||
@@ -25,2 +25,3 @@ if (configs.length === 0) | ||
}; | ||
exports.validateConfigs = validateConfigs; | ||
//# sourceMappingURL=validateConfigs.js.map |
@@ -16,3 +16,3 @@ "use strict"; | ||
const files_1 = require("../helpers/files"); | ||
exports.toClientSchema = (schemaGql) => __awaiter(void 0, void 0, void 0, function* () { | ||
const toClientSchema = (schemaGql) => __awaiter(void 0, void 0, void 0, function* () { | ||
const schema = graphql_1.buildSchema(schemaGql); | ||
@@ -25,3 +25,4 @@ const introspectionResponse = yield graphql_1.graphql(schema, graphql_1.getIntrospectionQuery()); | ||
}); | ||
exports.schemaRenderTest = (schemaGql, renderer, parser) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.toClientSchema = toClientSchema; | ||
const schemaRenderTest = (schemaGql, renderer, parser) => __awaiter(void 0, void 0, void 0, function* () { | ||
const schema = yield exports.toClientSchema(schemaGql); | ||
@@ -32,3 +33,4 @@ const ctx = new RenderContext_1.RenderContext(schema); | ||
}); | ||
exports.typeRenderTest = (schemaGql, renderer, typeNames, parser) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.schemaRenderTest = schemaRenderTest; | ||
const typeRenderTest = (schemaGql, renderer, typeNames, parser) => __awaiter(void 0, void 0, void 0, function* () { | ||
const schema = yield exports.toClientSchema(schemaGql); | ||
@@ -45,3 +47,4 @@ const ctx = new RenderContext_1.RenderContext(schema); | ||
}); | ||
exports.typeRenderTestCase = (dirName, file, renderer, typeNames, output = false) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.typeRenderTest = typeRenderTest; | ||
const typeRenderTestCase = (dirName, file, renderer, typeNames, output = false) => __awaiter(void 0, void 0, void 0, function* () { | ||
const [gql, ts] = yield Promise.all([ | ||
@@ -60,2 +63,3 @@ files_1.readFileFromPath([dirName, `cases/${file}.graphql`]), | ||
}); | ||
exports.typeRenderTestCase = typeRenderTestCase; | ||
//# sourceMappingURL=render.js.map |
{ | ||
"name": "@genql/cli", | ||
"_": "[bump]", | ||
"version": "2.3.3", | ||
"version": "2.4.0", | ||
"description": "Generate a client sdl from your GraphQl API", | ||
@@ -29,3 +29,3 @@ "main": "dist/index.js", | ||
"compile": "sucrase -q ./src -d ./dist --transforms typescript,imports", | ||
"dev": "yarn compile && node dist" | ||
"watch": "tsc -w" | ||
}, | ||
@@ -50,7 +50,6 @@ "keywords": [], | ||
"sucrase": "^3.12.1", | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^4.0.2" | ||
"ts-jest": "^23.10.5" | ||
}, | ||
"dependencies": { | ||
"@genql/runtime": "^2.3.3", | ||
"@genql/runtime": "^2.4.0", | ||
"@graphql-tools/graphql-file-loader": "^6.0.10", | ||
@@ -101,3 +100,3 @@ "@graphql-tools/load": "^6.0.10", | ||
}, | ||
"gitHead": "d684f2821719a56b9e47d47931e198e3249f8068" | ||
"gitHead": "cabb8773868e2100852c492912cae6604ee7049e" | ||
} |
@@ -118,3 +118,3 @@ #!/usr/bin/env node | ||
useYarn: false, | ||
dependencies: [`@genql/runtime@${version}`], | ||
dependencies: [`@genql/runtime@${version}`, 'graphql'], | ||
}) | ||
@@ -121,0 +121,0 @@ }) |
@@ -11,3 +11,3 @@ import { promises as fs } from 'fs' | ||
if (err) rj(err) | ||
else rs() | ||
else rs(undefined) | ||
}) | ||
@@ -19,3 +19,3 @@ }) | ||
if (err) rj(err) | ||
else rs() | ||
else rs(undefined) | ||
}) | ||
@@ -22,0 +22,0 @@ }) |
import { GraphQLSchema } from 'graphql' | ||
import { RenderContext } from '../common/RenderContext' | ||
import { RUNTIME_LIB_NAME } from '../../config' | ||
import { version } from '../../version' | ||
const { version } = require('../../../package.json') | ||
@@ -73,3 +73,3 @@ const renderClientCode = (ctx: RenderContext) => { | ||
export var version = '${version}' | ||
export var version = ${JSON.stringify(version)} | ||
assertSameVersion(version) | ||
@@ -76,0 +76,0 @@ |
@@ -12,1 +12,5 @@ export function sortKeys(obj: Record<any, any>): Record<any, any> { | ||
} | ||
export function intersection<T>(a: T[][]): T[] { | ||
return a.reduce((p, c) => p.filter((e) => c.includes(e))) | ||
} |
import { GraphQLUnionType } from 'graphql' | ||
import { typeComment } from '../common/comment' | ||
import { RenderContext } from '../common/RenderContext' | ||
import { intersection } from '../common/support' | ||
import { requestTypeName } from './requestTypeName' | ||
export const unionType = (type: GraphQLUnionType, ctx: RenderContext) => { | ||
let types = type.getTypes() | ||
if (ctx.config?.sortProperties) { | ||
types = types.sort() | ||
} | ||
const fieldStrings = types.map(t => `on_${t.name}?:${requestTypeName(t)}`) | ||
let types = type.getTypes() | ||
if (ctx.config?.sortProperties) { | ||
types = types.sort() | ||
} | ||
const fieldStrings = types.map((t) => `on_${t.name}?:${requestTypeName(t)}`) | ||
const commonInterfaces = intersection(types.map((x) => x.getInterfaces())) | ||
fieldStrings.push( | ||
...commonInterfaces.map((type) => { | ||
return `on_${type.name}?: ${requestTypeName(type)}` | ||
}), | ||
) | ||
fieldStrings.push('__typename?:boolean | number') | ||
fieldStrings.push('__typename?: boolean | number') | ||
ctx.addCodeBlock(`${typeComment(type)}export interface ${requestTypeName(type)}{${fieldStrings.join(',')}}`) | ||
ctx.addCodeBlock( | ||
`${typeComment(type)}export interface ${requestTypeName( | ||
type, | ||
)}{\n${fieldStrings.map((x) => ' ' + x).join(',\n')}\n}`, | ||
) | ||
} |
import { GraphQLUnionType } from 'graphql' | ||
import { RenderContext } from '../common/RenderContext' | ||
import { FieldMap, Type } from '@genql/runtime/dist/types' | ||
import { intersection } from '../common/support' | ||
export const unionType = (type: GraphQLUnionType, _: RenderContext) => { | ||
const typeObj: FieldMap<string> = type | ||
.getTypes() | ||
.reduce<FieldMap<string>>((r, t) => { | ||
r[`on_${t.name}`] = { type: t.name } | ||
return r | ||
}, {}) | ||
const types = type.getTypes() | ||
const typeObj: FieldMap<string> = types.reduce<FieldMap<string>>((r, t) => { | ||
r[`on_${t.name}`] = { type: t.name } | ||
return r | ||
}, {}) | ||
const commonInterfaces = intersection(types.map((x) => x.getInterfaces())) | ||
commonInterfaces.forEach((t) => { | ||
typeObj[`on_${t.name}`] = { type: t.name } | ||
}) | ||
typeObj.__typename = { type: 'String' } | ||
@@ -14,0 +19,0 @@ |
@@ -1,4 +0,2 @@ | ||
const { version } = require('../package.json') | ||
export { version } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
243252
15
4637
Updated@genql/runtime@^2.4.0