GraphQL 在 [2, 33] 处的 \"-\"(错误)上解析错误

问题描述 投票:0回答:1

我试图将查询从函数返回到另一个函数,但是在执行此函数时它会抛出错误

{"errors":[{"message":"Parse error on \"-\" (error) at [2, 61]","locations":[{"line":2,"column":61}]}]},..}

我做错了什么?我该如何通过查询?

export function queryDependencyGraph(owner: string, repository: string) {
    return `query ($owner: String!, $repository: String!) {
        repository(owner: ${owner}, name: ${repository}) {
          url
          name
          dependencyGraphManifests(withDependencies: true) {
            nodes{
              dependencies {
                nodes{
                  packageManager
                  packageName
                  requirements
                }
              }
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
        }
      }
    `
  }
  const query = queryDependencyGraph("abcd-defg", repoName)
  const headers : Record<string, string> = {
    "Accept": "application/vnd.github.hawkgirl-preview+json",
    "Content-Type": "application/json"
  }
  const variables : Record<string, string> = {
    owner: 'abcd-defg', 
    repository: 'xxx'}

  const headers : Record<string, string> = {
    "Accept": "application/vnd.github.hawkgirl-preview+json",
    "Content-Type": "application/json"
  }
const response = await graphqlRequest("https://api.github.com/graphql", { query: query, headers : headers });
graphql github-api
1个回答
0
投票

看起来您正在将字符串文字语法混合到 GraphQL 中。

您所在的地方:

repository(owner: ${owner}, name: ${repository}) {

用途:

repository(owner: $owner, name: $repository) {
© www.soinside.com 2019 - 2024. All rights reserved.