Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ltwlf/fe4fa295440df860e4fe4e34564a638c to your computer and use it in GitHub Desktop.
Save ltwlf/fe4fa295440df860e4fe4e34564a638c to your computer and use it in GitHub Desktop.
import { ApolloServer, gql } from 'apollo-server-azure-functions'
import * as mongoose from 'mongoose'
import { schema } from './model'
mongoose.connect(process.env.COSMOSDB_CONNSTR, {
useUnifiedTopology: true,
useNewUrlParser: true,
auth: {
user: process.env.COSMODDB_USER,
password: process.env.COSMOSDB_PASSWORD,
},
})
.then(() => {
try {
mongoose.connection.db.admin().command({
shardCollection: 'MyDB.MyCol1',
key: { myPartionKey: 'hashed' },
})
} catch (err) {
console.log(err)
}
try {
mongoose.connection.db.admin().command({
shardCollection: 'MyDB.MyCol2',
key: { myPartionKey: 'hashed' },
})
} catch (err) {
console.log(err)
}
console.log('Connection to CosmosDB successful 🚀')
})
.catch((err) => console.error(err))
const server = new ApolloServer({
schema,
playground: {
settings: {
'editor.theme': 'dark',
},
},
},
)
exports.graphqlHandler = server.createHandler({
cors: {
origin: true,
credentials: true,
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment