Comparing version 0.15.3 to 0.15.4
52
index.js
@@ -15,3 +15,2 @@ 'use strict'; | ||
const titleCase = require('title-case'); | ||
const definition = require('graphql/type/definition'); | ||
@@ -719,3 +718,3 @@ function getOperationInfo(doc) { | ||
const enumTypes = resolveEnumTypes(schema); | ||
const summary = resolveSummary(schema, info.operation); | ||
const summary = resolveDescription(schema, info.operation); | ||
return Object.assign(Object.assign({ tags, | ||
@@ -728,5 +727,3 @@ description, | ||
'application/json': { | ||
schema: resolveRequestBody(info.operation.variableDefinitions, { | ||
customScalars, enumTypes | ||
}), | ||
schema: resolveRequestBody(info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }), | ||
}, | ||
@@ -737,3 +734,3 @@ }, | ||
: { | ||
parameters: resolveParameters(url, info.operation.variableDefinitions, { customScalars, enumTypes }), | ||
parameters: resolveParameters(url, info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }), | ||
})), { responses: { | ||
@@ -755,11 +752,13 @@ 200: { | ||
function resolveEnumTypes(schema) { | ||
const enumTypes = Object.values(schema.getTypeMap()).filter(graphql.isEnumType).map(definition.assertEnumType); | ||
return Object.fromEntries(enumTypes.map(type => ([type.name, | ||
const enumTypes = Object.values(schema.getTypeMap()) | ||
.filter(graphql.isEnumType); | ||
return Object.fromEntries(enumTypes.map((type) => [ | ||
type.name, | ||
{ | ||
type: 'string', | ||
enum: type.getValues().map(value => value.name), | ||
enum: type.getValues().map((value) => value.name), | ||
}, | ||
]))); | ||
])); | ||
} | ||
function resolveParameters(url, variables, opts) { | ||
function resolveParameters(url, variables, schema, operation, opts) { | ||
if (!variables) { | ||
@@ -774,6 +773,7 @@ return []; | ||
schema: resolveParamSchema(variable.type, opts), | ||
description: resolveVariableDescription(schema, operation, variable), | ||
}; | ||
}); | ||
} | ||
function resolveRequestBody(variables, opts) { | ||
function resolveRequestBody(variables, schema, operation, opts) { | ||
if (!variables) { | ||
@@ -788,3 +788,3 @@ return {}; | ||
} | ||
properties[variable.variable.name.value] = resolveParamSchema(variable.type, opts); | ||
properties[variable.variable.name.value] = Object.assign(Object.assign({}, resolveParamSchema(variable.type, opts)), { description: resolveVariableDescription(schema, operation, variable) }); | ||
}); | ||
@@ -809,4 +809,3 @@ return Object.assign({ type: 'object', properties }, (required.length ? { required } : {})); | ||
opts.customScalars[type.name.value] || | ||
opts.enumTypes[type.name.value] || | ||
{ $ref: mapToRef(type.name.value) }); | ||
opts.enumTypes[type.name.value] || { $ref: mapToRef(type.name.value) }); | ||
} | ||
@@ -832,3 +831,3 @@ function resolveResponse({ schema, operation, opts, }) { | ||
} | ||
function resolveSummary(schema, operation) { | ||
function getOperationFieldNode(schema, operation) { | ||
const selection = operation.selectionSet.selections[0]; | ||
@@ -838,14 +837,21 @@ const fieldName = selection.name.value; | ||
if (!typeDefinition) { | ||
return ''; | ||
return undefined; | ||
} | ||
const definitionNode = typeDefinition.astNode || graphql.parse(graphql.printType(typeDefinition)).definitions[0]; | ||
if (!isObjectTypeDefinitionNode(definitionNode)) { | ||
return ''; | ||
return undefined; | ||
} | ||
const fieldNode = definitionNode.fields.find((field) => field.name.value === fieldName); | ||
const descriptionDefinition = fieldNode && fieldNode.description; | ||
return descriptionDefinition && descriptionDefinition.value | ||
? descriptionDefinition.value | ||
: ''; | ||
return definitionNode.fields.find((field) => field.name.value === fieldName); | ||
} | ||
function resolveDescription(schema, operation) { | ||
var _a; | ||
const fieldNode = getOperationFieldNode(schema, operation); | ||
return ((_a = fieldNode === null || fieldNode === void 0 ? void 0 : fieldNode.description) === null || _a === void 0 ? void 0 : _a.value) || ''; | ||
} | ||
function resolveVariableDescription(schema, operation, variable) { | ||
var _a, _b; | ||
const fieldNode = getOperationFieldNode(schema, operation); | ||
const argument = (_a = fieldNode === null || fieldNode === void 0 ? void 0 : fieldNode.arguments) === null || _a === void 0 ? void 0 : _a.find((arg) => arg.name.value === variable.variable.name.value); | ||
return (_b = argument === null || argument === void 0 ? void 0 : argument.description) === null || _b === void 0 ? void 0 : _b.value; | ||
} | ||
function isObjectTypeDefinitionNode(node) { | ||
@@ -852,0 +858,0 @@ return node.kind === graphql.Kind.OBJECT_TYPE_DEFINITION; |
{ | ||
"name": "sofa-api", | ||
"version": "0.15.3", | ||
"version": "0.15.4", | ||
"description": "Create REST APIs with GraphQL", | ||
@@ -10,3 +10,3 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@graphql-tools/utils": "9.1.3", | ||
"@graphql-tools/utils": "9.1.4", | ||
"@whatwg-node/fetch": "^0.6.0", | ||
@@ -13,0 +13,0 @@ "@whatwg-node/router": "^0.1.2", |
Sorry, the diff of this file is not supported yet
88293
1970
+ Added@graphql-tools/utils@9.1.4(transitive)
- Removed@graphql-tools/utils@9.1.3(transitive)
Updated@graphql-tools/utils@9.1.4