Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const { mdast } = await processMDX({ node: mdxNode });
const excerptNodes = [];
visit(mdast, node => {
if (node.type === "text" || node.type === "inlineCode") {
excerptNodes.push(node.value);
}
return;
});
return prune(excerptNodes.join(" "), pruneLength, "…");
}
},
headings: {
type: new GraphQLList(HeadingType),
args: {
depth: {
type: Headings
}
},
async resolve(mdxNode, { depth }) {
// TODO: change this to operate on html instead of mdast
const { mdast } = await processMDX({ node: mdxNode });
let headings = [];
visit(mdast, "heading", heading => {
headings.push({
value: toString(heading),
depth: heading.depth
});
});
if (typeof depth === `number`) {
if (!R.isEmpty(primaryFields))
sliceFields.primary = {
type: new GraphQLObjectType({
name: generateNamespacedTypeName(
customTypeId,
sliceZoneId,
fieldId,
'Primary',
),
fields: R.map(fieldToGraphQLType(customTypeId), primaryFields),
}),
}
if (!R.isEmpty(itemsFields))
sliceFields.items = {
type: new GraphQLList(
new GraphQLObjectType({
name: generateNamespacedTypeName(
customTypeId,
sliceZoneId,
fieldId,
'Item',
),
fields: R.map(fieldToGraphQLType(customTypeId), itemsFields),
}),
),
}
// GraphQL type must match source plugin type.
const sliceType = new GraphQLObjectType({
name: generatePublicTypeName(customTypeId, sliceZoneId, fieldId),
fields: sliceFields,
});
if (!hasItems && !(k in current[model])) {
const otherSchema = current[spec.model];
const RelationType = new GraphQLTypes.GraphQLObjectType({
name: model + '__' + k + '__relation',
fields: {
...otherSchema,
id: {
type: GraphQLTypes.GraphQLString
}
}
});
current[model][k] = {type: new GraphQLTypes.GraphQLList(RelationType)};
}
}
}
// Handling cover
const ProcessedType = new GraphQLTypes.GraphQLObjectType({
name: model + '__processed_image_string',
fields: {
small: {
type: GraphQLTypes.GraphQLString
},
medium: {
type: GraphQLTypes.GraphQLString
},
large: {
type: GraphQLTypes.GraphQLString
case 'Slices':
const choiceTypes = R.pipe(
R.path(['config', 'choices']),
R.mapObjIndexed(
fieldToGraphQLType(customTypeId, { sliceZoneId: fieldId }),
),
R.values,
R.map(R.prop('type')),
)(field)
const unionType = new GraphQLUnionType({
name: generateNamespacedTypeName(customTypeId, fieldId, 'Slice'),
types: choiceTypes,
})
return { type: new GraphQLList(unionType) }
default:
console.log(`UNPROCESSED FIELD for type "${field.type}"`)
return {}
}
}
},
depth: {
type: GraphQLInt,
resolve: ({depth}) => depth,
},
parents: {
type: new GraphQLList(ParentHeadingType),
resolve: ({parents}) => parents,
},
},
})
return {
headingsDetail : {
type: new GraphQLList(HeadingType),
resolve: ({ rawMarkdownBody }) => _attachParents(_getHeaders(rawMarkdownBody)),
}
}
}
name: `MarkdownHeadingDetail`,
fields: {
value: {
type: GraphQLString,
resolve: ({value}) => value,
},
id: {
type: GraphQLString,
resolve: ({id}) => id,
},
depth: {
type: GraphQLInt,
resolve: ({depth}) => depth,
},
parents: {
type: new GraphQLList(ParentHeadingType),
resolve: ({parents}) => parents,
},
},
})
return {
headingsDetail : {
type: new GraphQLList(HeadingType),
resolve: ({ rawMarkdownBody }) => _attachParents(_getHeaders(rawMarkdownBody)),
}
}
}
if (target in schemas[source])
return;
const BacklinkType = new GraphQLTypes.GraphQLObjectType({
name: source + '__' + target + '__backlink',
fields: {
...schemas[target],
id: {
type: GraphQLTypes.GraphQLString
}
}
});
schemas[source][target] = {
type: new GraphQLTypes.GraphQLList(BacklinkType),
resolve: function(item) {
return getNodes().filter(node => {
if (!node[source])
return;
return node[source].some(id => id === item.id)
});
}
};
};
return { type: GraphQLPrismicImage }
case 'Link':
return { type: GraphQLPrismicLink }
case 'Group':
const group = R.pipe(
R.path(['config', 'fields']),
subfields =>
new GraphQLObjectType({
name: generateNamespacedTypeName('Group', fieldId),
fields: R.map(fieldToGraphQLType(customTypeId), subfields),
}),
)(field)
return { type: new GraphQLList(group) }
case 'Slice':
const { sliceZoneId } = options
const { 'non-repeat': primaryFields, repeat: itemsFields } = field
const sliceFields = {
id: { type: new GraphQLNonNull(GraphQLString) },
slice_type: { type: new GraphQLNonNull(GraphQLString) },
}
if (!R.isEmpty(primaryFields))
sliceFields.primary = {
type: new GraphQLObjectType({
name: generateNamespacedTypeName(
customTypeId,
sliceZoneId,
function recurseIntoSchema(model, meta) {
if (meta.type === 'string')
return {type: GraphQLTypes.GraphQLString};
if (meta.type === 'number')
return {type: GraphQLTypes.GraphQLFloat};
if (meta.type === 'boolean')
return {type: GraphQLTypes.GraphQLBoolean};
if (meta.type === 'array' && meta.formType !== 'ref') {
const {type: subType} = recurseIntoSchema(model, meta.items);
return {
type: new GraphQLTypes.GraphQLList(subType)
};
}
if (meta.type === 'object') {
const fields = {};
for (const k in meta.properties)
fields[k] = recurseIntoSchema(model, meta.properties[k]);
return {
type: new GraphQLTypes.GraphQLObjectType({
name: model + '__' + _.deburr(meta.title.replace(/ /g, '_')),
fields
})
};
}