import { expect } from 'chai' ; import { jsonToGraphQLQuery } from '../' ; describe ( 'jsonToGraphQLQuery() - fragments' , ( ) => { it ( 'supports inline fragments' , ( ) => { const query = { query : { Posts : { __on : { __typeName : 'ConfigurablePost' , id : true } } } } ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( 'query { Posts { ... on ConfigurablePost { id } } }' ) ; } ) ; it ( 'supports inline fragments with subfields on same level' , ( ) => { const query = { query : { Posts : { title : true , __on : { __typeName : 'ConfigurablePost' , id : true } } } } ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( 'query { Posts { title ... on ConfigurablePost { id } } }' ) ; } ) ; it ( 'supports multiple inline fragments' , ( ) => { const query = { query : { Posts : { __on : [ { __typeName : 'ConfigurablePost' , id : true } , { __typeName : 'UnconfigurablePost' , name : true } ] } } } ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( 'query { Posts { ... on ConfigurablePost { id } ... on UnconfigurablePost { name } } }' ) ; } ) ; it ( 'supports full inline fragments' , ( ) => { const query = { query : { Posts : { __all_on : [ 'ConfigurablePost' , 'PageInfo' ] } } } ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( 'query { Posts { ...ConfigurablePost ...PageInfo } }' ) ; } ) ; } ) ;