graphql / graphql/graphiql

[language-service] parsing error for string template variables in a "default argument value" position

Open
#2,787 3 comments 1 reaction 0 assignees View on GitHub
bug graphql-language-service lsp-server
Dominant language
TypeScript
Stars
16.9k
Forks
1.9k
Avg merge
22h 45m
Merged PRs (30d)
70

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current Behavior

I'd love to be able to extract default argument values into constants, so I can:

* avoid "magic values" in the schema
* use the constant default values inside other functions

This is the pattern I'd like to implement:

```ts
const schema = gql`
type ImageAsset {
src(
height: Int
width: Int = ${DEFAULT_WIDTH}
): ImageSource!
}
`;
```

... which unfortunately leads to a parsing error: `Syntax Error: Unexpected ")".`

![image](https://user-images.githubusercontent.com/6758913/193485494-90ad547f-6695-4698-b2a5-51c46db99180.png)

![image](https://user-images.githubusercontent.com/6758913/193485503-651d9fe2-8f8c-4c82-b805-9564c7568eb8.png)

### Expected Behavior

`vscode-graphql` should understand that this is, at the very least, "some default value" (understandable that it probably won't be able to grab the exact value — that would be pretty awesome, though!)

### Steps To Reproduce

```ts
const schema = gql`
type ImageAsset {
src(
height: Int
width: Int = ${DEFAULT_WIDTH}
): ImageSource!
}
`;
```

### Environment

```Markdown
- VSCode extension `graphql.vscode-graphql` Version: 0.7.5
- OS: MacOS Ventura (13.0 Beta, build 22A5352e)
```

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.