使用apollo服务器运行此查询时,我遇到一个GraphQL错误。有人知道它有什么问题吗?
我试图从GitHub GraphQL获取一些数据,但我得到了一个GaphQLError。我在github的开发者部分尝试了相同的查询,结果很好。有人知道它有什么问题吗使用apollo服务器运行此查询时,我遇到一个GraphQL错误。有人知道它有什么问题吗?,graphql,angular7,Graphql,Angular7,我试图从GitHub GraphQL获取一些数据,但我得到了一个GaphQLError。我在github的开发者部分尝试了相同的查询,结果很好。有人知道它有什么问题吗 issueQuery = gql` query search(first: 10, type: ISSUE, query: "repo:angular/angular is:issue state:open") { issueCount edges {
issueQuery = gql`
query search(first: 10, type: ISSUE, query: "repo:angular/angular is:issue state:open") {
issueCount
edges {
node {
... on Issue {
createdAt
title
body
url
comments(first: 10) {
nodes {
body
}
}
}
}
}
}
`;
错误堆栈跟踪:
"GraphQLError: Syntax Error: Expected $, found Name "first"
at syntaxError (http://localhost:4200/vendor.js:70270:10)
at expect (http://localhost:4200/vendor.js:75154:67)
at parseVariable (http://localhost:4200/vendor.js:73984:3)
at parseVariableDefinition (http://localhost:4200/vendor.js:73970:15)
at many (http://localhost:4200/vendor.js:75222:16)
at parseVariableDefinitions (http://localhost:4200/vendor.js:73959:82)
at parseOperationDefinition (http://localhost:4200/vendor.js:73926:26)
at parseExecutableDefinition (http://localhost:4200/vendor.js:73881:16)
at parseDefinition (http://localhost:4200/vendor.js:73845:16)
at many (http://localhost:4200/vendor.js:75222:16)"
在参数之前添加$时出现新的错误堆栈跟踪:
"GraphQLError: Syntax Error: Expected Name, found Int "10"
at syntaxError (http://localhost:4200/vendor.js:70270:10)
at expect (http://localhost:4200/vendor.js:75154:67)
at parseName (http://localhost:4200/vendor.js:73809:15)
at parseNamedType (http://localhost:4200/vendor.js:74385:11)
at parseTypeReference (http://localhost:4200/vendor.js:74364:12)
at parseVariableDefinition (http://localhost:4200/vendor.js:73971:83)
at many (http://localhost:4200/vendor.js:75222:16)
at parseVariableDefinitions (http://localhost:4200/vendor.js:73959:82)
at parseOperationDefinition (http://localhost:4200/vendor.js:73926:26)
at parseExecutableDefinition (http://localhost:4200/vendor.js:73881:16)"
不要将操作与正在查询的实际字段混淆。语法应该如下所示:
operationType [operationName] [variableDefinitions] {
selectionSet
}
其中operationType
是query
、mutation
或subscription
中的一种,operationName
是调试中使用的操作的任意名称,variableDefinitions
是操作中引用的任何变量的类型定义,selectionSet
是您实际查询的一个或多个字段
在本例中,search
是我们要查询的字段,因此不应通过query
关键字进行搜索。如果您已通过以下身份验证,则此功能可以正常工作:
query OptionalName {
search(first: 10, type: ISSUE, query: "repo:angular/angular is:issue state:open") {
issueCount
edges {
# more fields
}
}
}
如果操作类型为query
,则可以完全忽略query
关键字。这称为“查询速记”:
如果使用变量,请在操作旁边的括号内定义它们。变量名是任意的,但按照惯例,我们使用它们将用于的输入字段名:
query OptionalName ($first: Int, type: SearchType!, $query: String! ) {
search(first: $first, type: $type, query: $query) {
issueCount
edges {
# more fields
}
}
}
错误是什么?我添加了错误堆栈跟踪。
query OptionalName ($first: Int, type: SearchType!, $query: String! ) {
search(first: $first, type: $type, query: $query) {
issueCount
edges {
# more fields
}
}
}