import Router from './Router' ; import Route from './Route' ; import { IGlobalConfiguration } from './types' ; const TYPE_FRAGMENT = `
  fragment TypeFragment on __Type {
    ...InputField
    inputFields {
      name
      type {
        ...InputField
        inputFields {
          name
          type {
            ...InputField
          }
        }
      }
    }
  }

  fragment InputField on __Type {
    kind
    name
    description
    enumValues {
      name
      description
    }
  }
` ; function buildQueryForVariable ( variableName ) { return `
		${ variableName }: __type(name: "${ variableName }") {
			...TypeFragment
		}
  ` ; } function buildIntrospectionQuery ( variables ) { return `
    query IntrospectionTypeQuery {
      ${ variables . map ( buildQueryForVariable ) . join ( '\n' ) }
    }

    ${ TYPE_FRAGMENT }
  ` ; } function getAllUsedVariables ( routes ) { const variables = ( [ ] as string [ ] ) . concat ( ... routes . map ( route => Object . values ( route . operationVariables ) . map ( variable => variable . type ) ) ) ; const uniqueVariables = [ ... new Set ( variables ) ] ; return uniqueVariables ; } export default async function describeRouteVariables ( router ) { const variables = getAllUsedVariables ( router . routes ) ; const query = buildIntrospectionQuery ( variables ) ; try { const response = await router . axios ( { data : { query , } } ) ; return response . data . data ; } catch ( error ) { console . error ( `
      There was an issue connecting to GraphQL to generate documentation.
      Please ensure your connection string is correct and that any required proxies
      have been applied.
    ` ) ; throw error ; } }