UNPKG

571 BJavaScriptView Raw
1import { getNamedType, isObjectType } from 'graphql';
2export function forEachField(schema, fn) {
3 const typeMap = schema.getTypeMap();
4 for (const typeName in typeMap) {
5 const type = typeMap[typeName];
6 // TODO: maybe have an option to include these?
7 if (!getNamedType(type).name.startsWith('__') && isObjectType(type)) {
8 const fields = type.getFields();
9 for (const fieldName in fields) {
10 const field = fields[fieldName];
11 fn(field, typeName, fieldName);
12 }
13 }
14 }
15}