Я настраиваю Apollo Server, который будет запрашивать данные из Firestore. Однако вместо извлечения данных отображается эта ошибка:
Unhandled rejection: TypeError: Path must be a string. Received 3734
at assertPath (path.js:28:11)
at Object.dirname (path.js:1349:5)
at Object.6531 (/tmp/zeit-fun-5c8c1c7110a82/index.ts:189050:36)
at __webpack_require__ (/webpack/bootstrap:19:1)
at Object.4457 (/tmp/zeit-fun-5c8c1c7110a82/index.ts:134666:25)
at __webpack_require__ (/webpack/bootstrap:19:1)
at Object.2907 (/tmp/zeit-fun-5c8c1c7110a82/index.ts:86630:16)
at __webpack_require__ (/webpack/bootstrap:19:1)
at Object.9750 (/tmp/zeit-fun-5c8c1c7110a82/index.ts:262279:13)
at __webpack_require__ (/webpack/bootstrap:19:1)
LambdaError: RequestId: 41dcf309-5d2a-4806-8062-f400b7902f2a Process exited before completing request
at Lambda.<anonymous> (/snapshot/repo/dist/index.js:1:2543198)
at Generator.next (<anonymous>)
at fulfilled (/snapshot/repo/dist/index.js:1:2541339)
at process._tickCallback (internal/process/next_tick.js:68:7)
Я сузился там, где возникает ошибка, и ошибка возникает только тогда, когда get()
вызывается в пожарном депо. Я просмотрел другие темы с похожими проблемами, и, похоже, решения не найдено.
index.ts
const { ApolloServer, gql, ApolloError } = require('apollo-server')
const admin = require('firebase-admin')
const serviceAccount = require('./firebase-secret.json')
const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'url here'
})
const typeDefs = gql`
type Query {
ping: String
}
`
const resolvers = {
Query: {
async ping () {
console.log('ping')
try {
const result = await app.firestore().collection('actions').get()
console.log(result)
return 'pong'
} catch (error) {
throw new ApolloError(error)
}
}
}
}
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
formatError: (error) => {
console.log(error)
return error
},
formatResponse: (response) => {
console.log(response)
return response
}
})
server.listen({ port: 3000 }).then(({ url }) => {
console.log(`? Server ready at ${url}`)
})
package.json
{
"version": "1.0.0",
"scripts": {
"dev": "now dev"
},
"dependencies": {
"apollo-server": "^2.4.8",
"firebase-admin": "^8.0.0",
"graphql": "^14.1.1",
"graphql-tag": "^2.10.1",
"graphql-tools": "^4.0.4",
"merge-graphql-schemas": "^1.5.8",
"moment": "^2.24.0",
"now": "^15.3.0",
"uuid": "^3.3.2"
},
"license": "ISC",
"devDependencies": {
"@types/graphql": "^14.0.3",
"json-graphql-server": "^2.1.3",
"prettier": "^1.16.4",
"typescript": "^3.3.3333"
}
}
now.json
{
"version": 2,
"builds": [{ "src": "index.ts", "use": "@now/node-server@canary" }],
"routes": [{ "src": "/api", "dest": "index.ts" }]
}