1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.graphql = graphql;
|
7 | exports.graphqlSync = graphqlSync;
|
8 |
|
9 | var _isPromise = _interopRequireDefault(require("./jsutils/isPromise.js"));
|
10 |
|
11 | var _parser = require("./language/parser.js");
|
12 |
|
13 | var _validate = require("./validation/validate.js");
|
14 |
|
15 | var _validate2 = require("./type/validate.js");
|
16 |
|
17 | var _execute = require("./execution/execute.js");
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | function graphql(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
|
22 | var _arguments = arguments;
|
23 |
|
24 |
|
25 |
|
26 | return new Promise(function (resolve) {
|
27 | return resolve(
|
28 | _arguments.length === 1 ? graphqlImpl(argsOrSchema) : graphqlImpl({
|
29 | schema: argsOrSchema,
|
30 | source: source,
|
31 | rootValue: rootValue,
|
32 | contextValue: contextValue,
|
33 | variableValues: variableValues,
|
34 | operationName: operationName,
|
35 | fieldResolver: fieldResolver,
|
36 | typeResolver: typeResolver
|
37 | }));
|
38 | });
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function graphqlSync(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver) {
|
49 |
|
50 |
|
51 | var result = arguments.length === 1 ? graphqlImpl(argsOrSchema) : graphqlImpl({
|
52 | schema: argsOrSchema,
|
53 | source: source,
|
54 | rootValue: rootValue,
|
55 | contextValue: contextValue,
|
56 | variableValues: variableValues,
|
57 | operationName: operationName,
|
58 | fieldResolver: fieldResolver,
|
59 | typeResolver: typeResolver
|
60 | });
|
61 |
|
62 | if ((0, _isPromise.default)(result)) {
|
63 | throw new Error('GraphQL execution failed to complete synchronously.');
|
64 | }
|
65 |
|
66 | return result;
|
67 | }
|
68 |
|
69 | function graphqlImpl(args) {
|
70 | var schema = args.schema,
|
71 | source = args.source,
|
72 | rootValue = args.rootValue,
|
73 | contextValue = args.contextValue,
|
74 | variableValues = args.variableValues,
|
75 | operationName = args.operationName,
|
76 | fieldResolver = args.fieldResolver,
|
77 | typeResolver = args.typeResolver;
|
78 |
|
79 | var schemaValidationErrors = (0, _validate2.validateSchema)(schema);
|
80 |
|
81 | if (schemaValidationErrors.length > 0) {
|
82 | return {
|
83 | errors: schemaValidationErrors
|
84 | };
|
85 | }
|
86 |
|
87 |
|
88 | var document;
|
89 |
|
90 | try {
|
91 | document = (0, _parser.parse)(source);
|
92 | } catch (syntaxError) {
|
93 | return {
|
94 | errors: [syntaxError]
|
95 | };
|
96 | }
|
97 |
|
98 |
|
99 | var validationErrors = (0, _validate.validate)(schema, document);
|
100 |
|
101 | if (validationErrors.length > 0) {
|
102 | return {
|
103 | errors: validationErrors
|
104 | };
|
105 | }
|
106 |
|
107 |
|
108 | return (0, _execute.execute)({
|
109 | schema: schema,
|
110 | document: document,
|
111 | rootValue: rootValue,
|
112 | contextValue: contextValue,
|
113 | variableValues: variableValues,
|
114 | operationName: operationName,
|
115 | fieldResolver: fieldResolver,
|
116 | typeResolver: typeResolver
|
117 | });
|
118 | }
|