[英]GraphQLError: Syntax Error: Unexpected "("
I am new to GraphQL and am trying to query the TfL API for a project with React.我是 GraphQL 的新手,我正在尝试使用 React 查询 TfL API 的项目。 I am trying to pass
$arrival
as a variable into the query, dynamically calling arrivals by station ID.我试图将
$arrival
作为变量传递到查询中,通过车站 ID 动态调用到达。 It was working yesterday but this morning it is throwing a syntax error, any ideas where it may be coming from?它昨天还在工作,但今天早上它抛出了一个语法错误,有什么想法可能来自哪里?
Type Defs类型定义
const typeDefs = `
type Station {
id: String!
stationName: String
lineId: String
lineName: String
platformName: String
direction: String
timestamp: String
timeToStation: Int
currentLocation: String
towards: String
expectedArrival: String
modeName: String
}
type Query($arrival: String!) {
getArrivals(id: $arrival): [Station]
station: [Station]
}
`;
Query询问
const GET_ALL_ARRIVALS = gql`
query Arrivals($id: String!) {
getArrivals(id: $id) {
id
stationName
platformName
lineName
towards
timeToStation
}
}
`;
Try changing your schema to尝试将您的架构更改为
const typeDefs = `
type Station {
id: String!
stationName: String
lineId: String
lineName: String
platformName: String
direction: String
timestamp: String
timeToStation: Int
currentLocation: String
towards: String
expectedArrival: String
modeName: String
}
type Query {
getArrivals(id: String!): [Station]
station: [Station]
}
`;
That doesn't explain the error, but it seems wrong to me in comparison to the documentation这并不能解释错误,但与文档相比,这对我来说似乎是错误的
When you declare the top-level query type, you're trying to embed variable definitions as part of the type definition.当您声明顶级查询类型时,您会尝试将变量定义作为类型定义的一部分嵌入。 They don't belong here;
他们不属于这里; they are purely part of the query.
它们纯粹是查询的一部分。
$variable
references never appear anywhere in the schema. $variable
引用永远不会出现在模式中的任何地方。
type Query { # does not take any parameters
getArrivals(id: ID!): [Station]
# ^^^ specify the _type_ of the field argument here
}
query Arrivals($someId: ID!) { # variable definition is part of the query
getArrivals(id: $someId) { # bind variable to field argument
id, ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.