@@ -539,6 +539,19 @@ describe('ParseGraphQLServer', () => {
539539 expect ( dateType . kind ) . toEqual ( 'SCALAR' ) ;
540540 } ) ;
541541
542+ it ( 'should have ArrayResult type' , async ( ) => {
543+ const arrayResultType = ( await apolloClient . query ( {
544+ query : gql `
545+ query ArrayResultType {
546+ __type(name: "ArrayResult") {
547+ kind
548+ }
549+ }
550+ ` ,
551+ } ) ) . data [ '__type' ] ;
552+ expect ( arrayResultType . kind ) . toEqual ( 'UNION' ) ;
553+ } ) ;
554+
542555 it ( 'should have File object type' , async ( ) => {
543556 const fileType = ( await apolloClient . query ( {
544557 query : gql `
@@ -746,6 +759,25 @@ describe('ParseGraphQLServer', () => {
746759 ) . toBeTruthy ( JSON . stringify ( schemaTypes ) ) ;
747760 } ) ;
748761
762+ it ( 'should ArrayResult contains all types' , async ( ) => {
763+ const objectType = ( await apolloClient . query ( {
764+ query : gql `
765+ query ObjectType {
766+ __type(name: "ArrayResult") {
767+ kind
768+ possibleTypes {
769+ name
770+ }
771+ }
772+ }
773+ ` ,
774+ } ) ) . data [ '__type' ] ;
775+ const possibleTypes = objectType . possibleTypes . map ( o => o . name ) ;
776+ expect ( possibleTypes ) . toContain ( '_UserClass' ) ;
777+ expect ( possibleTypes ) . toContain ( '_RoleClass' ) ;
778+ expect ( possibleTypes ) . toContain ( 'Element' ) ;
779+ } ) ;
780+
749781 it ( 'should update schema when it changes' , async ( ) => {
750782 const schemaController = await parseServer . config . databaseController . loadSchema ( ) ;
751783 await schemaController . updateClass ( '_User' , {
@@ -1661,6 +1693,84 @@ describe('ParseGraphQLServer', () => {
16611693 expect ( new Date ( result . updatedAt ) ) . toEqual ( obj . updatedAt ) ;
16621694 } ) ;
16631695
1696+ it_only_db ( 'mongo' ) (
1697+ 'should return child objects in array fields' ,
1698+ async ( ) => {
1699+ const obj1 = new Parse . Object ( 'Customer' ) ;
1700+ const obj2 = new Parse . Object ( 'SomeClass' ) ;
1701+ const obj3 = new Parse . Object ( 'Customer' ) ;
1702+
1703+ obj1 . set ( 'someCustomerField' , 'imCustomerOne' ) ;
1704+ const arrayField = [ 42.42 , 42 , 'string' , true ] ;
1705+ obj1 . set ( 'arrayField' , arrayField ) ;
1706+ await obj1 . save ( ) ;
1707+
1708+ obj2 . set ( 'someClassField' , 'imSomeClassTwo' ) ;
1709+ await obj2 . save ( ) ;
1710+
1711+ //const obj3Relation = obj3.relation('manyRelations')
1712+ obj3 . set ( 'manyRelations' , [ obj1 , obj2 ] ) ;
1713+ await obj3 . save ( ) ;
1714+
1715+ await parseGraphQLServer . parseGraphQLSchema . databaseController . schemaCache . clear ( ) ;
1716+
1717+ const result = ( await apolloClient . query ( {
1718+ query : gql `
1719+ query GetCustomer($objectId: ID!) {
1720+ objects {
1721+ getCustomer(objectId: $objectId) {
1722+ objectId
1723+ manyRelations {
1724+ ... on CustomerClass {
1725+ objectId
1726+ someCustomerField
1727+ arrayField {
1728+ ... on Element {
1729+ value
1730+ }
1731+ }
1732+ }
1733+ ... on SomeClassClass {
1734+ objectId
1735+ someClassField
1736+ }
1737+ }
1738+ createdAt
1739+ updatedAt
1740+ }
1741+ }
1742+ }
1743+ ` ,
1744+ variables : {
1745+ objectId : obj3 . id ,
1746+ } ,
1747+ } ) ) . data . objects . getCustomer ;
1748+
1749+ expect ( result . objectId ) . toEqual ( obj3 . id ) ;
1750+ expect ( result . manyRelations . length ) . toEqual ( 2 ) ;
1751+
1752+ const customerSubObject = result . manyRelations . find (
1753+ o => o . objectId === obj1 . id
1754+ ) ;
1755+ const someClassSubObject = result . manyRelations . find (
1756+ o => o . objectId === obj2 . id
1757+ ) ;
1758+
1759+ expect ( customerSubObject ) . toBeDefined ( ) ;
1760+ expect ( someClassSubObject ) . toBeDefined ( ) ;
1761+ expect ( customerSubObject . someCustomerField ) . toEqual (
1762+ 'imCustomerOne'
1763+ ) ;
1764+ const formatedArrayField = customerSubObject . arrayField . map (
1765+ elem => elem . value
1766+ ) ;
1767+ expect ( formatedArrayField ) . toEqual ( arrayField ) ;
1768+ expect ( someClassSubObject . someClassField ) . toEqual (
1769+ 'imSomeClassTwo'
1770+ ) ;
1771+ }
1772+ ) ;
1773+
16641774 it ( 'should respect level permissions' , async ( ) => {
16651775 await prepareData ( ) ;
16661776
@@ -5609,7 +5719,11 @@ describe('ParseGraphQLServer', () => {
56095719 findSomeClass(where: { someField: { _exists: true } }) {
56105720 results {
56115721 objectId
5612- someField
5722+ someField {
5723+ ... on Element {
5724+ value
5725+ }
5726+ }
56135727 }
56145728 }
56155729 }
0 commit comments