{"record":{"id":"ee9de7053661d63b","repo":"dgraph-io/dgraph","slug":"missing-fragment-s","errorCode":null,"errorMessage":"Missing fragment: %s","messagePattern":"Missing fragment: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dql/parser.go","lineNumber":276,"sourceCode":"\tfn.Entered = true\n\tif err := fn.Gq.expandFragments(fmap); err != nil {\n\t\treturn err\n\t}\n\tfn.Exited = true\n\treturn nil\n}\n\nfunc (gq *GraphQuery) expandFragments(fmap fragmentMap) error {\n\t// We have to make a copy of children to preserve order and replace\n\t// fragment references with fragment content. The copy is newChildren.\n\tvar newChildren []*GraphQuery\n\t// Expand non-fragments. Do not append to gq.Children.\n\tfor _, child := range gq.Children {\n\t\tif child.isFragment() {\n\t\t\tfname := child.fragment // Name of fragment being referenced.\n\t\t\tfchild := fmap[fname]\n\t\t\tif fchild == nil {\n\t\t\t\treturn errors.Errorf(\"Missing fragment: %s\", fname)\n\t\t\t}\n\t\t\tif err := fchild.expand(fmap); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tnewChildren = append(newChildren, fchild.Gq.Children...)\n\t\t} else {\n\t\t\tif err := child.expandFragments(fmap); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tnewChildren = append(newChildren, child)\n\t\t}\n\t}\n\tgq.Children = newChildren\n\treturn nil\n}\n\nfunc convertToVarMap(variables map[string]string) (vm varMap) {\n\tvm = make(map[string]varInfo)","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dql/parser.go#L258-L294","documentation":"expandFragments walks the query tree and replaces fragment-spread children with the fields of the fragment definition looked up in the fragment map (fmap). If a spread references a fragment name that was never defined in the query, fmap lookup returns nil and the library returns this error naming the missing fragment.","triggerScenarios":"Executing a DQL query via ParseWithNeedVars containing a spread like '...userDetails' with no corresponding 'fragment userDetails on ...' definition anywhere in the query string.","commonSituations":"Copy-pasting a query that uses shared fragments without copying the fragment definitions; typos in the fragment name in the spread vs. the definition; stripping fragments in tooling that assembles queries dynamically.","solutions":["Add the missing 'fragment <name> on <type> { ... }' definition to the query text","Check the fragment name in the error message against your spread sites for typos/case mismatches","Ensure your query-builder/tooling emits fragment definitions alongside spreads","Remove the spread if the fragment is intentionally unavailable and inline the needed fields"],"exampleFix":"// before\nquery { user(func: uid(0x1)) { ...userDetails } }\n// after\nquery { user(func: uid(0x1)) { ...userDetails } }\nfragment userDetails on User { name email }","handlingStrategy":"validation","validationCode":"func allFragmentsDefined(query string) error {\n  reSpread := regexp.MustCompile(`\\.\\.\\.([A-Za-z_][A-Za-z0-9_]*)`)\n  reDef := regexp.MustCompile(`fragment\\s+([A-Za-z_][A-Za-z0-9_]*)\\s+on`)\n  defined := map[string]bool{}\n  for _, m := range reDef.FindAllStringSubmatch(query, -1) { defined[m[1]] = true }\n  for _, m := range reSpread.FindAllStringSubmatch(query, -1) {\n    if !defined[m[1]] { return fmt.Errorf(\"spread of undefined fragment %s\", m[1]) }\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always ship fragment definitions together with queries that spread them","Store shared fragments as named constants/templates appended to every query","Check spread names against definitions for case-sensitive typos"],"tags":["dgraph","dql","graphql","fragments"],"backgroundTag":"missing-fragment-definition","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}