【问题标题】:GraphQL LSP with CoC + Neovim带有 CoC + Neovim 的 GraphQL LSP
【发布时间】:2022-05-11 02:07:45
【问题描述】:

我正在尝试设置一个 GraphQL 语言服务器,以通过 CoC(完成征服)在 NVIM 中使用以进行 linting。

我已经从 GraphQL here 安装了 LSP,但我无法让它识别我的 GQL 架构。我目前正在使用 Apollo,因此我的 Schema 位于 Javascript 文件中。

设置 LSP 的例程是here

我在项目的根目录中放置了一个 .graphqlrc 文件,它指向一个包含我的架构的 Javascript 文件。

schema: api/src/schema.js

Language Server 似乎短暂运行并 lint 此文件,但很快崩溃,然后给我以下错误:

[Info  - 3:47:22 PM] Connection to server got closed. Server will restart.
8/11/2021, 3:47:22 PM [4] (pid: 43189) graphql-language-service-usage-logs: {"type":"usage","messageType":"initialize"}
8/11/2021, 3:47:22 PM [1] (pid: 43189) graphql-language-service-usage-logs: Error: 
      Unable to find any GraphQL type definitions for the following pointers:
        
          - api/src/schema.js

这是我的 CoC 设置文件:

// coc-settings.json
{
  "languageserver": {
    "graphql": {
      "command": "graphql-lsp",
      "args": ["server", "-m", "stream"],
      "filetypes": [
        "typescript",
        "typescriptreact",
        "graphql",
        "javascript",
        "javascriptreact"
      ]
    }
  },
}

schema.js 文件:

const { gql } = require('apollo-server');

/**
 * Type Definitions for our Schema using the SDL.
 */
const typeDefs = gql`
  type User {
    id: ID!
    username: String!
  }

  type Pet {
    id: String!
    createdAt: Int!
    name: String!
    type: String!
    img: String!
  }

  type Query {
    pets: [Pet]!
  }

  type Mutation {
    cool: String!
  }
`;

module.exports = typeDefs;

【问题讨论】:

  • 嗨,@Harrison 我也遇到了同样的问题,你解决了吗?
  • 你好,很遗憾我没有!从那以后我开始使用 nvim 的内置语言服务器而不是 CoC,但祝你好运找到解决方案。

标签: javascript graphql neovim


【解决方案1】:

我认为问题在于schema.js 不是一个有效的模式文件——它是一个产生运行时模式的程序。 graphql-lspschema 配置选项应指向 schema.gql 文件,或包含由针对实时 GraphQL 服务的自省查询产生的 JSON 数据的文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    • 2023-01-29
    • 1970-01-01
    相关资源
    最近更新 更多