wrap-cli icon indicating copy to clipboard operation
wrap-cli copied to clipboard

Env becomes required when properties are non-nullable

Open krisbitney opened this issue 2 years ago • 0 comments

Describe the bug I am implementing a uri resolver extension: https://github.com/polywrap/uri-resolver-extensions/blob/master/interface/schema.graphql

My wrapper schema looks like this:

#import { Module, MaybeUriOrManifest } into UriResolver from "wrap://ens/wraps.eth:[email protected]"
#import { Module } into ENS from "wrap://ens/wraps.eth:[email protected]"

type Module implements UriResolver_Module {}

type Env {
    registryAddress: String!
}

When I invoke the wrapper with method tryResolveUri, it throws:

    WrapError: __wrap_abort: called `Result::unwrap()` on an `Err` value: TypeReadError("Missing required field: 'registryAddress: String.'")
    code: 51 WRAPPER INVOKE ABORTED
    uri: wrap://fs//Users/kris/WebstormProjects/polywrap/uri-resolver-extensions/implementations/ens-contenthash/build
    method: tryResolveUri
    args: {
      "authority": "ens",
      "path": "goerli/wrappers.polywrap-test.eth"
    } 
    source: { file: "src/wrap/module/wrapped.rs", row: 23, col: 45 }

src/wrap/module/wrapped.rs:

pub fn try_resolve_uri_wrapped(args: &[u8], env_size: u32) -> Vec<u8> {
    let mut env: Option<Env> = None;

    if env_size > 0 {
      let env_buf = wrap_load_env(env_size);
      env = Some(Env::from_buffer(&env_buf).unwrap()); // line 23
    }

The error is only thrown when the registryAddress property is non-nullable. When I make it optional, the env is optional.

Please provide the steps to reproduce and if possible a minimal demo of the problem. Make the registryAddress property of the Env in the schema non-nullable in the ens-contenthash-resolver wrapper: https://github.com/polywrap/uri-resolver-extensions/tree/master/implementations/ens-contenthash

Then execute nvm use && yarn && yarn build && yarn test from the ens-contenthash-resolver package root.

Expected behavior I would expect the env to be optional even when properties of the env are not nullable.

In the context of the ens-contenthash-resolver wrapper, I want the env to be optional. But if a user provides an env, I want to ensure the env includes a registryAddress.

krisbitney avatar Feb 22 '23 15:02 krisbitney