diff --git a/.prettierignore b/.prettierignore index a1731045fcc..e2172396f09 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ +# deliate whitespace character assertions: packages/graphql-language-service-server/src/__tests__/parseDocument-test.ts diff --git a/package.json b/package.json index 7bb52807585..9ed4d69468f 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "prepublishOnly": "./scripts/prepublish.sh", "postbuild": "wsrun --exclude-missing postbuild", "pretty": "yarn pretty-check --write", - "pretty-check": "prettier --cache --check --ignore-path .gitignore --ignore-path .eslintignore .", + "pretty-check": "prettier --cache --check --ignore-path .gitignore --ignore-path .prettierignore --ignore-path .eslintignore .", "ci:version": "yarn changeset version && yarn build && yarn format", "release": "yarn build && yarn build-bundles && (wsrun release --exclude-missing --serial --recursive --changedSince main -- || true) && yarn changeset publish", "release:canary": "(node scripts/canary-release.js && yarn build-bundles && yarn changeset publish --tag canary) || echo Skipping Canary...", diff --git a/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts b/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts index 26544f49d45..13ac1cc49c9 100644 --- a/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts +++ b/packages/graphql-language-service-server/src/__tests__/MessageProcessor.spec.ts @@ -22,6 +22,11 @@ const fooTypePosition = { end: { line: 2, character: 24 }, }; +const fooInlineTypePosition = { + start: { line: 5, character: 0 }, + end: { line: 5, character: 24 }, +}; + const genSchemaPath = '/tmp/graphql-language-service/test/projects/default/generated-schema.graphql'; @@ -96,7 +101,7 @@ describe('MessageProcessor with no config', () => { }); }); -describe('project with simple config and graphql files', () => { +describe('MessageProcessor with config', () => { let app; afterEach(() => { mockfs.restore(); @@ -447,12 +452,15 @@ describe('project with simple config and graphql files', () => { 'b/fragments.ts', '\n\n\nexport const fragment = gql`\n\n fragment T on Test { isTest }\n`', ], - ['b/schema.graphql', schemaFile[1]], + [ + 'b/schema.ts', + `\n\nexport const schema = gql(\`\n${schemaFile[1]}\`)`, + ], [ 'package.json', `{ "graphql": { "projects": { "a": { "schema": "http://localhost:3100/graphql", "documents": "./a/**" }, - "b": { "schema": "./b/schema.graphql", "documents": "./b/**" } } + "b": { "schema": "./b/schema.ts", "documents": "./b/**" } } } }`, ], @@ -491,25 +499,29 @@ describe('project with simple config and graphql files', () => { // this confirms that autocomplete respects cross-project boundaries for types. // it performs a definition request for the foo field in Query const schemaCompletion1 = await project.lsp.handleCompletionRequest({ - textDocument: { uri: project.uri('b/schema.graphql') }, - position: { character: 21, line: 0 }, + textDocument: { uri: project.uri('b/schema.ts') }, + position: { character: 21, line: 3 }, }); expect(schemaCompletion1.items.map(i => i.label)).toEqual(['Foo']); // it performs a definition request for the Foo type in Test.test const schemaDefinition = await project.lsp.handleDefinitionRequest({ - textDocument: { uri: project.uri('b/schema.graphql') }, - position: { character: 21, line: 4 }, + textDocument: { uri: project.uri('b/schema.ts') }, + position: { character: 21, line: 6 }, }); - expect(serializeRange(schemaDefinition[0].range)).toEqual(fooTypePosition); + expect(serializeRange(schemaDefinition[0].range)).toEqual( + fooInlineTypePosition, + ); expect(project.lsp._logger.error).not.toHaveBeenCalled(); // simulate a watched schema file change (codegen, etc) project.changeFile( - 'b/schema.graphql', - schemaFile[1] + '\ntype Example1 { field: }', + 'b/schema.ts', + `\n\nexport const schema = gql(\`\n${ + schemaFile[1] + '\ntype Example1 { field: }' + }\`\n)`, ); await project.lsp.handleWatchedFilesChangedNotification({ changes: [ - { uri: project.uri('b/schema.graphql'), type: FileChangeType.Changed }, + { uri: project.uri('b/schema.ts'), type: FileChangeType.Changed }, ], }); // TODO: repeat this with other changes to the schema file and use a @@ -522,8 +534,8 @@ describe('project with simple config and graphql files', () => { // }); // console.log(project.fileCache.get('b/schema.graphql')); const schemaCompletion = await project.lsp.handleCompletionRequest({ - textDocument: { uri: project.uri('b/schema.graphql') }, - position: { character: 25, line: 5 }, + textDocument: { uri: project.uri('b/schema.ts') }, + position: { character: 25, line: 8 }, }); // TODO: SDL completion still feels incomplete here... where is Int? // where is self-referential Example1? diff --git a/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts b/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts index 76a506ce649..bbc1872dfac 100644 --- a/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts +++ b/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts @@ -87,6 +87,35 @@ query Test { `); }); + it('finds queries in call expressions with with newlines preceding the template', async () => { + const text = ` + import {gql} from 'react-apollo'; + import type {B} from 'B'; + import A from './A'; + + const QUERY = gql( + \` + query Test { + test { + value + ...FragmentsComment + } + } + \`); + + export function Example(arg: string) {}`; + + const contents = findGraphQLTags(text, '.ts'); + expect(contents[0].template).toEqual(` + query Test { + test { + value + ...FragmentsComment + } + } + `); + }); + it('finds queries in #graphql-annotated templates', async () => { const text = ` import {gql} from 'react-apollo'; diff --git a/packages/graphql-language-service-server/src/__tests__/parseDocument-test.ts b/packages/graphql-language-service-server/src/__tests__/parseDocument-test.ts index 94b0fa7a44e..7733641335e 100644 --- a/packages/graphql-language-service-server/src/__tests__/parseDocument-test.ts +++ b/packages/graphql-language-service-server/src/__tests__/parseDocument-test.ts @@ -1,4 +1,3 @@ -/** prettier-ignore-file */ import { parseDocument } from '../parseDocument'; describe('parseDocument', () => { @@ -89,8 +88,7 @@ describe('parseDocument', () => { `); }); - it - ('parseDocument finds queries in tagged templates using tsx', async () => { + it('parseDocument finds queries in tagged templates using tsx', async () => { const text = ` import {gql} from 'react-apollo'; import {B} from 'B'; @@ -304,7 +302,7 @@ describe('parseDocument', () => { export function Example(arg: string) {}`; const contents = parseDocument(text, 'test.ts'); - /* prettier-ignore-start */ + // please let me keep this whitespace prettier! expect(contents[0].query).toEqual(/* GraphQL */ ` query Test { test { @@ -314,7 +312,6 @@ describe('parseDocument', () => { } `); - /* prettier-ignore-end */ }); it('parseDocument ignores non gql tagged templates', async () => {