{"record":{"id":"65f39a4ec995c592","repo":"dgraph-io/dgraph","slug":"found-type-mismatch-for-variable-s-in-s-s","errorCode":null,"errorMessage":"found type mismatch for variable `$%s` in %s `%s`, expected `%s`, got `%s`.","messagePattern":"found type mismatch for variable `\\$(.+?)` in (.+?) `(.+?)`, expected `(.+?)`, got `(.+?)`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/remote.go","lineNumber":439,"sourceCode":"\n\t\tswitch givenArgVal.Kind {\n\t\tcase ast.Variable:\n\t\t\tgivenArgTyp, ok := md.givenVarTypes[givenArgVal.Raw]\n\t\t\tif !ok {\n\t\t\t\treturn errors.Errorf(\"variable $%s is missing in given context.\", givenArgVal.Raw)\n\t\t\t}\n\t\t\t// TODO: we will consider ID as String for the purpose of type matching\n\t\t\t//rootType := givenArgTyp\n\t\t\t//for rootType.NamedType == \"\" {\n\t\t\t//\trootType = rootType.Elem\n\t\t\t//}\n\t\t\t//if rootType.NamedType == \"ID\" {\n\t\t\t//\trootType.NamedType = \"String\"\n\t\t\t//}\n\t\t\texpectedArgType := givenArgTyp.String()\n\t\t\tgotArgType := remoteArgTyp.String()\n\t\t\tif expectedArgType != gotArgType {\n\t\t\t\treturn errors.Errorf(\"found type mismatch for variable `$%s` in %s `%s`, expected\"+\n\t\t\t\t\t\" `%s`, got `%s`.\", givenArgVal.Raw, *md.operationType, *md.givenQryName,\n\t\t\t\t\texpectedArgType, gotArgType)\n\t\t\t}\n\t\t\t// deep check the remote type and verify it with the local schema.\n\t\t\tif err := matchDeepTypes(remoteArgTyp, md.remoteTypes, md.schema); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tcase ast.ObjectValue:\n\t\t\tif !(remoteArgTyp.Kind == inputObject || (remoteArgTyp.\n\t\t\t\tKind == nonNull && remoteArgTyp.OfType != nil && remoteArgTyp.OfType.\n\t\t\t\tKind == inputObject)) {\n\t\t\t\treturn errors.Errorf(\"object value supplied for argument `%s` in %s `%s`, \"+\n\t\t\t\t\t\"but remote argument doesn't accept INPUT_OBJECT.\", givenArgName,\n\t\t\t\t\t*md.operationType, *md.givenQryName)\n\t\t\t}\n\t\t\tremoteObjTypname := remoteArgTyp.NamedType()\n\t\t\tremoteObjTyp, ok := md.remoteTypes[remoteObjTypname]\n\t\t\tif !ok {","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/remote.go#L421-L457","documentation":"For a variable argument, matchArgSignature compares the declared variable type (expected, from the operation's variable definitions) with the remote argument's type (got). If their type strings differ — including wrappers like NonNull or List — this error is thrown. It ensures the client-declared variable type is assignable to what the remote operation actually accepts.","triggerScenarios":"validateRemoteGraphql -> matchArgSignature when e.g. the operation declares `$var: String` but the remote argument is `Int`, or declares `[Int]` where the remote expects `Int`, or omits the `!` the remote requires (and vice versa).","commonSituations":"Remote API tightened nullability (Int -> Int!) after upgrade; client template uses a generic String variable for IDs/numbers; list vs single-value mismatch; ID vs String mismatch where the library did not apply its ID-as-String leniency.","solutions":["Change the variable declaration type to exactly match the remote argument type string (including [] and ! wrappers).","Introspect the remote field's arguments and copy the type verbatim into the variable definition.","If the remote changed nullability recently, update stored queries or pin the remote schema version.","Note the library intentionally treats ID as String in places (see commented TODO); if you rely on that, ensure the named types align otherwise."],"exampleFix":"// before\nquery($age: String) { userNames(car: {age: $age}) }\n// remote arg: age: Int!\n// after\nquery($age: Int!) { userNames(car: {age: $age}) }","handlingStrategy":"validation","validationCode":"// Compare declared variable type to remote arg type before composing\nif varType.String() != remoteArgType.String() {\n    return fmt.Errorf(\"$%s: %s != remote %s\", varName, varType, remoteArgType)\n}","typeGuard":"func variableTypeMatches(declared, remote string) bool { return declared == remote }","tryCatchPattern":"if err := validateRemoteGraphql(...); err != nil {\n    if strings.Contains(err.Error(), \"found type mismatch for variable\") {\n        return fmt.Errorf(\"fix variable declaration: %w\", err)\n    }\n    return err\n}","preventionTips":["Copy variable types verbatim from remote introspection","Include [] and ! wrappers when declaring variables","Re-validate queries after upstream schema changes","Treat ID arguments carefully (String vs ID)"],"tags":["graphql","type-mismatch","variables"],"backgroundTag":"graphql-schema-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}