當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。