author import { readFile } from 'fs/promises' ; import { GraphQLSchema } from 'graphql' ; import { buildSchema , getIntrospectionQuery } from 'graphql/utilities' ; import { buildClientSchema } from 'graphql/utilities' ; import fetch from 'node-fetch' ; import { join } from 'path' ; export async function loadRemoteSchema ( endpoint , headers ? ) { const body = JSON . stringify ( { "query" : getIntrospectionQuery ( ) } ) ; const response = await fetch ( endpoint , { method : 'POST' , body , headers : { "Accept" : "application/json" , "Content-Type" : "application/json" , "Content-Length" : Buffer . byteLength ( body ) . toString ( ) , ... headers } } ) ; const { data , errors } = await response . json ( ) ; if ( errors !== undefined ) { throw new Error ( ) ; } return buildClientSchema ( data ) ; } export async function loadLocalSchema ( location ) { const sdl = await readFile ( location , { encoding : "utf8" } ) ; return buildSchema ( sdl ) ; }