Skip to content

Commit 66b7bf2

Browse files
committed
changelog update
1 parent 496c364 commit 66b7bf2

File tree

3 files changed

+93
-982
lines changed

3 files changed

+93
-982
lines changed

.changeset/wet-toes-mate.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
'graphql-language-service-server': minor
3+
'vscode-graphql': patch
4+
---
5+
6+
Introduce `locateCommand` based on Relay LSP `pathToLocateCommand`:
7+
8+
Now with `<graphql config>.extensions.languageService.locateCommand`, you can specify either the [existing signature](https://marketplace.visualstudio.com/items?itemName=meta.relay#relay.pathtolocatecommand-default-null) for relay, with the same callback parameters and return signature.
9+
10+
Relay LSP currently supports `Type` and `Type.field` for the 2nd argument. Ours also returns `Type.field(argument)` as a point of reference. It works with object types, input types, fragments, executable definitions and their fields, and should work for directive definitions as well.
11+
12+
In the case of unnamed types such as fragment spreads, they return the name of the implemented type currently, but I'm curious what users prefer here. I assumed that some people may want to not be limited to only using this for SDL type definition lookups. Also look soon to see `locateCommand` support added for symbols, outline, and coming references and implementations.
13+
14+
The module at the path you specify in relay LSP for `pathToLocateCommand` should work as such
15+
16+
```ts
17+
// import it
18+
import { locateCommand } from './graphql/tooling/lsp/locate.js';
19+
export default {
20+
languageService: {
21+
locateCommand,
22+
},
23+
24+
projects: {
25+
a: {
26+
schema: 'https://localhost:8000/graphql',
27+
documents: './a/**/*.{ts,tsx,jsx,js,graphql}',
28+
},
29+
b: {
30+
schema: './schema/ascode.ts',
31+
documents: './b/**/*.{ts,tsx,jsx,js,graphql}',
32+
},
33+
},
34+
};
35+
```
36+
37+
```ts
38+
// or define it inline
39+
40+
import { type LocateCommand } from 'graphql-language-service-server';
41+
42+
// relay LSP style
43+
const languageCommand = (projectName: string, typePath: string) => {
44+
const { path, startLine, endLine } = ourLookupUtility(projectName, typePath);
45+
return `${path}:${startLine}:${endLine}`;
46+
};
47+
48+
// an example with our alternative return signature
49+
const languageCommand: LocateCommand = (projectName, typePath, info) => {
50+
// pass more info, such as GraphQLType with the ast node. info.project is also available if you need it
51+
const { path, range } = ourLookupUtility(
52+
projectName,
53+
typePath,
54+
info.type.node,
55+
);
56+
return { uri: path, range }; // range.start.line/range.end.line
57+
};
58+
59+
export default {
60+
languageService: {
61+
locateCommand,
62+
},
63+
schema: 'https://localhost:8000/graphql',
64+
documents: './**/*.{ts,tsx,jsx,js,graphql}',
65+
};
66+
```
67+
68+
Passing a string as a module path to resolve is coming in a follow-up release. Then it can be used with `.yml`, `.toml`, `.json`, `package.json#graphql`, etc
69+
70+
For now this was a quick baseline for a feature asked for in multiple channels!
71+
72+
Let us know how this works, and about any other interoperability improvements between our graphql LSP and other language servers (relay, intellij, etc) used by you and colleauges in your engineering organisations. We are trying our best to keep up with the awesome innovations they have 👀!

packages/graphql-language-service-server/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ further customization:
123123
```ts
124124
import { loadConfig } from 'graphql-config'; // 3.0.0 or later!
125125
126+
const config = await loadConfig({
127+
...options here
128+
})
129+
126130
await startServer({
127131
method: 'node',
128132
// or instead of configName, an exact path (relative from rootDir or absolute)
@@ -131,7 +135,7 @@ await startServer({
131135
// configDir: '',
132136
loadConfigOptions: {
133137
// any of the options for graphql-config@3 `loadConfig()`
134-
138+
schema: await config.getSchema()
135139
// rootDir is same as `configDir` before, the path where the graphql config file would be found by cosmic-config
136140
rootDir: 'config/',
137141
// or - the relative or absolute path to your file
@@ -162,6 +166,22 @@ module.exports = {
162166
cacheSchemaFileForLookup: true,
163167
// undefined by default which has the same effect as `true`, set to `false` if you are already using // `graphql-eslint` or some other tool for validating graphql in your IDE. Must be explicitly `false` to disable this feature, not just "falsy"
164168
enableValidation: true,
169+
// (experimental) enhanced auto expansion of graphql leaf fields and arguments
170+
fillLeafsOnComplete: true,
171+
// instead of jumping directly to the SDL file, you can override definition peek/jump results to point to different files or locations
172+
// (for example, source files for your schema in any language!)
173+
// based on Relay vscode's pathToLocateCommand
174+
locateCommand: (projectName, typePath, info) => {
175+
// pass more info, such as GraphQLType with the ast node. info.project is also available if you need it
176+
const { path, range } = ourLookupUtility(
177+
projectName,
178+
typePath,
179+
info.type.node,
180+
);
181+
return { uri: path, range }; // range.start.line/range.end.character/etc, base 1
182+
// you can also return relay LSP style
183+
return '/path/to/file.py:20:23';
184+
},
165185
},
166186
},
167187
};

0 commit comments

Comments
 (0)