當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。