本文整理汇总了TypeScript中prisma-datamodel.SdlExpect.type方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SdlExpect.type方法的具体用法?TypeScript SdlExpect.type怎么用?TypeScript SdlExpect.type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prisma-datamodel.SdlExpect
的用法示例。
在下文中一共展示了SdlExpect.type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('Should create embedded types correctly', () => {
const customer = {
_id: 1,
customer: 'Hugo',
shippingAddress: {
street: 'Test-Street',
number: 3
}
}
const merger = new ModelMerger('Customer', false, new MockDocumentDataSource({}))
merger.analyze(customer)
const { type, embedded } = merger.getType()
expect(embedded).toHaveLength(1)
const embeddedType = SdlExpect.type(embedded, 'CustomerShippingAddress', false, true)
expect(type.name).toBe('Customer')
expect(type.isEmbedded).toBe(false)
expect(type.fields).toHaveLength(3)
SdlExpect.field(type, '_id', true, false, TypeIdentifiers.integer, true)
SdlExpect.field(type, 'customer', false, false, TypeIdentifiers.string)
SdlExpect.field(type, 'shippingAddress', false, false, embeddedType)
expect(embeddedType.fields).toHaveLength(2)
SdlExpect.field(embeddedType, 'street', false, false, TypeIdentifiers.string)
SdlExpect.field(embeddedType, 'number', false, false, TypeIdentifiers.integer)
})
示例2: it
it("Should infer a model and basic scalar and array types correctly.", async () => {
await env.createCollection('Movie', [{
name: 'Titanic',
genre: 'Science Fiction',
year: 1991,
rating: 9.5,
hasLeonardo: true,
roles: ['Rose', 'Jake']
}])
const connector = new MongoConnector(env.getClient())
const introspection = await connector.introspect(env.schemaName)
const sdl = await introspection.getDatamodel()
const types = sdl.types
expect(types).toHaveLength(1)
const movieType = SdlExpect.type(types, 'Movie')
expect(movieType.fields).toHaveLength(7)
SdlExpect.field(movieType, '_id', true, false, TypeIdentifiers.id, true)
SdlExpect.field(movieType, 'name', false, false, TypeIdentifiers.string)
SdlExpect.field(movieType, 'genre', false, false, TypeIdentifiers.string)
SdlExpect.field(movieType, 'year', false, false, TypeIdentifiers.integer)
SdlExpect.field(movieType, 'rating', false, false, TypeIdentifiers.float)
SdlExpect.field(movieType, 'hasLeonardo', false, false, TypeIdentifiers.boolean)
SdlExpect.field(movieType, 'roles', false, true, TypeIdentifiers.string)
}, 10000)
示例3: assertUserItemModel
export function assertUserItemModel(allTypes: IGQLType[]) {
const userType = SdlExpect.type(allTypes, 'User', false, false)
const ordersType = SdlExpect.type(allTypes, 'UserOrders', false, true)
const itemType = SdlExpect.type(allTypes, 'Item', false, false)
expect(userType.fields).toHaveLength(3)
SdlExpect.field(userType, 'orders', false, true, ordersType)
SdlExpect.field(userType, '_id', true, false, TypeIdentifiers.string, true)
SdlExpect.field(userType, 'firstName', false, false, TypeIdentifiers.string)
expect(ordersType.fields).toHaveLength(2)
SdlExpect.field(ordersType, 'item', false, false, itemType)
SdlExpect.field(ordersType, 'count', false, false, TypeIdentifiers.integer)
expect(itemType.fields).toHaveLength(2)
SdlExpect.field(itemType, '_id', true, false, TypeIdentifiers.string, true)
SdlExpect.field(itemType, 'cost', false, false, TypeIdentifiers.integer)
}
示例4: it
it('Should infer a relation with random sampling correctly.', async () => {
// Gen large number of items
const items = [...Array(1000).keys()].map(x => {
return { _id: `item_${x}`, other: `other_${x}` }
})
const others = [...Array(1000).keys()]
.filter(x => Math.random() >= 0.5)
.map(x => {
return { _id: `other_${x}` }
})
await env.createCollection('Item', items)
await env.createCollection('Other', others)
const connector = new MongoConnector(env.getClient())
const introspection = await connector.introspect(env.schemaName)
const sdl = await introspection.getDatamodel()
const schema = await introspection.renderToDatamodelString()
const itemType = SdlExpect.type(sdl.types, 'Item', false, false)
const otherType = SdlExpect.type(sdl.types, 'Other', false, false)
SdlExpect.field(itemType, 'other', false, false, otherType)
}, 20000)
示例5: it
it('Should merge conflicting models additively and recursively.', () => {
const user1 = {
lastName: 'Test-1',
shippingAddress: {
country: 'Germany'
}
}
const user2 = {
lastName: 'Test-3',
firstName: 'Test-2',
shippingAddress: {
country: 'Germany',
street: 'Teststreet'
}
}
const user3 = {
firstName: 'Test-2',
shippingAddress: {
street: 'Teststreet',
houseNumber: 4
}
}
const merger = new ModelMerger('User', false, new MockDocumentDataSource({}))
merger.analyze(user1)
merger.analyze(user2)
merger.analyze(user3)
const { type, embedded } = merger.getType()
const embeddedType = SdlExpect.type(embedded, 'UserShippingAddress', false, true)
expect(type.fields).toHaveLength(3)
SdlExpect.field(embeddedType, 'country', false, false, TypeIdentifiers.string)
SdlExpect.field(embeddedType, 'street', false, false, TypeIdentifiers.string)
SdlExpect.field(embeddedType, 'houseNumber', false, false, TypeIdentifiers.integer)
SdlExpect.field(type, 'lastName', false, false, TypeIdentifiers.string)
SdlExpect.field(type, 'firstName', false, false, TypeIdentifiers.string)
SdlExpect.field(type, 'shippingAddress', false, false, embeddedType)
})