Package Exports
- @scalars/grapi-mongodb
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@scalars/grapi-mongodb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
MongoDB Data-Source
yarn add @scalars/grapi-mongodb
Or
npm install @scalars/grapi-mongodb
# Add on file schema.graphql
type VehiclesFromActor implements Relation @config(
name: "VehiclesFromActor"
foreignKey: { key: "owner_car_id" }
)
type Actor @Model( dataSource: "datasource", key: "Actor" ) {
id: ID ! @unique
name: String !
vehicles: [ Vehicle ! ] ! @relation( with: VehiclesFromActor )
}
type Vehicle @Model( dataSource: "datasource", key: "Vehicle" ) {
id: ID ! @unique
trademark: String !
model: String
name: String
owner: Actor @relation( with: VehiclesFromActor )
}
import { readFileSync } from 'fs'
import { resolve } from 'path'
import { MongodbDataSourceGroup } from '@scalars/grapi-mongodb'
import { Grapi } from '@scalars/grapi'
import { ApolloServer } from 'apollo-server'
const getDataSource = async () => {
const datasource = new MongodbDataSourceGroup(
process.env.MONGO_URI,
process.env.DATA_BASE_NAME
)
await datasource.initialize()
return datasource
}
const startGraphQLServer = async () => {
const datasource = await getDataSource()
const sdl = readFileSync( resolve( __dirname, 'schema.graphql' ) ).toString()
const grapi = new Grapi( {
sdl,
dataSources: {
datasource: ( args ) => datasource.getDataSource( args.key ),
}
} )
const server = new ApolloServer( grapi.createApolloConfig() )
server.listen().then( ( { url } ) => {
console.info( `GraphQL Server On: ${ url }` )
console.info( `Go To Browser And See PlayGround` )
} )
}
startGraphQLServer()
Extended Documentation
License
Apache-2.0
Madrov Team