Skip to content

Commit 8e3e945

Browse files
authored
Adds tests
1 parent 6767b43 commit 8e3e945

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,64 @@ query Test {
400400
`);
401401
});
402402

403+
it('parseDocument finds queries in #graphql-annotated templates', async () => {
404+
const text = `
405+
import {gql} from 'react-apollo';
406+
import {B} from 'B';
407+
import A from './A';
408+
409+
const QUERY: string = \`#graphql
410+
query Test {
411+
test {
412+
value
413+
...FragmentsComment
414+
}
415+
}
416+
\${A.fragments.test}
417+
\`
418+
419+
export function Example(arg: string) {}`;
420+
421+
const contents = parseDocument(text, 'test.ts');
422+
expect(contents[0].query).toEqual(`#graphql
423+
query Test {
424+
test {
425+
value
426+
...FragmentsComment
427+
}
428+
}
429+
`);
430+
});
431+
432+
it('parseDocument finds queries in /*GraphQL*/-annotated templates', async () => {
433+
const text = `
434+
import {gql} from 'react-apollo';
435+
import {B} from 'B';
436+
import A from './A';
437+
438+
const QUERY: string = /* GraphQL */ \`
439+
query Test {
440+
test {
441+
value
442+
...FragmentsComment
443+
}
444+
}
445+
\${A.fragments.test}
446+
\`
447+
448+
export function Example(arg: string) {}`;
449+
450+
const contents = parseDocument(text, 'test.ts');
451+
expect(contents[0].query).toEqual(`
452+
query Test {
453+
test {
454+
value
455+
...FragmentsComment
456+
}
457+
}
458+
`);
459+
});
460+
403461
it('parseDocument ignores non gql tagged templates', async () => {
404462
const text = `
405463
// @flow

0 commit comments

Comments
 (0)