import { expect } from 'chai' ; import { jsonToGraphQLQuery } from '../' ; describe ( 'jsonToGraphQLQuery() - directives' , ( ) => { it ( 'converts a simple query with args and directives with no arguments' , ( ) => { const query = { query : { Posts : { __args : { where : { id : 10 , } , orderBy : 'flibble' } , __directives : { client : true } , id : true , title : true , post_date : true } } } as any ; expect ( jsonToGraphQLQuery ( query , { pretty : true } ) ) . to . equal ( `query {
    Posts @client (where: {id: 10}, orderBy: "flibble") {
        id
        title
        post_date
    }
}` ) ; } ) ; it ( 'converts a complex query with directives with no arguments' , ( ) => { const query = { query : { diet : { __directives : { client : true } , id : 'diet' , options : { mood : { category : 'Diet' , id : 'mood' , selected : true , } , weight : { category : 'Diet' , icon : 'fa fa-question-circle' , id : 'weight' , selected : false , text : 'Weight' } , } , title : 'Diet' } , someOtherAbritraryKey : { __directives : { client : true } , arb1 : 'arbitrary value' , arb2 : 'some other arbitrary value' } } } ; const expected = 'query { diet @client { id options { ' + 'mood { category id selected } weight { category icon id text } } ' + 'title } someOtherAbritraryKey @client { arb1 arb2 } }' ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( expected ) ; } ) ; it ( 'converts a simple query with args and multiple directives' , ( ) => { const query = { query : { Posts : { __args : { where : { id : 10 , } , orderBy : 'flibble' , } , __directives : { client : true , withArgs : { id : [ 1 , 2 , 3 ] , } , } , id : true , title : true , post_date : true , } , } , } as any ; expect ( jsonToGraphQLQuery ( query , { pretty : true } ) ) . to . equal ( `query {
    Posts @client @withArgs(id: [1, 2, 3]) (where: {id: 10}, orderBy: "flibble") {
        id
        title
        post_date
    }
}` ) ; } ) ; it ( 'converts a complex query with multiple directives' , ( ) => { const query = { query : { diet : { __directives : { client : true , } , id : 'diet' , options : { mood : { category : 'Diet' , id : 'mood' , selected : true , } , weight : { category : 'Diet' , icon : 'fa fa-question-circle' , id : 'weight' , selected : false , text : 'Weight' , } , } , title : 'Diet' , } , someOtherAbritraryKey : { __directives : { client : true , withArgs : { id : [ 1 , 2 , 3 ] , } , } , arb1 : 'arbitrary value' , arb2 : 'some other arbitrary value' , } , } , } ; const expected = 'query { diet @client { id options { ' + 'mood { category id selected } weight { category icon id text } } ' + 'title } someOtherAbritraryKey @client @withArgs(id: [1, 2, 3]) { arb1 arb2 } }' ; expect ( jsonToGraphQLQuery ( query ) ) . to . equal ( expected ) ; } ) ; } ) ;