本文整理汇总了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)
}
示例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))
})
示例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))
}
}
示例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))
}
示例5: main
function main() {
console.log(printSchema(schema));
}
示例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))
}