| 2 | import type { SchemaLoader } from './typings'; |
| 3 | |
| 4 | export const defaultSchemaLoader: SchemaLoader = (schemaConfig, parser) => { |
| 5 | const { |
| 6 | schema, |
| 7 | documentAST, |
| 8 | introspectionJSON, |
| 9 | introspectionJSONString, |
| 10 | buildSchemaOptions, |
| 11 | documentString, |
| 12 | } = schemaConfig; |
| 13 | if (schema) { |
| 14 | return schema; |
| 15 | } |
| 16 | if (introspectionJSONString) { |
| 17 | const introspectionJSONResult = JSON.parse(introspectionJSONString); |
| 18 | return buildClientSchema(introspectionJSONResult, buildSchemaOptions); |
| 19 | } |
| 20 | if (documentString && parser) { |
| 21 | const docAST = parser(documentString); |
| 22 | return buildASTSchema(docAST, buildSchemaOptions); |
| 23 | } |
| 24 | if (introspectionJSON) { |
| 25 | return buildClientSchema(introspectionJSON, buildSchemaOptions); |
| 26 | } |
| 27 | if (documentAST) { |
| 28 | return buildASTSchema(documentAST, buildSchemaOptions); |
| 29 | } |
| 30 | throw new Error('no schema supplied'); |
| 31 | }; |