I have been struggling with this for over an hour, but can't seem to get it to work.
I'm using the ruby implementation of GraphQL together with Rails and i'm trying to do a User.all with GraphQL. I have the following QueryType which defines the field users.
QueryType = GraphQL::ObjectType.define do
name "Query"
description "The query root for this schema"
field :users do
types[IndexUserType]
resolve -> () {
User.all
}
end
end
and the IndexUserType defined as follows:
IndexUserType = GraphQL::ObjectType.define do
name "IndexUserType"
description "An Index User"
field :firstname, types.String
end
and i'm trying to get all the users with their firstname using the following query:
query={ users { firstname } }
Normally I could to the following on Has-Many relationships, however this is not working and I think this is because the 'obj' cannot be set without a parent.
resolve -> (obj, args, ctx) {
obj.cousins
}
After a lot of trial and error, I managed to solve a get all with the following: