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:
werfen Sie einen Blick in diese Tabelle https://github.com/sibelius/graphql-dataloader-boilerplate –