graphql / vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
https://marketplace.visualstudio.com/items?itemName=Prisma.vscode-graphql
MIT License
557 stars 71 forks source link

No autocomplete feature #313

Closed MariaSolOs closed 3 years ago

MariaSolOs commented 3 years ago

Actual Behavior

The extension successfully provides syntax highlighting but I'm not getting "go to" support or autocompletion.

Expected Behavior

The extension says guarantees "syntax highlighting, autocomplete suggestions, validation against schema, snippets and hover support".

Steps to Reproduce the Problem Or Description

In .vscode/settings.json, I included:

"graphql-config.load.filePath": "/config/graphql.config.json",
"vscode-graphql.useSchemaFileDefinitions": true

and my graphql config file is

{
    "schema": "/graphql/schema.js",
    "documents": ["/graphql/resolvers.js"]
}

I'm sure the config file is found since I can see the Graphql button at the bottom when writing a gql string. However, there's no autocompletion at all and the "Execute Query" button on the client does nothing.

Specifications

Logs Of TS Server || GraphQL Language Service

waterdrop01 commented 3 years ago

Same problem. If anyone succeed to get "go to definition" and "autocomplete", please let us know here :) Thanks!

MariaSolOs commented 3 years ago

So I was able to fix the issue with Codegen and using an introspection file for the schema. As a reference, here's a sketch of my project's structure:

|--graphql.config.js
|--package.json
|-- server
    |--graphql
       |--intro-schema.json
       |--schema.ts
    |-- codegen.yml
|-- client
    |--src
       |--graphql-api

Here's what worked for me:

  1. Install Codegen. In my case, this involved running npm i --save-dev @graphql-codegen/cli @graphql-codegen/introspection.
  2. Add a codegen.yml file to your project. It doesn't need to be at the root, just make sure that the filepaths in this configuration file are correct. This is what I used:
    overwrite: true
    schema: './graphql/schema.ts'
    watch: true
    generates:
    ./graphql/intro-schema.json:
    plugins:
      - introspection
  3. Add a script to your package.json file for generating the introspection file. Considering my file structure, I used:
    "scripts": {
    ...
    "generate": "cd server && graphql-codegen --config codegen.yml"
    },
  4. Use the generated introspection file as the schema for the extension. Here's the relevant snippet of my graphql.config.js file:
    module.exports = {
    schema: './server/graphql/intro-schema.json',
    documents: ['./client/src/graphql-api/*.graphql']
    }

    And ta-da! It worked for me then :) (you may need to reload your window though).

Disclaimer 1: I didn't install Codegen just to make the extension work. I use Typescript and so I wanted to use their tools to type my queries and mutations. I later saw that this extension also accepted introspection files and it did, so I successfully made it work with that. Disclaimer 2: No, I don't work for Codegen or anything like that. Just sharing what worked with me to the rest of the world <3

waterdrop01 commented 3 years ago

Thanks a lot @MariaSolOs for the detailed answer... but no luck for me :(

I'm using .graphqlrc.yml config file, and even when setting the introspection .json file as schema value, vscode-graphql doesn't give any extra hint. I guess I will just give up on go-to and auto-completion ^^