当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript utilities.printSchema函数代码示例

本文整理汇总了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;未经允许,请勿转载。