-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MongoDB: Updated for dynamic $oid and $date objects
PR-URL: hasura/graphql-engine-mono#10323 Co-authored-by: Julian <[email protected]> GitOrigin-RevId: 58ca3685c413c52c334a552f43136a8c243c729a
- Loading branch information
1 parent
2d2fe93
commit ad08230
Showing
2 changed files
with
181 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ import { inferLogicalModels } from './inferLogicalModel'; | |
describe('inferLogicalModels', () => { | ||
it('returns a logical model', () => { | ||
const document = { | ||
_id: '11123-123-123', | ||
_id: { | ||
$oid: '11123-123-123', | ||
}, | ||
name: 'John', | ||
age: 30, | ||
isActive: true, | ||
|
@@ -28,7 +30,9 @@ describe('inferLogicalModels', () => { | |
|
||
it('returns multiple logical models with array', () => { | ||
const document = { | ||
_id: '11123-123-123', | ||
_id: { | ||
$oid: '11123-123-123', | ||
}, | ||
name: 'John', | ||
age: 30, | ||
isActive: true, | ||
|
@@ -108,7 +112,9 @@ describe('inferLogicalModels', () => { | |
|
||
it('returns multiple logical models with object', () => { | ||
const document = { | ||
_id: 'asd', | ||
_id: { | ||
$oid: 'asd', | ||
}, | ||
name: 'Stu', | ||
year: 2018, | ||
gpa: 3.5, | ||
|
@@ -264,4 +270,43 @@ describe('inferLogicalModels', () => { | |
}, | ||
]); | ||
}); | ||
|
||
it('handles documents with object ids with names other than _id', () => { | ||
const document = { | ||
_id: { | ||
$oid: '5a9427648b0beebeb69579cc', | ||
}, | ||
name: 'Andrea Le', | ||
email: '[email protected]', | ||
movie_id: { | ||
$oid: '573a1390f29313caabcd418c', | ||
}, | ||
text: 'Rem officiis eaque repellendus amet eos doloribus. Porro dolor voluptatum voluptates neque culpa molestias. Voluptate unde nulla temporibus ullam.', | ||
date: { | ||
$date: '2012-03-26T23:20:16.000Z', | ||
}, | ||
}; | ||
|
||
const logicalModels = inferLogicalModels( | ||
'new-documents', | ||
JSON.stringify(document) | ||
); | ||
|
||
expect(logicalModels).toEqual([ | ||
{ | ||
fields: [ | ||
{ name: '_id', type: { nullable: false, scalar: 'objectId' } }, | ||
{ name: 'name', type: { nullable: false, scalar: 'string' } }, | ||
{ name: 'email', type: { nullable: false, scalar: 'string' } }, | ||
{ | ||
name: 'movie_id', | ||
type: { nullable: false, scalar: 'objectId' }, | ||
}, | ||
{ name: 'text', type: { nullable: false, scalar: 'string' } }, | ||
{ name: 'date', type: { nullable: false, scalar: 'date' } }, | ||
], | ||
name: 'newdocuments', | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters