Skip to content

Commit 0ac0a85

Browse files
authored
feat: merge completion logic (for implements &, variables) (#1747)
1 parent ed6c94c commit 0ac0a85

File tree

10 files changed

+406
-452
lines changed

10 files changed

+406
-452
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"prebuild-bundles": "yarn build-ts-esm && yarn build-bundles-clean",
3838
"build-bundles-clean": "rimraf '{packages,examples,plugins}/**/{bundle,cdn,webpack}' && lerna run build-bundles-clean",
3939
"tsc": "tsc --build",
40-
"test": "jest",
40+
"test": "yarn jest && yarn test-mocha",
41+
"jest": "jest",
4142
"test-mocha": "nyc --reporter=lcov --reporter=text-summary mocha --require packages/codemirror-graphql/resources/mochaBootload packages/codemirror-graphql/**/*-test.js",
4243
"test-all": "yarn test --coverage && yarn test-mocha",
4344
"ci": "yarn lint && yarn run check && yarn build && yarn test-all",
@@ -57,8 +58,6 @@
5758
"format": "yarn eslint --fix && yarn pretty",
5859
"prepublishOnly": "./resources/prepublish.sh",
5960
"postpublish": "ts-node ./resources/publishCleanup.ts",
60-
"dev-graphiql": "yarn workspace graphiql run dev",
61-
"dev-lsp": "echo no-op",
6261
"lerna-publish": "yarn ci && yarn ci-e2e && lerna publish",
6362
"watch": "yarn tsc --watch",
6463
"start-graphiql": "yarn workspace graphiql dev",

packages/codemirror-graphql/src/__tests__/hint-test.js

+82-4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ describe('graphql-hint', () => {
199199
type: TestType,
200200
isDeprecated: false,
201201
},
202+
{
203+
text: 'example',
204+
type: GraphQLString,
205+
isDeprecated: false,
206+
},
202207
{
203208
text: '__typename',
204209
type: GraphQLNonNull(GraphQLString),
@@ -283,7 +288,7 @@ describe('graphql-hint', () => {
283288
expect(suggestions.list).to.deep.equal(expectedSuggestions);
284289
});
285290

286-
it('provides correct argument suggestions after fileterd', async () => {
291+
it('provides correct argument suggestions after filtered', async () => {
287292
const suggestions = await getHintSuggestions('{ hasArgs ( f', {
288293
line: 0,
289294
ch: 13,
@@ -390,7 +395,7 @@ describe('graphql-hint', () => {
390395
expect(suggestions.list).to.deep.equal(expectedSuggestions);
391396
});
392397

393-
it('provides correct directive suggestion after fileterd', async () => {
398+
it('provides correct directive suggestion after filtered', async () => {
394399
const suggestions = await getHintSuggestions('{ test (@s', {
395400
line: 0,
396401
ch: 10,
@@ -466,6 +471,55 @@ describe('graphql-hint', () => {
466471
expect(suggestions.list).to.deep.equal(expectedSuggestions);
467472
});
468473

474+
it('provides interface suggestions for type when using implements keyword', async () => {
475+
const suggestions = await getHintSuggestions('type Type implements ', {
476+
line: 0,
477+
ch: 21,
478+
});
479+
const list = [
480+
{
481+
text: 'TestInterface',
482+
type: TestSchema.getType('TestInterface'),
483+
},
484+
{
485+
text: 'AnotherTestInterface',
486+
type: TestSchema.getType('AnotherTestInterface'),
487+
},
488+
];
489+
const expectedSuggestions = getExpectedSuggestions(list);
490+
expect(suggestions.list).to.deep.equal(expectedSuggestions);
491+
});
492+
493+
it('provides interface suggestions for interface when using implements keyword', async () => {
494+
const suggestions = await getHintSuggestions(
495+
'interface MyInt implements An',
496+
{ line: 0, ch: 29 },
497+
);
498+
const list = [
499+
{
500+
text: 'AnotherTestInterface',
501+
type: TestSchema.getType('AnotherTestInterface'),
502+
},
503+
];
504+
const expectedSuggestions = getExpectedSuggestions(list);
505+
expect(suggestions.list).to.deep.equal(expectedSuggestions);
506+
});
507+
508+
it('provides interface suggestions for interface when using implements keyword and multiple interfaces', async () => {
509+
const suggestions = await getHintSuggestions(
510+
'interface MyInt implements AnotherTestInterface & T',
511+
{ line: 0, ch: 51 },
512+
);
513+
const list = [
514+
{
515+
text: 'TestInterface',
516+
type: TestSchema.getType('TestInterface'),
517+
},
518+
];
519+
const expectedSuggestions = getExpectedSuggestions(list);
520+
expect(suggestions.list).to.deep.equal(expectedSuggestions);
521+
});
522+
469523
it('provides correct typeCondition suggestions', async () => {
470524
const suggestions = await getHintSuggestions('{ union { ... on ', {
471525
line: 0,
@@ -484,12 +538,16 @@ describe('graphql-hint', () => {
484538
text: 'TestInterface',
485539
description: '',
486540
},
541+
{
542+
text: 'AnotherTestInterface',
543+
description: '',
544+
},
487545
];
488546
const expectedSuggestions = getExpectedSuggestions(list);
489547
expect(suggestions.list).to.deep.equal(expectedSuggestions);
490548
});
491549

492-
it('provides correct typeCondition suggestions after filterd', async () => {
550+
it('provides correct typeCondition suggestions after filtered', async () => {
493551
const suggestions = await getHintSuggestions('{ union { ... on F', {
494552
line: 0,
495553
ch: 18,
@@ -503,6 +561,10 @@ describe('graphql-hint', () => {
503561
text: 'TestInterface',
504562
description: '',
505563
},
564+
{
565+
text: 'AnotherTestInterface',
566+
description: '',
567+
},
506568
];
507569
const expectedSuggestions = getExpectedSuggestions(list);
508570
expect(suggestions.list).to.deep.equal(expectedSuggestions);
@@ -530,6 +592,10 @@ describe('graphql-hint', () => {
530592
text: 'TestInterface',
531593
description: '',
532594
},
595+
{
596+
text: 'AnotherTestInterface',
597+
description: '',
598+
},
533599
{
534600
text: 'Second',
535601
description: '',
@@ -707,7 +773,7 @@ describe('graphql-hint', () => {
707773

708774
it('provides fragment names for fragments defined lower', async () => {
709775
const suggestions = await getHintSuggestions(
710-
'query { ... } fragment Foo on Test { id }',
776+
'query { ... }\nfragment Foo on Test { id }',
711777
{ line: 0, ch: 11 },
712778
);
713779
const list = [
@@ -769,6 +835,11 @@ describe('graphql-hint', () => {
769835
type: TestType,
770836
isDeprecated: false,
771837
},
838+
{
839+
text: 'example',
840+
type: GraphQLString,
841+
isDeprecated: false,
842+
},
772843
{
773844
text: '__typename',
774845
type: GraphQLNonNull(GraphQLString),
@@ -796,14 +867,21 @@ describe('graphql-hint', () => {
796867
type: TestType,
797868
isDeprecated: false,
798869
},
870+
{
871+
text: 'example',
872+
type: GraphQLString,
873+
isDeprecated: false,
874+
},
799875
{
800876
text: '__typename',
801877
type: GraphQLNonNull(GraphQLString),
802878
description: 'The name of the current Object type at runtime.',
803879
isDeprecated: false,
804880
},
805881
];
882+
806883
const expectedSuggestions = getExpectedSuggestions(list);
884+
807885
expect(suggestions.list).to.deep.equal(expectedSuggestions);
808886
});
809887

packages/codemirror-graphql/src/__tests__/testSchema.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,20 @@ const TestInterface = new GraphQLInterfaceType({
7070
},
7171
});
7272

73+
const AnotherTestInterface = new GraphQLInterfaceType({
74+
name: 'AnotherTestInterface',
75+
resolveType: () => UnionFirst,
76+
fields: {
77+
example: {
78+
type: GraphQLString,
79+
resolve: () => ({}),
80+
},
81+
},
82+
});
83+
7384
export const UnionFirst = new GraphQLObjectType({
7485
name: 'First',
75-
interfaces: [TestInterface],
86+
interfaces: [TestInterface, AnotherTestInterface],
7687
fields: () => ({
7788
scalar: {
7889
type: GraphQLString,
@@ -82,6 +93,10 @@ export const UnionFirst = new GraphQLObjectType({
8293
type: TestType,
8394
resolve: () => ({}),
8495
},
96+
example: {
97+
type: GraphQLString,
98+
resolve: () => ({}),
99+
},
85100
}),
86101
});
87102

0 commit comments

Comments
 (0)