Need help to configure the extension, schema does not load, Parse error at offset 0
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.9k
- Avg merge
- 22h 45m
- Merged PRs (30d)
- 70
Description
I have never been able to make use of this extension because it can never load my schema.
It's very likely that I didn't configure it properly, or that I have missed some important details.
At first, in the VSCode Problems panel, the extension reports the following issue:
```
graphql.config.json
Unable to parse content from '/Users/username/Desktop/project-name/gql/schema/schema.graphql': Parse error at offset 0.
```
If I use the code action `VSCode GraphQL - Manual Restart`, the problem above disappears, but I still don't have any type info or autocomplete in any source files (none of `.js` and `.gql`/`.graphql`).
The extension output in the VSCode Output panel reports this:
```
[Info - 2:57:51 PM] The graphql server has stopped running
[Info - 2:57:51 PM] The graphql server has stopped running
1/12/2022, 2:57:51 PM [3] (pid: 3236) graphql-language-service-usage-logs: {"type":"usage","messageType":"initialize"}
(node:3236) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(Use `Electron --trace-warnings ...` to show where the warning was created)
(node:3236) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
I am running this on the following environment:
```
OS: Mac OS 11.5.2 (Intel)
VSCode: 1.63.2 (Universal)
vscode-graphql: 0.3.41 and 0.3.50 (manually installed pre-release version)
Node: 14.18.0 (Node 14 LTS)
```
Can someone help me identify what is going wrong?
My project is structured as below, content of some files described further down:
```
project-root
|-- gql
| |-- resolvers /* GraphQL resolvers JS files */
| |-- schema
| | |-- **.@(graphql|gql) /* miscellaneous GrapqhQL SDL file */
| | |-- schema.graphql /* GraphQL schema root */
| | |-- index.js /* @graphql-tools schema export */
| |
| +-- index.js
|
|-- server /* miscellaneous JS files */
|-- graphql.config.json
|-- index.js /* node app start file */
|-- .env
+-- /* other files */
```
**graphql.config.json**
```json
{
"$schema": "./gql/schema/schema.graphql"
}
```
**gql/schema/schema.graphql**
```graphql
# just some example types
type UserProfile {
id: ID!
name: String!
email: String!
}
type User {
id: ID!
profile: UserProfile!
}
query {
getUser(id: ID!): User
}
```
**gql/schema/index.js**
```javascript
import { loadSchemaSync } from "@graphql-tools/load";
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
export default loadSchemaSync(
"gql/schema/schema.@(gql|graphql)",
{ loaders: [new GraphQLFileLoader()] }
);
```
**gql/index.js**
```javascript
export * as resolvers from "./resolvers";
export { default as schema } from "./schema";
```
Contributor guide
Assessment
This issue has not been assessed yet.