Comparing version 0.5.1 to 0.6.0
@@ -5,2 +5,7 @@ # Change log | ||
### v0.6.0 | ||
- fix(swagger): fix descriptions [PR #178](https://github.com/Urigo/SOFA/pull/178) | ||
- feat: support GraphQL Interfaces [PR #167](https://github.com/Urigo/SOFA/pull/167) | ||
### v0.5.1 | ||
@@ -7,0 +12,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const ast_1 = require("../ast"); | ||
@@ -105,5 +106,11 @@ const utils_1 = require("./utils"); | ||
const typeDefinition = schema.getType(titleCase(operation.operation)); | ||
const definitionNode = typeDefinition.astNode; | ||
if (!typeDefinition) { | ||
return ''; | ||
} | ||
const definitionNode = typeDefinition.astNode || graphql_1.parse(graphql_1.printType(typeDefinition)).definitions[0]; | ||
if (!isObjectTypeDefinitionNode(definitionNode)) { | ||
return ''; | ||
} | ||
const fieldNode = definitionNode.fields.find(field => field.name.value === fieldName); | ||
const descriptionDefinition = fieldNode.description; | ||
const descriptionDefinition = fieldNode && fieldNode.description; | ||
return descriptionDefinition && descriptionDefinition.value | ||
@@ -113,2 +120,5 @@ ? descriptionDefinition.value | ||
} | ||
function isObjectTypeDefinitionNode(node) { | ||
return node.kind === 'ObjectTypeDefinition'; | ||
} | ||
//# sourceMappingURL=operations.js.map |
@@ -15,4 +15,7 @@ "use strict"; | ||
properties[fieldName] = resolveField(field); | ||
if (field.description) { | ||
properties[fieldName].description = field.description; | ||
} | ||
} | ||
return Object.assign(Object.assign({ type: 'object' }, (required.length ? { required } : {})), { properties }); | ||
return Object.assign(Object.assign(Object.assign({ type: 'object' }, (required.length ? { required } : {})), { properties }), (type.description ? { description: type.description } : {})); | ||
} | ||
@@ -19,0 +22,0 @@ exports.buildSchemaObjectFromType = buildSchemaObjectFromType; |
@@ -69,2 +69,3 @@ "use strict"; | ||
depthLimit, | ||
schema, | ||
}), | ||
@@ -80,3 +81,3 @@ ], | ||
} | ||
function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, }) { | ||
function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, schema, }) { | ||
if (graphql_1.isUnionType(type)) { | ||
@@ -91,3 +92,2 @@ const types = type.getTypes(); | ||
.map(t => { | ||
const fields = t.getFields(); | ||
return { | ||
@@ -102,16 +102,44 @@ kind: 'InlineFragment', | ||
}, | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: Object.keys(fields).map(fieldName => { | ||
return resolveField({ | ||
type: t, | ||
field: fields[fieldName], | ||
models, | ||
path: [...path, fieldName], | ||
ancestors, | ||
ignore, | ||
depthLimit, | ||
}); | ||
}), | ||
selectionSet: resolveSelectionSet({ | ||
parent: type, | ||
type: t, | ||
models, | ||
path, | ||
ancestors, | ||
ignore, | ||
depthLimit, | ||
schema, | ||
}), | ||
}; | ||
}), | ||
}; | ||
} | ||
if (graphql_1.isInterfaceType(type)) { | ||
const types = Object.values(schema.getTypeMap()).filter(t => graphql_1.isObjectType(t) && t.getInterfaces().includes(type)); | ||
return { | ||
kind: 'SelectionSet', | ||
selections: types | ||
.filter(t => !hasCircularRef([...ancestors, t], { | ||
depth: depthLimit, | ||
})) | ||
.map(t => { | ||
return { | ||
kind: 'InlineFragment', | ||
typeCondition: { | ||
kind: 'NamedType', | ||
name: { | ||
kind: 'Name', | ||
value: t.name, | ||
}, | ||
}, | ||
selectionSet: resolveSelectionSet({ | ||
parent: type, | ||
type: t, | ||
models, | ||
path, | ||
ancestors, | ||
ignore, | ||
depthLimit, | ||
schema, | ||
}), | ||
}; | ||
@@ -157,2 +185,3 @@ }), | ||
depthLimit, | ||
schema, | ||
}); | ||
@@ -200,3 +229,3 @@ }), | ||
} | ||
function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, }) { | ||
function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, schema, }) { | ||
const namedType = graphql_1.getNamedType(field.type); | ||
@@ -241,2 +270,3 @@ let args = []; | ||
depthLimit, | ||
schema, | ||
}), | ||
@@ -243,0 +273,0 @@ arguments: args, |
{ | ||
"name": "sofa-api", | ||
"description": "Create REST APIs with GraphQL", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"main": "dist/index.js", | ||
@@ -53,8 +53,8 @@ "typings": "dist/index.d.ts", | ||
"@types/graphql": "14.2.3", | ||
"@types/jest": "24.0.18", | ||
"@types/jest": "24.0.21", | ||
"@types/request-promise-native": "1.0.17", | ||
"@types/supertest": "2.0.8", | ||
"@types/swagger-ui-express": "3.0.1", | ||
"@types/uuid": "3.4.5", | ||
"@types/webpack": "4.39.2", | ||
"@types/uuid": "3.4.6", | ||
"@types/webpack": "4.39.7", | ||
"@types/yamljs": "0.2.30", | ||
@@ -67,15 +67,15 @@ "body-parser": "1.19.0", | ||
"graphql-tag": "2.10.1", | ||
"graphql-tools": "4.0.5", | ||
"husky": "3.0.7", | ||
"graphql-tools": "4.0.6", | ||
"husky": "3.0.9", | ||
"jest": "24.9.0", | ||
"lint-staged": "9.4.1", | ||
"lint-staged": "9.4.2", | ||
"prettier": "1.18.2", | ||
"supertest": "4.0.2", | ||
"swagger-ui-express": "4.1.1", | ||
"swagger-ui-express": "4.1.2", | ||
"ts-jest": "24.1.0", | ||
"ts-loader": "6.2.0", | ||
"ts-loader": "6.2.1", | ||
"ts-node": "8.4.1", | ||
"typescript": "3.6.3", | ||
"webpack": "4.41.0", | ||
"webpack-cli": "3.3.9" | ||
"typescript": "3.6.4", | ||
"webpack": "4.41.2", | ||
"webpack-cli": "3.3.10" | ||
}, | ||
@@ -82,0 +82,0 @@ "husky": { |
[![sofa](https://user-images.githubusercontent.com/25294569/63839869-bfac8300-c988-11e9-978e-6b6c16c350de.gif)](https://sofa-api.com) | ||
[![npm version](https://badge.fury.io/js/sofa-api.svg)](https://npmjs.com/package/sofa-api) | ||
[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9) | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
@@ -5,0 +6,0 @@ [![renovate-app badge](https://img.shields.io/badge/renovate-app-blue.svg)](https://renovateapp.com/) |
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
472721
51
1612
278