2016-06-10 8 views
1

Ich habe http://docs.apollostack.com/apollo-server/guide.html/und diese video gefolgt und möchte versuchen, es an db unter www.mlab.com anzuschließen. Das Projekt stellt eine Verbindung zu mlab und graphiql her, aber wenn ich eine Abfrage in graphiql im ablege, die null/undefined Werte für meine Abfrage erhält.Basic graphQL Mongoose einrichten

Dies ist schema.js

const typeDefinitions = ` 
type Biz { 
name: String 
address: String 
} 

type Query { 
biz(name: String, address: String): Biz 
} 

schema { 
query: Query 
} 
`; 

export default [typeDefinitions]; 

Dies ist connectors.js:

// businesses in mongo DB 
    const MONGOLAB_URI = 'mongodb://user:[email protected]:64278/klik-mongodb'; 
    const mongo = Mongoose.connect(MONGOLAB_URI, function (err, res) { 
    if (err) { 
     console.log ('ERROR connecting to: ' + MONGOLAB_URI + '. ' + err); 
    } else { 
     console.log ('Succeeded connected to: ' + MONGOLAB_URI); 
    } 
    }); 

    const BizSchema = Mongoose.Schema({ 
    _id: Object, 
    address: String, 
    city: String, 
    country: String, 
    heading: String, 
    headingid: Number, 
    img_url: String, 
    name: String, 
    objectId: String, 
    phonenumber1: String, 
    website: String, 
    latitude: Number, 
    longitude: Number, 
    }); 

    const Biz = Mongoose.model('bizs', BizSchema); 

    export { Biz }; 

diese resolvers.js ist:

import { Biz } from './connectors'; 

    const resolvers = { 
    Query: { 
     biz(_, { name, address }) { 
     return Biz.find({ where: name, address }); 
     }, 
    }, 
    }; 

    export default resolvers; 

Dies ist ein Beispiel meiner MLab Objekt :

{ 
       "_id": { 
        "$oid": "573e8c9b1379f0f2fad98290" 
       }, 
       "accountid": 1404, 
       "address": "737, Grand Rue,", 
       "city": "Port-au-Prince", 
       "country": "Haiti", 
       "createdAt": "10/26/2015 7:27:42 PM", 
       "heading": "Computer, Printers and Supplies", 
       "headingid": 323, 
       "img_url": "https://res.cloudinary.com/klik-io/image/upload/v1454850817/pages-jaunes-haiti-icon_sosoco.png", 
       "name": "A & M Entreprises", 
       "objectId": "0lw9lVl23j", 
       "phonenumber1": "+509 3770 0303", 
       "website": "http://868.ht" 
      } 

Dies ist die graphiql Ausgabe: enter image description here

+0

werfen Sie einen Blick in diese Tabelle https://github.com/sibelius/graphql-dataloader-boilerplate –

Antwort

2

Es sieht aus wie Ihre biz Resolver find() verwendet, die eine Liste zurück. Was Sie wollen, ist findOne().

PS: Sie können diese Art von Problem normalerweise debuggen, indem Sie eine print-Anweisung in den entsprechenden Auflösungsfunktionen hinzufügen (oder den Node-Debugger ausführen).

+0

Danke. findOne hat versucht, ein Ergebnis zu erzielen. Ich hatte gehofft, eine Liste zu bekommen, weshalb ich find() benutzt habe. Danke, dass du dir die Zeit genommen hast. Ich weiß immer noch nicht, was ich nicht weiß. WILL versuchen, drucken und Debugger. Danke noch einmal. – idkjs