waterline-graphql icon indicating copy to clipboard operation
waterline-graphql copied to clipboard

Json attributes not accessible

Open benediktdertinger opened this issue 7 years ago • 3 comments

I use this project with sailsjs and mongodb and tried to setup a basic request which works fine. Here is my User.js model:

module.exports = {
  tableName: 'users',
  attributes: {
    profile: {
      type: 'json',
      defaultsTo: {
        'firstName': null,
        'lastName': null
      }
    }
  }
}

I can request the id attribute and the profile attribute like this (Postman body): {"request": "query getUser { users { id, profile } }"}

What I can't do is request a specific json attribute like so: {"request": "query getUser { users { id, profile { firstName } } }"}

I already tried waterline-to-graphql (doesn't return json at all), sails-hook-graphql (no docs provided) and sails-grapqhl (fails at request).

How can I do this?

benediktdertinger avatar Apr 27 '17 18:04 benediktdertinger

@benediktdertinger formatting your model like below should fix the problem:

module.exports = {
  tableName: 'users',
  attributes: {
    firstName: {
      type: 'string',
      defaultsTo: null
    },
    lastName: {
      type: 'string',
      defaultsTo: null
    }
  }
}

pierreburgy avatar Apr 28 '17 13:04 pierreburgy

@pierreburgy thanks for your reply! Does it mean, that I can't use nested objects at all?

benediktdertinger avatar Apr 29 '17 08:04 benediktdertinger

@benediktdertinger unfortunately not.

pierreburgy avatar Apr 29 '17 11:04 pierreburgy