1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.graphql = graphql;
|
7 | exports.graphqlSync = graphqlSync;
|
8 |
|
9 | var _validate = require("./type/validate");
|
10 |
|
11 | var _parser = require("./language/parser");
|
12 |
|
13 | var _validate2 = require("./validation/validate");
|
14 |
|
15 | var _execute = require("./execution/execute");
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function graphql(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
26 | var _arguments = arguments;
|
27 |
|
28 |
|
29 |
|
30 | return new Promise(function (resolve) {
|
31 | return resolve(
|
32 | _arguments.length === 1 ? graphqlImpl(argsOrSchema.schema, argsOrSchema.source, argsOrSchema.rootValue, argsOrSchema.contextValue, argsOrSchema.variableValues, argsOrSchema.operationName, argsOrSchema.fieldResolver) : graphqlImpl(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver));
|
33 | });
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function graphqlSync(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
44 |
|
45 |
|
46 | var result = arguments.length === 1 ? graphqlImpl(argsOrSchema.schema, argsOrSchema.source, argsOrSchema.rootValue, argsOrSchema.contextValue, argsOrSchema.variableValues, argsOrSchema.operationName, argsOrSchema.fieldResolver) : graphqlImpl(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver);
|
47 |
|
48 | if (result.then) {
|
49 | throw new Error('GraphQL execution failed to complete synchronously.');
|
50 | }
|
51 |
|
52 | return result;
|
53 | }
|
54 |
|
55 | function graphqlImpl(schema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
56 |
|
57 | var schemaValidationErrors = (0, _validate.validateSchema)(schema);
|
58 |
|
59 | if (schemaValidationErrors.length > 0) {
|
60 | return {
|
61 | errors: schemaValidationErrors
|
62 | };
|
63 | }
|
64 |
|
65 |
|
66 | var document;
|
67 |
|
68 | try {
|
69 | document = (0, _parser.parse)(source);
|
70 | } catch (syntaxError) {
|
71 | return {
|
72 | errors: [syntaxError]
|
73 | };
|
74 | }
|
75 |
|
76 |
|
77 | var validationErrors = (0, _validate2.validate)(schema, document);
|
78 |
|
79 | if (validationErrors.length > 0) {
|
80 | return {
|
81 | errors: validationErrors
|
82 | };
|
83 | }
|
84 |
|
85 |
|
86 | return (0, _execute.execute)(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver);
|
87 | } |
\ | No newline at end of file |