Skip to content

Commit

Permalink
changelog update
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed May 26, 2024
1 parent 496c364 commit 697e406
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
72 changes: 72 additions & 0 deletions .changeset/wet-toes-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
'graphql-language-service-server': minor
'vscode-graphql': patch
---

Introduce `locateCommand` based on Relay LSP `pathToLocateCommand`:

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.

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.

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.

The module at the path you specify in relay LSP for `pathToLocateCommand` should work as such

```ts
// import it
import { locateCommand } from './graphql/tooling/lsp/locate.js';
export default {
languageService: {
locateCommand,
},

projects: {
a: {
schema: 'https://localhost:8000/graphql',
documents: './a/**/*.{ts,tsx,jsx,js,graphql}',
},
b: {
schema: './schema/ascode.ts',
documents: './b/**/*.{ts,tsx,jsx,js,graphql}',
},
},
};
```

```ts
// or define it inline

import { type LocateCommand } from 'graphql-language-service-server';

// relay LSP style
const languageCommand = (projectName: string, typePath: string) => {
const { path, startLine, endLine } = ourLookupUtility(projectName, typePath);
return `${path}:${startLine}:${endLine}`;
};

// an example with our alternative return signature
const languageCommand: LocateCommand = (projectName, typePath, info) => {
// pass more info, such as GraphQLType with the ast node. info.project is also available if you need it
const { path, range } = ourLookupUtility(
projectName,
typePath,
info.type.node,
);
return { uri: path, range }; // range.start.line/range.end.line
};

export default {
languageService: {
locateCommand,
},
schema: 'https://localhost:8000/graphql',
documents: './**/*.{ts,tsx,jsx,js,graphql}',
};
```

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

For now this was a quick baseline for a feature asked for in multiple channels!

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 👀!
22 changes: 21 additions & 1 deletion packages/graphql-language-service-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ further customization:
```ts
import { loadConfig } from 'graphql-config'; // 3.0.0 or later!
const config = await loadConfig({
...options here
})
await startServer({
method: 'node',
// or instead of configName, an exact path (relative from rootDir or absolute)
Expand All @@ -131,7 +135,7 @@ await startServer({
// configDir: '',
loadConfigOptions: {
// any of the options for graphql-config@3 `loadConfig()`

schema: await config.getSchema()
// rootDir is same as `configDir` before, the path where the graphql config file would be found by cosmic-config
rootDir: 'config/',
// or - the relative or absolute path to your file
Expand Down Expand Up @@ -162,6 +166,22 @@ module.exports = {
cacheSchemaFileForLookup: true,
// 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"
enableValidation: true,
// (experimental) enhanced auto expansion of graphql leaf fields and arguments
fillLeafsOnComplete: true,
// instead of jumping directly to the SDL file, you can override definition peek/jump results to point to different files or locations
// (for example, source files for your schema in any language!)
// based on Relay vscode's pathToLocateCommand
locateCommand: (projectName, typePath, info) => {
// pass more info, such as GraphQLType with the ast node. info.project is also available if you need it
const { path, range } = ourLookupUtility(
projectName,
typePath,
info.type.node,
);
return { uri: path, range }; // range.start.line/range.end.character/etc, base 1
// you can also return relay LSP style
return '/path/to/file.py:20:23';
},
},
},
};
Expand Down

0 comments on commit 697e406

Please sign in to comment.