我正在尝试在node.js中使用ApolloClient
运行查询,并且收到以下错误:
Error: GraphQL error: line 1:23 no viable alternative at character '_'
at new ApolloError (node_modules/src/errors/ApolloError.ts:56:5)
at node_modules/src/core/QueryManager.ts:515:31
at node_modules/src/core/QueryManager.ts:1036:11
at Array.forEach (<anonymous>)
at node_modules/src/core/QueryManager.ts:1035:10
at Map.forEach (<anonymous>)
at QueryManager.broadcastQueries (node_modules/src/core/QueryManager.ts:1029:18)
at Object.next (node_modules/src/core/QueryManager.ts:1130:18)
at notifySubscription (node_modules/zen-observable/lib/Observable.js:130:18)
at onNotify (node_modules/zen-observable/lib/Observable.js:165:3)
at SubscriptionObserver.next (node_modules/zen-observable/lib/Observable.js:219:7)
at node_modules/apollo-link-dedup/src/dedupLink.ts:60:47
at Array.forEach (<anonymous>)
at Object.next (node_modules/apollo-link-dedup/src/dedupLink.ts:60:31)
at notifySubscription (node_modules/zen-observable/lib/Observable.js:130:18)
at onNotify (node_modules/zen-observable/lib/Observable.js:165:3)
at SubscriptionObserver.next (node_modules/zen-observable/lib/Observable.js:219:7)
at Object.next (node_modules/apollo-link-error/src/index.ts:60:22)
at notifySubscription (node_modules/zen-observable/lib/Observable.js:130:18)
at onNotify (node_modules/zen-observable/lib/Observable.js:165:3)
at SubscriptionObserver.next (node_modules/zen-observable/lib/Observable.js:219:7)
at node_modules/apollo-link-http/src/httpLink.ts:142:20
这是代码段:
require('cross-fetch/polyfill');
const ApolloBoost = require('apollo-boost');
const ApolloClient = ApolloBoost.default;
const gql = require('graphql-tag');
const {
url,
} = require('./utils');
const events = await client.query({
query: gql`
query EventsByTimeFrame(
$customerId: String!
$filters: [Field]!
) {
events(customerId: $customerId, filters: $filters) {
entityId
values
}
}
`,
variables: {
customerId,
filters: {
key: 'key',
value: 'waste',
},
},
});
当我尝试通过GraphiQL运行相同的查询时,它运行良好。任何想法为什么会发生这种情况?