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


TypeScript prisma-datamodel.SdlExpect类代码示例

本文整理汇总了TypeScript中prisma-datamodel.SdlExpect的典型用法代码示例。如果您正苦于以下问题:TypeScript SdlExpect类的具体用法?TypeScript SdlExpect怎么用?TypeScript SdlExpect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SdlExpect类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('Should create the sdl description for a simple model correctly.', () => {
    const document = {
      _id: 0,
      street: 'Test-Street',
      houseNumber: 3,
      rating: 5.7, 
    }

    const merger = new ModelMerger('document', false, new MockDocumentDataSource({})) 

    merger.analyze(document)

    const { type, embedded } = merger.getType()

    expect(embedded).toHaveLength(0)
    expect(type.name).toBe('document')
    expect(type.isEmbedded).toBe(false)
    expect(type.isEnum).toBe(false)

    expect(type.directives).toBeUndefined()
    expect(type.comments).toBeUndefined()

    expect(type.fields).toHaveLength(4)

    SdlExpect.field(type, '_id', true, false, TypeIdentifiers.integer, true)
    SdlExpect.field(type, 'street', false, false, TypeIdentifiers.string)
    SdlExpect.field(type, 'houseNumber', false, false, TypeIdentifiers.integer)
    SdlExpect.field(type, 'rating', false, false, TypeIdentifiers.float)
  })
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:29,代码来源:basic.ts

示例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)
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:29,代码来源:models.ts

示例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)
}
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:18,代码来源:simpleRelational.ts

示例4: 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)
  })
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:43,代码来源:conflicts.ts

示例5: 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)
  })
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:21,代码来源:relation.ts

示例6: 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)
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:24,代码来源:relations.ts


注:本文中的prisma-datamodel.SdlExpect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。