UNPKG

@omnigraph/raml

Version:

This package generates `GraphQLSchema` instance from **RAML API Document** (`.raml`) file located at a URL or FileSystem by resolving the JSON Schema dependencies. It uses `@omnigraph/json-schema` by generating the necessary configuration.

33 lines (32 loc) 1.38 kB
import { camelCase } from 'change-case'; export function getFieldNameFromPath(path, method, typeName) { // Replace identifiers with "by" path = path.split('{').join('by_').split('}').join(''); const [actualPartsStr, allQueryPartsStr] = path.split('?'); const actualParts = actualPartsStr.split('/').filter(Boolean); let fieldNameWithoutMethod = actualParts.join('_'); // If path doesn't give any field name without identifiers, we can use the return type with HTTP Method name if ((!fieldNameWithoutMethod || fieldNameWithoutMethod.startsWith('by')) && typeName) { // lowercase looks better in the schema const prefix = camelCase(typeName); if (fieldNameWithoutMethod) { fieldNameWithoutMethod = prefix + '_' + fieldNameWithoutMethod; } else { fieldNameWithoutMethod = prefix; } } if (allQueryPartsStr) { const queryParts = allQueryPartsStr.split('&'); for (const queryPart of queryParts) { const [queryName] = queryPart.split('='); fieldNameWithoutMethod += '_' + 'by' + '_' + queryName; } } // get_ doesn't look good in field names const methodPrefix = method.toLowerCase(); if (methodPrefix === 'get') { return fieldNameWithoutMethod; } return methodPrefix + '_' + fieldNameWithoutMethod; }