123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import isPromise from "./jsutils/isPromise.mjs";
- import { parse } from "./language/parser.mjs";
- import { validate } from "./validation/validate.mjs";
- import { validateSchema } from "./type/validate.mjs";
- import { execute } from "./execution/execute.mjs";
- export function graphql(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
- var _arguments = arguments;
-
-
- return new Promise(function (resolve) {
- return resolve(
- _arguments.length === 1 ? graphqlImpl(argsOrSchema) : graphqlImpl({
- schema: argsOrSchema,
- source: source,
- rootValue: rootValue,
- contextValue: contextValue,
- variableValues: variableValues,
- operationName: operationName,
- fieldResolver: fieldResolver,
- typeResolver: typeResolver
- }));
- });
- }
- export function graphqlSync(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
-
-
- var result = arguments.length === 1 ? graphqlImpl(argsOrSchema) : graphqlImpl({
- schema: argsOrSchema,
- source: source,
- rootValue: rootValue,
- contextValue: contextValue,
- variableValues: variableValues,
- operationName: operationName,
- fieldResolver: fieldResolver,
- typeResolver: typeResolver
- });
- if (isPromise(result)) {
- throw new Error('GraphQL execution failed to complete synchronously.');
- }
- return result;
- }
- function graphqlImpl(args) {
- var schema = args.schema,
- source = args.source,
- rootValue = args.rootValue,
- contextValue = args.contextValue,
- variableValues = args.variableValues,
- operationName = args.operationName,
- fieldResolver = args.fieldResolver,
- typeResolver = args.typeResolver;
- var schemaValidationErrors = validateSchema(schema);
- if (schemaValidationErrors.length > 0) {
- return {
- errors: schemaValidationErrors
- };
- }
- var document;
- try {
- document = parse(source);
- } catch (syntaxError) {
- return {
- errors: [syntaxError]
- };
- }
- var validationErrors = validate(schema, document);
- if (validationErrors.length > 0) {
- return {
- errors: validationErrors
- };
- }
- return execute({
- schema: schema,
- document: document,
- rootValue: rootValue,
- contextValue: contextValue,
- variableValues: variableValues,
- operationName: operationName,
- fieldResolver: fieldResolver,
- typeResolver: typeResolver
- });
- }
|