Last active
December 6, 2020 00:41
-
-
Save ltwlf/fe4fa295440df860e4fe4e34564a638c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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