'GraphQL LSP with CoC + Neovim
I'm trying to setup a GraphQL language server for use within NVIM for linting, through CoC (Conquer of Completion).
I've installed the LSP from GraphQL here but I'm having trouble getting it to recognize my GQL schema. I'm currently using Apollo, and so my Schema is inside of a Javascript file.
The routine for setting the LSP up is here.
I've placed a .graphqlrc
file in the root of my project, and it's pointing at a Javascript file which contains my schema.
schema: api/src/schema.js
The Language Server appears to run briefly and lint this file, but crashes quickly and then gives me the following error:
[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
Here's my CoC settings file:
// coc-settings.json
{
"languageserver": {
"graphql": {
"command": "graphql-lsp",
"args": ["server", "-m", "stream"],
"filetypes": [
"typescript",
"typescriptreact",
"graphql",
"javascript",
"javascriptreact"
]
}
},
}
The schema.js file:
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;
Solution 1:[1]
I think the problem is that schema.js
is not a valid schema file - it is a program that produces a runtime schema. The schema
configuration option for graphql-lsp
should point to either a schema.gql
file, or a file containing JSON data resulting from an introspection query against a live GraphQL service.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jesse Hallett |