Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix vscode-graphql-syntax’s grammar to support string literals on separate lines #3518

Merged
merged 14 commits into from Mar 1, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/famous-games-begin.md
@@ -0,0 +1,5 @@
---
'vscode-graphql-syntax': patch
---

Fix TextMate grammar to support string literals that don’t immediately follow a function call's left-parenthesis (`(`).
49 changes: 23 additions & 26 deletions packages/vscode-graphql-syntax/grammars/graphql.js.json
Expand Up @@ -4,39 +4,33 @@
"patterns": [
{
"contentName": "meta.embedded.block.graphql",
"begin": "\\s*+(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)|(/\\* GraphQL \\*/))\\s*\\(?\\s*(`|')",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
},
"2": {
"name": "entity.name.function.tagged-template.js"
},
"3": {
"name": "entity.name.function.tagged-template.js"
},
"4": {
"name": "comment.graphql.js"
},
"5": {
"name": "punctuation.definition.string.template.begin.js"
}
},
"end": "(`|')",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.template.end.js"
}
},
"begin": "(?<=(?:(?:Relay\\??\\.)QL|gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*)\\(",
"end": "\\)",
"patterns": [
{
"include": "source.graphql"
"begin": "(`|')",
"end": "(`|')",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.template.begin.js"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.string.template.end.js"
}
},
"patterns": [
{
"include": "source.graphql"
}
]
}
]
},
{
"contentName": "meta.embedded.block.graphql",
"begin": "\\s*+(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental))\\s*\\(?\\s*(?:<.*>)(`|')",
"begin": "\\s*+(?:(?:(?:(Relay)\\??\\.)(QL)|(gql|graphql|graphql\\.experimental)\\s*(?:<.*>)?\\s*)|(/\\* GraphQL \\*/))\\s*(`|')",
"beginCaptures": {
"1": {
"name": "variable.other.class.js"
Expand All @@ -48,6 +42,9 @@
"name": "entity.name.function.tagged-template.js"
},
"4": {
"name": "comment.graphql.js"
},
"5": {
"name": "punctuation.definition.string.template.begin.js"
}
},
Expand Down
44 changes: 44 additions & 0 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test-js.md
Expand Up @@ -26,6 +26,50 @@ const Component = () => {
};
```

```js
const variable = 1;

const queryA = graphql(`
query {
something(arg: ${variable})
}
`);

const queryB = graphql(
`
query {
something(arg: ${variable})
}
`
);

const queryC = graphql(
'query { something(arg: ${variable}) }'
);
```

```ts
const variable: number = 1;

const queryA = graphql(`
query {
something(arg: ${variable})
}
`);

const queryB = graphql(
`
query {
something(arg: ${variable})
}
`
);

const queryC = graphql(
'query { something(arg: ${variable}) }'
);
```

### svelte

```svelte
Expand Down
13 changes: 11 additions & 2 deletions packages/vscode-graphql-syntax/tests/__fixtures__/test.js
Expand Up @@ -37,8 +37,18 @@ const graphql = graphql(`
}
`);

const graphql = graphql(
`
query($id: ID!) { test }
`,
[var1, var2]
);

const query = /* GraphQL */ 'query { id } ';
const query = graphql('query { id } ');
const query = graphql('query($id: ID!) { id } ');
const query = graphql(
'query($id: ID!) { test }'
);

const queryWithInlineComment = `#graphql
query {
Expand All @@ -59,7 +69,6 @@ const queryWithInlineComment = `#graphql
}
}
`;
// TODO: fix this
const queryWithInlineComment = `
#graphql
query {
Expand Down
20 changes: 19 additions & 1 deletion packages/vscode-graphql-syntax/tests/__fixtures__/test.ts
Expand Up @@ -25,9 +25,27 @@ const query = graphql<SomeGeneric>`
}
`;

// TODO: Fix this
const query = graphql<Generic>('query { id }');

const query = graphql(
'query { id }'
);

const query = graphql<Generic>(
'query { id }'
);

const query = graphql(`
query { id }
`);

const query = graphql(
`
query { id }
`,
[var1, var2]
);

const queryWithInlineComment = `#graphql
query {
user(id: "5", name: boolean) {
Expand Down