2

I have probably overlooked something in the docs, but I have seem to run into a problem with being able to get a single object from my graphql queries.

Here is the schema:

type Query {
    product(name: String!): Product
}

type Product {
    _id: String
    name: String
}

Here is the resolver:

Query: {
   product (_, args) {
       return Products.find({where: args})
   },
   products () {
       return Products.find().fetch()
   }
}

Here is the Query:

query {
    product(name: "burgers") {
        name
    }
}

I get a result of this:

{
    "data": {
        "product": {
          "name": null
        }
    }
}

Am I just forgetting to add something to this, and if so could you point me the right direction.

user3119898
  • 27
  • 1
  • 1
  • 5

1 Answers1

1

If Products is a Meteor Collection, then .find returns a cursor, so the right thing to return would be Products.findOne({name: args.name})

http://docs.meteor.com/api/collections.html#Mongo-Collection-findOne

Loren
  • 13,903
  • 8
  • 48
  • 79