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


TypeScript SdlExpect.field方法代码示例

本文整理汇总了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)
  })
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:33,代码来源: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: 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

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

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


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