INNER CODE UNIT · TypeScript
extractFragment
SaltyAom/mobius · src/index.ts:814
const extractFragment = /fragment\s+(\w+)\s+on\s+[\w:]+\s*{([^}]*)}/g
/**
* Create fragments for usage in Prisma-like client
*/
export const createFragment = (schema: string) => {
const matches = schema.match(extractFragment)
if (!matches) return {}
const fragments: Record<string, Record<string, true>> = {}
if (matches) {
for (const match of matches) {
// @ts-ignore
const [, name, content] = extractFragment.exec(matches)!
const current: Record<string, true> = {}
for (const item of content.split(/(,|\n)/g))