Skip to content

Null fields in mongo return sub fields #7

@yoadsn

Description

@yoadsn

Hey,
I am not sure where this behavior is coming from.. have been debugging both graphql-compose* and graphql-js for the past 5 hours. Any help in the right direction would be great!

Assume this mongodb document:

{
 _id: objectId("5816f273f3bb751f5021d849"),
 someField: null
}

And this mongoose schema:

let inner = {
 otherField: String
}

let MyType = Schema({
  someField: inner
})

The following gql query (assume the getOne field returns the above document):

query {
  getOne(_id: "5816f273f3bb751f5021d849") {
    someField {
      otherField
    }
  }
}

I expect to get:

{
   "data" : {
    "getOne" : {
      someField: null
    }
  }
}

This is for example what graffiti-mongoose returns..
But from graphql-compose* I get:

{
   "data" : {
    "getOne" : {
      someField: {
        otherField: null
      }
    }
  }
}

Am I expecting the wrong behavior? I found this issue graphql/graphql-js#424 that support what I expect (I think). Where is the difference?
So far I reached the conclusion that graphql-js does not recognize the value for "someField" to be null here:
https://github.com/graphql/graphql-js/blob/73513d35747cdea255156edbe30d85d9bd0c1b81/src/execution/execute.js#L774
I'm using graphql 0.7.2 although this specific code seems to remain the same in 0.8*.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions