code: function buildSelectionSet(type, getDefaultFieldNames) {
    // Unwrap any non-null or list types.
    const namedType = getNamedType(type);
  
    // Unknown types and leaf types do not have selection sets.
    if (!type || isLeafType(type)) {
      return;
    }
  
    // Get an array of field names to use.
    const fieldNames = getDefaultFieldNames(namedType);
  
    // If there are no field names to use, return no selection set.
    if (!Array.isArray(fieldNames) || fieldNames.length === 0) {
      return;
    }
  
    // Build a selection set of each field, calling buildSelectionSet recursively.
    return {
      kind: 'SelectionSet',
      selections: fieldNames.map(fieldName => {
        const fieldDef = namedType.getFields()[fieldName];
        const fieldType = fieldDef ? fieldDef.type : null;
        return {
          kind: 'Field',
          name: {
            kind: 'Name',
            value: fieldName,
          },
          selectionSet: buildSelectionSet(fieldType, getDefaultFieldNames),
        };
      }),
    };
  }
docs: Given a GraphQL type, and a function which produces field names, recursively generate a SelectionSet which includes default fields.