You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting error the requested element is null which the schema does not allow when adding errors to the GraphQL context and return nil, nil from resolver.
I have this query defined and resolver below. If I'm returning nil, err it is fine. I see proper GraphQL error response. Meaning {"data": null, "errors": ...}.
But in second case, I can get mutli error from payload.BuildURL. Based on error type inside I can differentiate which input was wrong.
However, that fails with the requested element is null which the schema does not allow. And to me that is strange.
I understand, that in schema I have non-nullable response. And if I would see that error in both cases (returning error directly and adding to context) it would be fine. But this is strange.
funcErrorOnPath(ctx context.Context, errerror, path...string) error {
gqlErr=gqlerror.WrapPath(graphql.GetPath(ctx), err)
for_, v:=rangepath {
gqlErr.Path=append(gqlErr.Path, ast.PathName(v))
}
returngqlErr
}
func (*queryResolver) ExternalDataResolverReplacePlaceholders(
ctx context.Context,
cfg model.ExternalDataResolverConfigInput,
valuesmap[string]any,
) (*model.ExternalDataResolverReplacedPlaceholders, error) {
ifuri, err:=url.Parse(cfg.URL); err!=nil||!uri.IsAbs() {
// Here I return nil as response together with error and it is finereturnnil, ErrorOnPath(ctx, errors.New("URL must be valid and absolute"), "config", "URL")
}
resp:=&model.ExternalDataResolverReplacedPlaceholders{}
varerrerrorresp.URL, err=payload.BuildURL(cfg.URL, values)
iferr!=nil {
ifme, ok:=err.(*payload.MultiError); ok {
for_, e:=rangeme.Errors {
switche:=e.(type) {
case*payload.MissingVariableError:
graphql.AddError(ctx, ErrorOnPath(ctx, e, "values"))
case*payload.InvalidDefaultValueError:
graphql.AddError(ctx, ErrorOnPath(ctx, e, "config", "URL"))
}
}
// Here if I return nil, and all errors are added to context, this is an issuereturnnil, nil
}
returnnil, ErrorOnPath(ctx, err, "config", "URL")
}
returnresp, nil
}
I was debugging that deeper into generated code, and I spot 1 place which causes the trouble I believe. But not sure if fixing that wouldn't break the rest of the code.
When I was debugging, I got here in generated code:
ifv==nil {
if!graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
returngraphql.Null
}
v in my case is nil so it is checking if field has error with this code. But when it goes to equalPath, input parameters are follow:
I'm getting error
the requested element is null which the schema does not allow
when adding errors to the GraphQL context andreturn nil, nil
from resolver.I have this query defined and resolver below. If I'm returning
nil, err
it is fine. I see proper GraphQL error response. Meaning{"data": null, "errors": ...}
.But in second case, I can get mutli error from
payload.BuildURL
. Based on error type inside I can differentiate which input was wrong.However, that fails with
the requested element is null which the schema does not allow
. And to me that is strange.I understand, that in schema I have non-nullable response. And if I would see that error in both cases (returning error directly and adding to context) it would be fine. But this is strange.
Resolver:
I was debugging that deeper into generated code, and I spot 1 place which causes the trouble I believe. But not sure if fixing that wouldn't break the rest of the code.
When I was debugging, I got here in generated code:
v
in my case isnil
so it is checking if field has error with this code. But when it goes toequalPath
, input parameters are follow:path
contains["externalDataResolverReplacePlaceholders"]
err.Path
contains["externalDataResolverReplacePlaceholders", "values"]
so
equalPath
returns false, which means that HasFieldError is false too and then I see the"the requested element is null..."
error.The text was updated successfully, but these errors were encountered: