Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit 2e8983d

Browse files
authored
Merge pull request #52 from joelgriffith/bugfix/aliased-field-arguments-directives-hint-not-populating
Bugfix/aliased field arguments and directives not populating hint list
2 parents b9dad0d + 268a409 commit 2e8983d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
"LICENSE"
2727
],
2828
"options": {
29-
"mocha": "--full-trace --require resources/mocha-bootload src/**/__tests__/**/*-test.js"
29+
"mocha": "--full-trace --require resources/mocha-bootload src/**/__tests__/**/*-test.js",
30+
"mocha_tdd": "--full-trace --watch --require resources/mocha-bootload src/**/__tests__/**/*-test.js"
3031
},
3132
"scripts": {
3233
"test": "npm run lint && npm run testonly",
3334
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
35+
"testwatch": "babel-node --inspect ./node_modules/.bin/_mocha $npm_package_options_mocha_tdd",
3436
"lint": "eslint src",
3537
"check": "flow check",
3638
"build": "babel src --ignore __tests__ --out-dir .",

src/__tests__/hint-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,28 @@ describe('graphql-hint', () => {
8686
checkSuggestions(argumentNames, suggestions.list);
8787
});
8888

89+
it('provides correct argument suggestions when using aliases', async () => {
90+
var suggestions = await getHintSuggestions(
91+
'{ aliasTest: hasArgs ( ', { line: 0, ch: 23 });
92+
var argumentNames =
93+
TestSchema.getQueryType().getFields().hasArgs.args.map(arg => arg.name);
94+
checkSuggestions(argumentNames, suggestions.list);
95+
});
96+
8997
it('provides correct directive suggestions', async () => {
9098
var suggestions = await getHintSuggestions(
9199
'{ test (@', { line: 0, ch: 9 });
92100
var directiveNames = [ 'include', 'skip' ];
93101
checkSuggestions(directiveNames, suggestions.list);
94102
});
95103

104+
it('provides correct directive suggestions when using aliases', async () => {
105+
var suggestions = await getHintSuggestions(
106+
'{ aliasTest: test (@', { line: 0, ch: 20 });
107+
var directiveNames = [ 'include', 'skip' ];
108+
checkSuggestions(directiveNames, suggestions.list);
109+
});
110+
96111
it('provides correct typeCondition suggestions', async () => {
97112
var suggestions = await getHintSuggestions(
98113
'{ union { ... on ', { line: 0, ch: 17 });

src/utils/getHintsAtPosition.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function canUseDirective(kind, directive) {
235235
case 'Subscription':
236236
return locations.indexOf('SUBSCRIPTION') !== -1;
237237
case 'Field':
238+
case 'AliasedField':
238239
return locations.indexOf('FIELD') !== -1;
239240
case 'FragmentDefinition':
240241
return locations.indexOf('FRAGMENT_DEFINITION') !== -1;
@@ -296,6 +297,9 @@ function getTypeInfo(schema, tokenState) {
296297
info.fieldDef && info.fieldDef.args :
297298
state.prevState.kind === 'Directive' ?
298299
info.directiveDef && info.directiveDef.args :
300+
state.prevState.kind === 'AliasedField' ?
301+
state.prevState.name &&
302+
getFieldDef(schema, info.parentType, state.prevState.name).args :
299303
null;
300304
break;
301305
case 'Argument':

0 commit comments

Comments
 (0)