本文整理汇总了TypeScript中prisma-datamodel.SdlExpect.field方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SdlExpect.field方法的具体用法?TypeScript SdlExpect.field怎么用?TypeScript SdlExpect.field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prisma-datamodel.SdlExpect
的用法示例。
在下文中一共展示了SdlExpect.field方法的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: it
it('Should bail on type conflict.', () => {
const user1 = {
lastName: 'Test-1',
shippingAddress: {
country: 'Germany'
}
}
const user2 = {
lastName: [false],
firstName: 'Test-2',
shippingAddress: {
country: 'Germany',
street: 8
}
}
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)
const conflictingEmbeddedField = SdlExpect.field(embeddedType, 'street', false, false, ModelSampler.ErrorType)
SdlExpect.error(conflictingEmbeddedField)
const conflictingField = SdlExpect.field(type, 'lastName', false, false, ModelSampler.ErrorType)
SdlExpect.error(conflictingField)
})
示例4: it
it('Should mark potential relation fields correctly.', () => {
const user = {
_id: 'id',
fk1: 'Hello',
fk2: '000000000000000000000000',
field: 3
}
const merger = new ModelMerger('User', false, new MockDocumentDataSource({}))
merger.analyze(user)
const { type } = merger.getType()
expect(type.fields).toHaveLength(4)
expect(SdlExpect.field(type, '_id', true, false, TypeIdentifiers.string, true).relationName).toBe(null)
expect(SdlExpect.field(type, 'fk1', false, false, TypeIdentifiers.string).relationName).toBe(ModelSampler.ErrorType)
expect(SdlExpect.field(type, 'fk2', false, false, TypeIdentifiers.string).relationName).toBe(ModelSampler.ErrorType)
expect(SdlExpect.field(type, 'field', false, false, TypeIdentifiers.integer).relationName).toBe(null)
})
示例5: 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)
}