Comparing version 0.15.2 to 0.15.3
29
index.js
@@ -15,2 +15,3 @@ 'use strict'; | ||
const titleCase = require('title-case'); | ||
const definition = require('graphql/type/definition'); | ||
@@ -717,2 +718,3 @@ function getOperationInfo(doc) { | ||
const info = getOperationInfo(operation); | ||
const enumTypes = resolveEnumTypes(schema); | ||
const summary = resolveSummary(schema, info.operation); | ||
@@ -727,3 +729,3 @@ return Object.assign(Object.assign({ tags, | ||
schema: resolveRequestBody(info.operation.variableDefinitions, { | ||
customScalars, | ||
customScalars, enumTypes | ||
}), | ||
@@ -735,3 +737,3 @@ }, | ||
: { | ||
parameters: resolveParameters(url, info.operation.variableDefinitions, { customScalars }), | ||
parameters: resolveParameters(url, info.operation.variableDefinitions, { customScalars, enumTypes }), | ||
})), { responses: { | ||
@@ -745,3 +747,3 @@ 200: { | ||
operation: info.operation, | ||
customScalars, | ||
opts: { customScalars, enumTypes }, | ||
}), | ||
@@ -753,2 +755,11 @@ }, | ||
} | ||
function resolveEnumTypes(schema) { | ||
const enumTypes = Object.values(schema.getTypeMap()).filter(graphql.isEnumType).map(definition.assertEnumType); | ||
return Object.fromEntries(enumTypes.map(type => ([type.name, | ||
{ | ||
type: 'string', | ||
enum: type.getValues().map(value => value.name), | ||
}, | ||
]))); | ||
} | ||
function resolveParameters(url, variables, opts) { | ||
@@ -796,7 +807,7 @@ if (!variables) { | ||
return (primitive || | ||
opts.customScalars[type.name.value] || { | ||
$ref: mapToRef(type.name.value), | ||
}); | ||
opts.customScalars[type.name.value] || | ||
opts.enumTypes[type.name.value] || | ||
{ $ref: mapToRef(type.name.value) }); | ||
} | ||
function resolveResponse({ schema, operation, customScalars, }) { | ||
function resolveResponse({ schema, operation, opts, }) { | ||
const operationType = operation.operation; | ||
@@ -808,3 +819,3 @@ const rootField = operation.selectionSet.selections[0]; | ||
const field = queryType.getFields()[rootField.name.value]; | ||
return resolveFieldType(field.type, { customScalars }); | ||
return resolveFieldType(field.type, opts); | ||
} | ||
@@ -814,3 +825,3 @@ if (operationType === 'mutation') { | ||
const field = mutationType.getFields()[rootField.name.value]; | ||
return resolveFieldType(field.type, { customScalars }); | ||
return resolveFieldType(field.type, opts); | ||
} | ||
@@ -817,0 +828,0 @@ } |
{ | ||
"name": "sofa-api", | ||
"version": "0.15.2", | ||
"version": "0.15.3", | ||
"description": "Create REST APIs with GraphQL", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
86777
1958