Skip to content

Go-to-definition opens wrong file when localSchemaFile is relative and apollo.config is in a subfolder #317

Description

@unrevised6419

Summary

When a project's schema is a local file (localSchemaFile) and the apollo.config file lives in a subfolder, go-to-definition (Cmd/Ctrl+Click) on a schema field opens a non-existent file in the workspace root instead of the real schema file next to the config. Using a URL / introspection schema instead works fine.

This came up in #302, but it's a distinct bug from that feature request, so I'm splitting it out.

Reproduction

Config in a subfolder with a relative localSchemaFile:

myproject/                     # workspace folder
└── graphql/
    ├── apollo.config.json     # { client: { service: { localSchemaFile: "./schema.graphql" } } }
    ├── schema.graphql
    └── query.graphql

Open query.graphql, Cmd/Ctrl+Click a field.

  • Expected: jumps to graphql/schema.graphql.
  • Actual: opens a non-existent schema.graphql in the workspace root.

Root cause

In src/language-server/providers/schema/file.ts, the schema file is read relative to the config directory (readFileSync resolves against configDir), so loading succeeds. But the Source URI attached to the schema AST — the one used for go-to-definition — is built with resolve(path), which resolves relative to process.cwd(). In the extension process.cwd() is the first workspace folder, not the folder the apollo.config lives in, so the definition location points at <cwd>/schema.graphql.

The same process.cwd() assumption is also in getRelativeLocalSchemaFilePaths (project/internal.ts), used to exclude the schema file from the scanned documents.

Fix

Resolve both the read path and the URI (and the exclude glob) relative to the config file's directory, so read and go-to-definition always agree.

I have a branch with the fix, a regression test, and a sampleWorkspace/multiProjectSubfolders sample reproducing the exact multi-config layout: unrevised6419#1

(Opening a PR against this repo is currently locked for me, so it's on my fork for now — happy to open it here once unblocked, or the commit can be cherry-picked.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions