| 20 | // select and format all the data from the schema that we need for the docs |
| 21 | // used in the build step |
| 22 | export default async function processSchemas(idl, previewsPerVersion) { |
| 23 | const schemaAST = parse(idl.toString()) |
| 24 | const schema = buildASTSchema(schemaAST) |
| 25 | |
| 26 | // list of objects is used when processing mutations |
| 27 | const objectsInSchema = schemaAST.definitions.filter((def) => def.kind === 'ObjectTypeDefinition') |
| 28 | |
| 29 | const data = {} |
| 30 | |
| 31 | data.queries = [] |
| 32 | data.mutations = [] |
| 33 | data.objects = [] |
| 34 | data.interfaces = [] |
| 35 | data.enums = [] |
| 36 | data.unions = [] |
| 37 | data.inputObjects = [] |
| 38 | data.scalars = [] |
| 39 | |
| 40 | await Promise.all( |
| 41 | schemaAST.definitions.map(async (def) => { |
| 42 | // QUERIES |
| 43 | if (def.name.value === 'Query') { |
| 44 | await Promise.all( |
| 45 | def.fields.map(async (field) => { |
| 46 | const query = {} |
| 47 | const queryArgs = [] |
| 48 | |
| 49 | query.name = field.name.value |
| 50 | query.type = helpers.getType(field) |
| 51 | query.kind = helpers.getTypeKind(query.type, schema) |
| 52 | query.id = helpers.getId(query.type) |
| 53 | query.href = helpers.getFullLink(query.kind, query.id) |
| 54 | query.description = await helpers.getDescription(field.description.value) |
| 55 | query.isDeprecated = helpers.getDeprecationStatus(field.directives, query.name) |
| 56 | query.deprecationReason = await helpers.getDeprecationReason(field.directives, query) |
| 57 | query.preview = await helpers.getPreview(field.directives, query, previewsPerVersion) |
| 58 | |
| 59 | await Promise.all( |
| 60 | field.arguments.map(async (arg) => { |
| 61 | const queryArg = {} |
| 62 | queryArg.name = arg.name.value |
| 63 | queryArg.defaultValue = arg.defaultValue ? arg.defaultValue.value : undefined |
| 64 | queryArg.type = helpers.getType(arg) |
| 65 | queryArg.id = helpers.getId(queryArg.type) |
| 66 | queryArg.kind = helpers.getTypeKind(queryArg.type, schema) |
| 67 | queryArg.href = helpers.getFullLink(queryArg.kind, queryArg.id) |
| 68 | queryArg.description = await helpers.getDescription(arg.description.value) |
| 69 | queryArg.isDeprecated = helpers.getDeprecationStatus(arg.directives, queryArg.name) |
| 70 | queryArg.deprecationReason = await helpers.getDeprecationReason( |
| 71 | arg.directives, |
| 72 | queryArg |
| 73 | ) |
| 74 | queryArg.preview = await helpers.getPreview( |
| 75 | arg.directives, |
| 76 | queryArg, |
| 77 | previewsPerVersion |
| 78 | ) |
| 79 | queryArgs.push(queryArg) |