123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { devAssert } from './jsutils/devAssert.mjs';
- import { isPromise } from './jsutils/isPromise.mjs';
- import { parse } from './language/parser.mjs';
- import { validateSchema } from './type/validate.mjs';
- import { validate } from './validation/validate.mjs';
- import { execute } from './execution/execute.mjs';
- export function graphql(args) {
-
- return new Promise((resolve) => resolve(graphqlImpl(args)));
- }
- export function graphqlSync(args) {
- const result = graphqlImpl(args);
- if (isPromise(result)) {
- throw new Error('GraphQL execution failed to complete synchronously.');
- }
- return result;
- }
- function graphqlImpl(args) {
-
- arguments.length < 2 ||
- devAssert(
- false,
- 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
- );
- const {
- schema,
- source,
- rootValue,
- contextValue,
- variableValues,
- operationName,
- fieldResolver,
- typeResolver,
- } = args;
- const schemaValidationErrors = validateSchema(schema);
- if (schemaValidationErrors.length > 0) {
- return {
- errors: schemaValidationErrors,
- };
- }
- let document;
- try {
- document = parse(source);
- } catch (syntaxError) {
- return {
- errors: [syntaxError],
- };
- }
- const validationErrors = validate(schema, document);
- if (validationErrors.length > 0) {
- return {
- errors: validationErrors,
- };
- }
- return execute({
- schema,
- document,
- rootValue,
- contextValue,
- variableValues,
- operationName,
- fieldResolver,
- typeResolver,
- });
- }
|