graphql / vscode-graphql

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

Setting "vscode-graphql.rejectUnauthorized" is ignored #333

Closed Moortiii closed 3 years ago

Moortiii commented 3 years ago

Actual Behavior

If vscode-graphql.rejectUnauthorized is set to false the GraphQL Language server still attempts to verify certificates. As a result, all queries fail and no autocomplete is provided.

UnhandledPromiseRejectionWarning: FetchError: request to https://localhost:9000/graphql failed, reason: unable to verify the first certificate

Expected Behavior

The request should succeed since it shouldn't care about the certificate.

Steps to Reproduce the Problem Or Description

  1. Set up a GraphQL server that runs over HTTPS
  2. Download the Extension
  3. Set up a graphql.config.js file at the root of the project
  4. Open settings.json (globally or locally in a project) and set the setting vscode-graphql.rejectUnauthorized to false
  5. Create a .graphql file in a directory in the project and open it
  6. Check the GraphQL Language Server Logs

If I download the schema manually from the URL and set schema to use the local file autocomplete works perfectly.

Specifications

Logs Of TS Server || GraphQL Language Service

(node:7018) UnhandledPromiseRejectionWarning: FetchError: request to https://localhost:9000/graphql failed, reason: unable to verify the first certificate
    at ClientRequest.<anonymous> (/home/user/.vscode/extensions/graphql.vscode-graphql-0.3.18/node_modules/graphql-config/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Moortiii commented 3 years ago

After further investigation this appears to be an issue with the local instance of node and not an issue with the plugin itself.

Resolved by either:

a) Exporting NODE_TLS_REJECT_UNAUTHORIZED=0 b) Exporting NODE_EXTRA_CA_CERTS=/path/to/extra/ca_certificate

For plugins that allow for javascript configuration files, we can prepend the file with the following line if we are sure we don't need to perform certificate verificiation:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0