1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import { validateSchema } from './type/validate';
|
10 | import { parse } from './language/parser';
|
11 | import { validate } from './validation/validate';
|
12 | import { execute } from './execution/execute';
|
13 | export function graphql(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
14 | var _arguments = arguments;
|
15 |
|
16 |
|
17 |
|
18 | return new Promise(function (resolve) {
|
19 | return resolve(
|
20 | _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));
|
21 | });
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | export function graphqlSync(argsOrSchema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
31 |
|
32 |
|
33 | 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);
|
34 |
|
35 | if (result.then) {
|
36 | throw new Error('GraphQL execution failed to complete synchronously.');
|
37 | }
|
38 |
|
39 | return result;
|
40 | }
|
41 |
|
42 | function graphqlImpl(schema, source, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
43 |
|
44 | var schemaValidationErrors = validateSchema(schema);
|
45 |
|
46 | if (schemaValidationErrors.length > 0) {
|
47 | return {
|
48 | errors: schemaValidationErrors
|
49 | };
|
50 | }
|
51 |
|
52 |
|
53 | var document;
|
54 |
|
55 | try {
|
56 | document = parse(source);
|
57 | } catch (syntaxError) {
|
58 | return {
|
59 | errors: [syntaxError]
|
60 | };
|
61 | }
|
62 |
|
63 |
|
64 | var validationErrors = validate(schema, document);
|
65 |
|
66 | if (validationErrors.length > 0) {
|
67 | return {
|
68 | errors: validationErrors
|
69 | };
|
70 | }
|
71 |
|
72 |
|
73 | return execute(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver);
|
74 | } |
\ | No newline at end of file |