• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utilities.printSchema函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中graphql/utilities.printSchema函数的典型用法代码示例。如果您正苦于以下问题:TypeScript printSchema函数的具体用法?TypeScript printSchema怎么用?TypeScript printSchema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了printSchema函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: blackBoxTest

export default function blackBoxTest(name: string) {
  const generators = new Generators()

  const modelPath = path.join(__dirname, `cases/${name}/model.graphql`)
  const prismaPath = path.join(__dirname, `cases/${name}/prisma.graphql`)

  expect(fs.existsSync(modelPath))
  expect(fs.existsSync(prismaPath))

  const model = fs.readFileSync(modelPath, { encoding: 'UTF-8' })
  const prisma = fs.readFileSync(prismaPath, { encoding: 'UTF-8' })

  const types = DatamodelParser.parseFromSchemaString(model)
  const ourSchema = generators.schema.generate(types, {})


  const ourPrintedSchema = printSchema(ourSchema)

  // Write a copy of the generated schema to the FS, for debugging
  fs.writeFileSync(
    path.join(__dirname, `cases/${name}/generated.graphql`),
    ourPrintedSchema,
    { encoding: 'UTF-8' },
  )

  // Check if our schema equals the prisma schema. 
  const prismaSchema = buildSchema(prisma)
  AstTools.assertTypesEqual(prismaSchema, ourSchema)

  // Check if we can parse the schema we build (e.g. it's syntactically valid).
  parse(ourPrintedSchema)
}
开发者ID:nunsie,项目名称:prisma,代码行数:32,代码来源:blackBoxTest.ts


示例2: printSchema

 .then(response => {
   const schema = JSON.parse(response.body).data
   const sdl = printSchema(buildClientSchema(schema))
   const parsedSdl = parse(sdl)
   const mutatedSdl = visit(parsedSdl, {
     ObjectTypeDefinition: {
       enter(node: ObjectTypeDefinitionNode) {
         if (
           !['Query', 'Mutation', 'Subscription'].includes(node.name.value)
         ) {
           const nodeWithValidFields = visit(node, {
             FieldDefinition: {
               enter: (fieldNode: FieldDefinitionNode) => {
                 if (
                   (fieldNode.arguments &&
                     fieldNode.arguments.length > 0 &&
                     fieldNode.type.kind === 'NamedType') ||
                   (fieldNode.type.kind === 'NonNullType' &&
                     !isScalarType(fieldNode.type))
                 ) {
                   return {
                     ...fieldNode,
                     arguments: fieldNode.arguments
                       ? fieldNode.arguments.filter(
                           arg => arg.name.value !== 'where',
                         )
                       : [],
                   }
                 } else {
                   return fieldNode
                 }
               },
             },
           })
           return nodeWithValidFields
         }
       },
     },
     EnumTypeDefinition: {
       enter(enumNode: EnumTypeDefinitionNode) {
         if (enumNode.name.value === 'PrismaDatabase') {
           return null
         }
       },
     },
     FieldDefinition: {
       enter(fieldNode: FieldDefinitionNode) {
         if (fieldNode.name.value === 'executeRaw') {
           return null
         }
       },
     },
   })
   console.log(print(mutatedSdl))
 })
开发者ID:nunsie,项目名称:prisma,代码行数:55,代码来源:fetchSchemaFromEndpoint.ts


示例3: exportPostGraphQLSchema

/**
 * Exports a PostGraphQL schema by looking at a Postgres client.
 */
export default async function exportPostGraphQLSchema (
  schema: GraphQLSchema,
  options: {
    exportJsonSchemaPath?: string,
    exportGqlSchemaPath?: string,
  } = {},
): Promise<void> {
  // JSON version
  if (typeof options.exportJsonSchemaPath === 'string') {
    const result = await graphql(schema, introspectionQuery)
    await writeFileAsync(options.exportJsonSchemaPath, JSON.stringify(result, null, 2))
  }

  // Schema language version
  if (typeof options.exportGqlSchemaPath === 'string') {
    await writeFileAsync(options.exportGqlSchemaPath, printSchema(schema))
  }
}
开发者ID:tim-field,项目名称:postgraphql,代码行数:21,代码来源:exportPostGraphQLSchema.ts


示例4: generateCRUDSchemaString

/**
 * Computes a prisma OpenCRUD schema for a given model.
 * @param model The model in SDL as string.
 * @returns The OpenCRUD schema as prettified string for the given model. 
 */
export default function generateCRUDSchemaString(model: string) : string {
  return printSchema(generateCRUDSchema(model))
}
开发者ID:nunsie,项目名称:prisma,代码行数:8,代码来源:index.ts


示例5: main

function main() {
    console.log(printSchema(schema));
}
开发者ID:Quramy,项目名称:graphql-decorator,代码行数:3,代码来源:print.ts


示例6: generateCRUDSchemaString

/**
 * Computes a prisma OpenCRUD schema for a given model.
 * @param model The model in SDL as string.
 * @param databaseType: The database type implementation to use.
 * @returns The OpenCRUD schema as prettified string for the given model.
 */
export default function generateCRUDSchemaString(
  model: string,
  databaseType: DatabaseType = DatabaseType.postgres,
): string {
  return printSchema(generateCRUDSchema(model, databaseType))
}
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:12,代码来源:index.ts



注:本文中的graphql/utilities.printSchema函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript buildASTSchema.getDescription函数代码示例发布时间:2022-05-25
下一篇:
TypeScript printer.print函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap