Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Type[] | Null" produces incorrect rules #118

Closed
mm-gmbd opened this issue Jan 14, 2016 · 5 comments
Closed

"Type[] | Null" produces incorrect rules #118

mm-gmbd opened this issue Jan 14, 2016 · 5 comments
Labels

Comments

@mm-gmbd
Copy link

mm-gmbd commented Jan 14, 2016

The following Bolt rules:

type Something {
  A: Boolean,
  B: Number[] | Null
}

path /path is Something {
  read() = true;
}

produce the following rules json:

{
  "rules": {
    "path": {
      ".validate": "newData.hasChildren(['A'])",
      "A": {
        ".validate": "newData.isBoolean()"
      },
      "B": {
        "$key1": {
          ".validate": "newData.isNumber()"
        },
        ".validate": "newData.val() == null"
      },
      "$other": {
        ".validate": "false"
      },
      ".read": "true"
    }
  }
}

Notice the rules for B. It correctly produces the map rule ensuring that all wildcarded children are numbers, but it also produces a rule for B itself, validation that newData.val() == null. This precludes me from being able to write anything at /path/B!

I think the desired behavior would be, when encountered with an Type[] | Null, it would not produce any validation at the level of Type.

@mm-gmbd
Copy link
Author

mm-gmbd commented Jan 14, 2016

It looks like the fix is to remove | Null entirely. I had thought this would make the .validate rules at path equivalent to the following:

"path": {
  ".validate": "newData.hasChildren(['A', 'B'])"
}

But it was smart enough to discard the 'B'. Still, probably would be less confusing to allow for Type[] | Null!

@mm-gmbd mm-gmbd changed the title mapped key in Type produces incorrect rules "Type[] | Null" produces incorrect rules Jan 14, 2016
@mckoss mckoss added the bug label Jan 14, 2016
@mckoss
Copy link
Contributor

mckoss commented Jan 15, 2016

Another test case:

path /x is String | Null;
path /y is String[];
path /z is String[] | Null;

produces:

{
  "rules": {
    "x": {
      ".validate": "newData.isString() || newData.val() == null"
    },
    "y": {
      "$key1": {
        ".validate": "newData.isString()"
      }
    },
    "z": {
      "$key1": {
        ".validate": "newData.isString()"
      },
      ".validate": "newData.val() == null"
    }
  }
}

@jacob-israel-turner
Copy link

I experienced this today. Commenting to follow the issue.

@YeomansIII
Copy link

Also having this issue, any progress on allowing Map | Null?

@nhim175
Copy link

nhim175 commented Jun 30, 2016

I got the same issue today. Is there any work around for this?

mckoss added a commit that referenced this issue Aug 4, 2016
Fix types for Array, Map, and Null (and their unions) - issue #118.
@mckoss mckoss closed this as completed Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants