dgraph-io/dgraph · error
while json unmarshaling result from remote introspection que
Error message
while json unmarshaling result from remote introspection query
What it means
After Dgraph executes the introspection query against the remote GraphQL schema, it reads the body and unmarshals it into introspectedSchema. If the body is not valid JSON in the expected introspection envelope, json.Unmarshal fails and this wrapped error is returned. Usually the remote returned an error page, empty body, or a non-standard introspection response.
Source
Thrown at graphql/schema/remote.go:76
for k := range headers {
req.Header.Set(k, headers.Get(k))
}
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Warningf("error closing body: %v", err)
}
}()
body, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
result := &introspectedSchema{}
return result, errors.Wrapf(json.Unmarshal(body, result),
"while json unmarshaling result from remote introspection query")
}
const (
list = "LIST"
nonNull = "NON_NULL"
inputObject = string(ast.InputObject)
)
const introspectionQuery = `
query {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}View on GitHub (pinned to 759e242be6)
Solutions
- Test the introspection POST against the remote URL manually (curl) and inspect the raw body
- Ensure the remote is a real GraphQL endpoint supporting introspection
- Check auth headers in the @custom directive config
- Confirm no proxy/CDN is rewriting or blocking the response
Defensive patterns
Strategy: fallback
Validate before calling
const res = await fetch(url, introspectionPost)
try { JSON.parse(await res.text()) } catch { throw new Error('remote introspection response is not valid JSON') } Try / catch
err := schema.ValidateCustom(dgSchema, gqlSchema)
if err != nil && strings.Contains(err.Error(), "while json unmarshaling result") {
// manually curl the remote endpoint and inspect the raw body
} Prevention
- Curl the remote with the introspection query before wiring @custom
- Confirm content-type is application/json
- Check auth headers so the remote doesn't return an error page
- Ensure no proxy rewrites the response body
When it happens
Trigger: validateRemoteGraphql calls introspectRemoteSchema, the remote responds (possibly HTTP 200) but the body isn't the expected JSON introspection result — truncated response, HTML error page, or a schema format the introspectedSchema struct doesn't match.
Common situations: Remote endpoint doesn't support the introspection query version Dgraph sends; gateway/CDN intercepting the response; remote requires auth so it returns an HTML/JSON auth error instead of introspection data.
Related errors
- POST method cannot have query parameters in url: %s
- remote schema doesn't have any queries.
- remote schema doesn't have any type named %s.
- Cycle detected: %s
- Missing fragment: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/07844d2ad5f5e81b.
Report an issue: GitHub.