import { Observable , of } from "rxjs" ; import { execute } from "./execution/execute" ; import { ExecutionResult , validateSchema , parse , validate , GraphQLSchema , Source , GraphQLFieldResolver , DocumentNode } from "graphql" ; import Maybe from "graphql/tsutils/Maybe" ; export type GraphQLArgs = { schema : GraphQLSchema ; source : string | Source ; rootValue ? : unknown ; contextValue ? : unknown ; variableValues ? : Maybe < { [ key ] : unknown ; } > ; operationName ? : string | null ; fieldResolver ? : GraphQLFieldResolver < any , any > | null ; } ; function isGraphQLArgs ( _argsOrSchema , args ) { return args . length === 1 ; } export function graphql < TData > ( arg0 ) ; export function graphql < TData > ( schema , source , rootValue ? , contextValue ? , variableValues ? , operationName ? , fieldResolver ? ) ; export function graphql ( argsOrSchema , source ? , rootValue ? , contextValue ? , variableValues ? , operationName ? , fieldResolver ? ) { return isGraphQLArgs ( argsOrSchema , arguments ) ? graphqlImpl ( argsOrSchema . schema , argsOrSchema . source , argsOrSchema . rootValue , argsOrSchema . contextValue , argsOrSchema . variableValues , argsOrSchema . operationName , argsOrSchema . fieldResolver ) : graphqlImpl ( argsOrSchema , source , rootValue , contextValue , variableValues , operationName , fieldResolver ) ; } function graphqlImpl < TData > ( schema , source , rootValue ? , contextValue ? , variableValues ? , operationName ? , fieldResolver ? ) { const schemaValidationErrors = validateSchema ( schema ) ; if ( schemaValidationErrors . length > 0 ) { return of ( { errors : schemaValidationErrors } ) ; } let document ; try { document = parse ( source ) ; } catch ( syntaxError ) { return of ( { errors : [ syntaxError ] } ) ; } const validationErrors = validate ( schema , document ) ; if ( validationErrors . length > 0 ) { return of ( { errors : validationErrors } ) ; } return execute ( schema , document , rootValue , contextValue , variableValues , operationName , fieldResolver ) ; }