import { graphql } from 'graphql' ; import { buildSchemaFromCode } from '..' ; import { int } from '../types' ; import { gql } from './utils' ; test ( 'Simple module' , async ( ) => { const schema = buildSchemaFromCode ( { modulePath : __filename , } ) ; expect ( schema ) . toEqualSchema ( gql `
    type Query {
      """
      adds two numbers together
      """
      sum(a: Int, b: Int): Int
      concat(first: String, last: String): String
      getPerson: Person
    }

    type Person {
      firstName: String
      lastName: String
      fullName: String
    }

    type Mutation {
      inc: Int
    }
  ` ) ; expect ( await graphql ( { schema , source : gql `
        query {
          sum(a: 2, b: 2)
          concat(first: "John", last: "Smith")
          getPerson {
            firstName
            lastName
            fullName
          }
        }
      ` , } ) ) . toEqual ( { data : { sum : 4 , concat : 'John Smith' , getPerson : { firstName : 'John' , lastName : 'Smith' , fullName : 'John Smith' , } , } , } ) ; } ) ; type Person = { firstName : string ; lastName : string ; } ; function getPerson ( ) { return { firstName : 'John' , lastName : 'Smith' , } ; } function fullName ( person ) { const { firstName , lastName } = person ; return `${ firstName } ${ lastName }` ; } export const Query = { /** adds two numbers together */ sum ( _ , { a , b } ) { return a + b ; } , concat ( _ , { first , last } ) { return `${ first } ${ last }` ; } , getPerson , } ; export const Mutation = { inc ( ) { return 0 ; } , } ; export const Person = { fullName , } ;