本文整理汇总了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
}