apollographql / apollographql/apollo-tooling

Rest directive is not defined and throws errors if manually defined

Open
#2,180 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

I'm currently using the `apollo-link-rest` package and using the `@rest` directive in my `gql` queries. I'm manually including type definitions for the rest fields to ensure that those fields are correctly defined.

**Intended outcome:**

I was expecting that would have been all I needed to do to get `@rest` fields to work correctly without VSCode flagging them as errors.

**Actual outcome:**

However, when I'm creating a query that includes `@rest`, VSCode is flagging those directives with `Unknown directive "@rest".`, and the field that it is attached to as `@client directive is missing on local field "< field name >"`.

I've also tried manually including the `@rest` directive schema in `apollo.config.js` in the `includes` section with ` "./node_modules/apollo-link-rest/schema.graphql"`. When I do that, the `@rest` directive is now correctly typed, however the `Apollo GraphQL` output tab in VSCode is now throwing out constant errors:

```
(node:20517) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(node:20517) UnhandledPromiseRejectionWarning: Error: The type of @rest(bodySerializer:) must be Input Type but got: RestFunctionOrString.

Union type RestFunctionOrString can only include Object types, it cannot include String.

Union type RestFunctionOrString can only include Object types, it cannot include RestFunction.
at assertValidSchema (/Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/graphql/type/validate.js:69:11)
at validate (/Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/graphql/validation/validate.js:51:35)
at Object.findDeprecatedUsages (/Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/graphql/utilities/findDeprecatedUsages.js:26:33)
at Object.collectExecutableDefinitionDiagnositics (/Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/apollo-language-server/lib/diagnostics.js:17:35)
at GraphQLClientProject.validate (/Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/apollo-language-server/lib/project/client.js:182:65)
at /Users/paulsanchez/.vscode/extensions/apollographql.vscode-apollo-1.17.1/node_modules/apollo-language-server/lib/workspace.js:58:46
at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:20517) 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(). (rejection id: 2)
(node:20517) [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.
```

**How to reproduce the issue:**

For ease of reproduction, I've created a GitHub repository that replicates the issue: https://github.com/basicdays/ghtest
Setup instructions are in that readme. All you need to do is open the folder in VSCode and look at the `Apollo GraphQL` in the output window. The queries in question are found in `./lib/index.js`.

**Versions**

After installing with the latest tag from npm, looks like I'm using:

- @apollo/client: ^3.3.3
- apollo-link-rest: ^0.8.0-beta.0

I also have version 1.17.1 of the Apollo GraphQL VSCode extension

Contributor guide

Open the contributing guide

Research direction

Open the linked reproduction and inspect lib/index.js, apollo.config.js, and the included apollo-link-rest schema; start by following the Apollo GraphQL output errors in VSCode. Reproduce the diagnostics with the documented package versions, then verify that @rest is recognized without the schema validation errors and local-field warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.