If I put in a page template graphql filter like:
filter: { frontmatter: { date: { ne: null } } }
it throws an error Unknown ast kind: NullValue But it works in the gatsby-node.js with createPages method
We use the Relay Compiler to validate queries in pages so we get more warnings there. Would like to do the same validation for queries written elsewhere e.g. in gatsby-node.js
Updated the issue title to reflect this :-)
Just sharing this announcement about a new GraphQL tool
I ran into this problem as well when trying to get a list of all blog posts without the static pages ("about me", etc.) Here's the query:
{
allMarkdownRemark(filter:{ frontmatter: { date: { ne: null }}}) {
edges {
node {
frontmatter {
title
date
}
}
}
}
}
This works as expected in GraphiQL, but returns the Unknown ast kind: NullValue error in the site itself. I'm not sure that this is a problem with validation, because the query seems to be correct. Is there another way to go about this?
I'm not sure actually where the null literal error is coming from. The null literal is a fairly new addition to the GQL language, so it's possible some place is using an older version of graphql, or the Relay compiler is intentionally protecting against it (which we should change)
I think you're right. As best as I can tell, the error seems to be coming from the Relay compiler, from this block:
Tracking it down in the Relay source, it looks like RelayParser._transformValue() is the culprit:
This switch statement doesn't contain a case for NullValue, but if I add one like this:
...
switch (ast.kind) {
case 'NullValue':
return {
kind: 'Literal',
metadata: null,
value: null
};
...
}
The error no longer occurs, and the query runs as expected. I'm not very familiar with the inner-workings of GraphQL and Relay, but it seems like this is an issue in Relay instead, right?
Will be keen to know how this pans out, as I tried the same thing today and having to work around it at the moment by ensuring my data has no null paths!! However there are occasions where I may wish to set them as null, for example, to signify that they are not "published"
For those finding this outside of gatsby, the issues has been fixed and merged into relay and realy-compiler ^1.3.0
Sweet! Thanks @nkohari for fixing the bug upstream!!