本文整理匯總了TypeScript中prisma-cli-engine.Client.introspect方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client.introspect方法的具體用法?TypeScript Client.introspect怎麽用?TypeScript Client.introspect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prisma-cli-engine.Client
的用法示例。
在下文中一共展示了Client.introspect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: fetchAndPrintSchema
export async function fetchAndPrintSchema(
client: Client,
serviceName: string,
stageName: string,
token?: string,
): Promise<string> {
const introspection = await client.introspect(serviceName, stageName, token)
const schema = buildClientSchema(introspection)
const sdl = printSchema(schema)
const document = parse(sdl)
const groupedDefinitions = groupBy(document.definitions, classifyDefinition)
let sortedDefinitions: DefinitionNode[] = []
typesOrder.map(type => {
const definitions = groupedDefinitions[type]
sortedDefinitions = sortedDefinitions.concat(definitions)
})
let newSdl = print({
kind: Kind.DOCUMENT,
definitions: sortedDefinitions,
})
const newDocument = parse(newSdl)
// add comments to document
let countOffset = 0
let charOffset = 0
typesOrder.forEach((type, index) => {
if (!groupedDefinitions[type]) {
return
}
const definitionCount = groupedDefinitions[type].length
const definitions = newDocument.definitions.slice(
countOffset,
definitionCount,
)
const start = definitions[0].loc!.start
const comment = `\
${index > 0 ? '\n' : ''}#
# ${descriptions[type]}
#\n\n`
newSdl =
newSdl.slice(0, start + charOffset) +
comment +
newSdl.slice(start + charOffset)
charOffset += comment.length
countOffset += definitionCount
})
const header = `# THIS FILE HAS BEEN AUTO-GENERATED BY "PRISMA DEPLOY"
# DO NOT EDIT THIS FILE DIRECTLY\n\n`
return header + newSdl
}