graphql-anywhere-mongodb
Version:
Use graphql to query mongodb
36 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const mongodb_1 = require("mongodb");
const mongo_graphql_client_1 = require("./mongo-graphql-client");
exports.graphqlClient = {
/**
* Build a {MongoGraphQLClient} from a pre-existing mongodb connection.
*
* @param connection The connection to build the client from.
* @param options Options for changing the behavior of the client.
* @return {MongoGraphQLClient} The client.
*/
forConnection(connection, options) {
return new mongo_graphql_client_1.MongoGraphQLClient(connection, options);
},
/**
* Build a {MongoGraphQLClient} by connecting to the passed mongodb connection string.
* It will use the native node mongodb driver to connect.
*
* @param mongoUri The mongodb connection string URI.
* @param options Mongo client options and options for changing the {MongoGraphQLClient}.
* @return {Promise<MongoGraphQLClient>} A promise resolved once connection to MongoDB
* has been established.
*/
forUri(mongoUri, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (typeof mongoUri !== 'string') {
throw new Error(`Must pass a valid MongoDB connection string`);
}
const connection = yield mongodb_1.MongoClient.connect(mongoUri, options);
return new mongo_graphql_client_1.MongoGraphQLClient(connection, options);
});
},
};
//# sourceMappingURL=mongo-grqphql-client-factory.js.map